2022-01-18 00:58:54 +08:00

252 lines
8.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*********************************************************************************************************************
* COPYRIGHT NOTICE
* Copyright (c) 2020,<2C><><EFBFBD>ɿƼ<C9BF>
* All rights reserved.
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<51><C8BA><EFBFBD><EFBFBD>Ⱥ<EFBFBD><C8BA>824575535
*
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>;<EFBFBD><CDBE>
* <20><>ӭ<EFBFBD><D3AD>λʹ<CEBB>ò<EFBFBD><C3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EBB1A3><EFBFBD><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC>İ<EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
* @file MPU6050
* @company <09>ɶ<EFBFBD><C9B6><EFBFBD><EFBFBD>ɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾
* @author <09><><EFBFBD>ɿƼ<C9BF>(QQ3184284598)
* @version <09>鿴doc<6F><63>version<6F>ļ<EFBFBD> <20>汾˵<E6B1BE><CBB5>
* @Software ADS v1.2.2
* @Target core TC264D
* @Taobao https://seekfree.taobao.com/
* @date 2020-3-23
* @note
<09><><EFBFBD>߶<EFBFBD><DFB6>
------------------------------------
<09><><EFBFBD><EFBFBD>IIC
SCL <20>鿴SEEKFREE_IIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SCL<43><EFBFBD><EAB6A8>
SDA <20>鿴SEEKFREE_IIC<49>ļ<EFBFBD><C4BC>ڵ<EFBFBD>SEEKFREE_SDA<44><EFBFBD><EAB6A8>
Ӳ<><D3B2>IIC
SCL <20>鿴init_mpu6050_hardware<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<49><43>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SDA <20>鿴init_mpu6050_hardware<72><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<49><43>ʼ<EFBFBD><CABC>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
------------------------------------
ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>RDA5807<30><37>SCL<43><4C>SDA<44><41><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>1K<31><4B><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD>뵥Ƭ<EBB5A5><C6AC><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޷<EFBFBD>ͨ<EFBFBD><CDA8>
********************************************************************************************************************/
#include "SEEKFREE_IIC.h"
#include "zf_stm_systick.h"
#include "SEEKFREE_RDA5807.h"
#define ack 1 //<2F><>Ӧ<EFBFBD><D3A6>
#define no_ack 0 //<2F><>Ӧ<EFBFBD><D3A6>
#define FM_ADDRESS 0x20>>1
uint8 rda5807_config_reg[] = {
0xc0, 0x03, // Register 0x2
0x00, 0x00, // Register 0x3
0x0a, 0x00, // Register 0x4
0x88, 0x0f, // Register 0x5
0x00, 0x00, // Register 0x6
0x42, 0x02, // Register 0x7
};
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807ģ<37><C4A3>IIC<49><43>ȡ<EFBFBD><C8A1><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
// @param dev_add <09><EFBFBD><E8B1B8>ַ(<28><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ַ)
// @param data[] <09><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ĵ<EFBFBD>ַָ<D6B7><D6B8>
// @param num <09><>ȡ<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rad5807m_simiic_write(uint8 dev_add, uint8 data[], uint8 num)
{
uint8 i;
uint16 temp_delay_time = 0;
temp_delay_time = simiic_delay_time;
simiic_delay_set(RAD5807_DELAY_TIME);//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>IIC<49><43>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ΪĬ<CEAA><C4AC><EFBFBD><EFBFBD><EFBFBD>ʽϸ<CABD>
simiic_start();
send_ch( (dev_add<<1) | 0x00); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>дλ
for(i=0;i<num;i++)
send_ch(data[i]); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
simiic_stop();
simiic_delay_set(temp_delay_time); //<2F><>ԭģ<D4AD><C4A3>IICĬ<43><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//-------------------------------------------------------------------------------------------------------------------
// @brief ģ<><C4A3>IIC<49><43>ȡ<EFBFBD><C8A1><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
// @param dev_add <09><EFBFBD><E8B1B8>ַ(<28><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ַ)
// @param dat_add <09><><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD>ĵ<EFBFBD>ַָ<D6B7><D6B8>
// @param num <09><>ȡ<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
// @return uint8 <09><><EFBFBD>ؼĴ<D8BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807m_simiic_read(uint8 dev_add,uint8 *dat_add,uint8 num)
{
uint16 temp_delay_time = 0;
temp_delay_time = simiic_delay_time;
simiic_delay_set(RAD5807_DELAY_TIME);//<2F><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>IIC<49><43>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>ΪĬ<CEAA><C4AC><EFBFBD><EFBFBD><EFBFBD>ʽϸ<CABD>
simiic_start();
send_ch( (dev_add<<1) | 0x01); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>Ӷ<EFBFBD>λ
while(--num)
{
*dat_add = read_ch(ack); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
dat_add++;
}
*dat_add = read_ch(no_ack); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
simiic_stop();
simiic_delay_set(temp_delay_time); //<2F><>ԭģ<D4AD><C4A3>IICĬ<43><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//-------------------------------------------------------------------------------------------------------------------
// @brief Ƶ<>ʼĴ<CABC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>
// @param channel Ƶ<>ʼĴ<CABC><C4B4><EFBFBD>ֵ
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_channel_config(uint16 reg_chn)
{
rda5807_config_reg[0] = 0xc0;
rda5807_config_reg[1] = 0x01;
rda5807_config_reg[2] = (uint8)(reg_chn >> 2);
rda5807_config_reg[3] = (uint8)(((reg_chn & 0x3) << 6) | 0x18);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5> <09><><EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>
// @param freq Ƶ<><C6B5>ֵ
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_set_channel(float freq)
{
uint16 reg_chn=0;
reg_chn = (int)((freq - 76.0) * 10.0 + 0.5);
rda5807_channel_config(reg_chn);
rad5807m_simiic_write(FM_ADDRESS,rda5807_config_reg, 4);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ģʽ
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_set_idle(void)
{
rda5807_config_reg[1] &= ~(1<<0);//Power Up Disabled.
rad5807m_simiic_write(FM_ADDRESS,rda5807_config_reg, 4);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ģʽ
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_set_transimt(void)
{
rda5807_config_reg[1] |= 1<<0;//Power Up Enable.
rad5807m_simiic_write(FM_ADDRESS,rda5807_config_reg, 4);
}
uint8 rda5807_read_reg[10];
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37>ȡID<49><44><EFBFBD>ڲ<EFBFBD>ʹ<EFBFBD>ã<EFBFBD><C3A3>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_read_id(void)
{
rda5807m_simiic_read(FM_ADDRESS,rda5807_read_reg,10);
}
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37>ȡRSSI(<28>ź<EFBFBD>ǿ<EFBFBD><C7BF>)
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
uint8 rda5807_read_rssi(void)
{
uint8 rssi;
rda5807m_simiic_read(FM_ADDRESS,rda5807_read_reg,3);
rssi = rda5807_read_reg[2] >> 1;
return rssi;
}
//-------------------------------------------------------------------------------------------------------------------
// @brief rda5807<30><37>ʼ<EFBFBD><CABC>
// @param NULL
// @return void
// @since v1.0
// Sample usage:
//-------------------------------------------------------------------------------------------------------------------
void rda5807_init(float freq)
{
uint8 dat[2] = {0x00,0x02};
//iic<69><63>ʼ<EFBFBD><CABC>
simiic_init();
systick_delay_ms(STM0, 1000);//<2F><>Ҫ<EFBFBD><D2AA>֤<EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>1S<31>ڲ<EFBFBD><DAB2><EFBFBD> FMģ<4D><C4A3>
while(rda5807_read_reg[8] != 0x58)
{
//<2F><>λ
rad5807m_simiic_write(FM_ADDRESS,dat,2);
systick_delay_ms(STM0, 10);
//<2F><>ȡ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ졣
rda5807m_simiic_read(FM_ADDRESS,rda5807_read_reg,10);
//<2F><><EFBFBD><EFBFBD>һֱ<D2BB><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>鿴SCL<43><4C>SDA<44>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Ӻá<D3BA>
//Ҳ<><D2B2><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD> <20>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD>5807.h<>ļ<EFBFBD><C4BC>е<EFBFBD>RAD5807_DELAY_TIME<4D><EFBFBD><EAB6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
//<2F><><EFBFBD><EFBFBD>SDA SCLû<4C>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8A3A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD><EFBFBD>޸ĵײ<C4B5><D7B2><EFBFBD><EFBFBD>ļ<EFBFBD>
//<2F><>gpio_init<69><74><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>IfxPort_PadDriver_cmosAutomotiveSpeed1<64><31>ΪIfxPort_PadDriver_cmosAutomotiveSpeed4
}
//<2F><><EFBFBD><EFBFBD>
rad5807m_simiic_write(FM_ADDRESS,rda5807_config_reg,sizeof(rda5807_config_reg));
//Ƶ<><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
rda5807_set_channel(freq);
}