mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-22 17:12:55 +08:00
252 lines
8.0 KiB
C
252 lines
8.0 KiB
C
|
/*********************************************************************************************************************
|
|||
|
* COPYRIGHT NOTICE
|
|||
|
* Copyright (c) 2020,<EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>
|
|||
|
* All rights reserved.
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QQȺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ⱥ<EFBFBD><EFBFBD>824575535
|
|||
|
*
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>;<EFBFBD><EFBFBD>
|
|||
|
* <EFBFBD><EFBFBD>ӭ<EFBFBD><EFBFBD>λʹ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>뱣<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD>İ<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @file MPU6050
|
|||
|
* @company <EFBFBD>ɶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾
|
|||
|
* @author <EFBFBD><EFBFBD><EFBFBD>ɿƼ<EFBFBD>(QQ3184284598)
|
|||
|
* @version <EFBFBD>鿴doc<EFBFBD><EFBFBD>version<EFBFBD>ļ<EFBFBD> <EFBFBD>汾˵<EFBFBD><EFBFBD>
|
|||
|
* @Software ADS v1.2.2
|
|||
|
* @Target core TC264D
|
|||
|
* @Taobao https://seekfree.taobao.com/
|
|||
|
* @date 2020-3-23
|
|||
|
* @note
|
|||
|
<EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD><EFBFBD>壺
|
|||
|
------------------------------------
|
|||
|
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC
|
|||
|
SCL <EFBFBD>鿴SEEKFREE_IIC<EFBFBD>ļ<EFBFBD><EFBFBD>ڵ<EFBFBD>SEEKFREE_SCL<EFBFBD>궨<EFBFBD><EFBFBD>
|
|||
|
SDA <EFBFBD>鿴SEEKFREE_IIC<EFBFBD>ļ<EFBFBD><EFBFBD>ڵ<EFBFBD>SEEKFREE_SDA<EFBFBD>궨<EFBFBD><EFBFBD>
|
|||
|
|
|||
|
Ӳ<EFBFBD><EFBFBD>IIC
|
|||
|
SCL <EFBFBD>鿴init_mpu6050_hardware<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
SDA <EFBFBD>鿴init_mpu6050_hardware<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IIC<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
------------------------------------
|
|||
|
ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RDA5807<EFBFBD><EFBFBD>SCL<EFBFBD><EFBFBD>SDA<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>1K<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뵥Ƭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
********************************************************************************************************************/
|
|||
|
|
|||
|
|
|||
|
|
|||
|
#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);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|