RDA5807p收音芯片完整驱动程序.docx
- 文档编号:3989049
- 上传时间:2022-11-26
- 格式:DOCX
- 页数:17
- 大小:17.86KB
RDA5807p收音芯片完整驱动程序.docx
《RDA5807p收音芯片完整驱动程序.docx》由会员分享,可在线阅读,更多相关《RDA5807p收音芯片完整驱动程序.docx(17页珍藏版)》请在冰豆网上搜索。
RDA5807p收音芯片完整驱动程序
FM单芯片收音IC(RDA5807SP)与LCD型MCU相结合,集成度高,外围少,基于DSP数字RF架构,彻底免生产调试。
极大地减少了人力,物力,提高生产效率,整体方案比传统PLL方案便宜百分之20以上,性价比高,FM方案成熟,已大批量投产。
本程序RDA5807p驱动程序,是企业级代码,完整规范,可以移植到任何51单片机甚至stm32,毫无压力!
注意:
此方案在iic总线上挂在多个器件,参考价值很高。
/**********************************I2C.C************************************/
#include
#include
#include
#include"type.h"
#include"utility.h"
#include"debug.h"
#include"I2C.h"
#include"gpio.h"
//SCL:
GPIO_D[1]
#definePORT_OUT_SCLGPIO_D_OUT
#definePORT_IN_SCLGPIO_D_IN
#definePORT_OE_SCLGPIO_D_OE
#defineMASK_BIT_SCL0x02
//SDA:
GPIO_D[0]
#definePORT_OUT_SDAGPIO_D_OUT
#definePORT_IN_SDAGPIO_D_IN
#definePORT_OE_SDAGPIO_D_OE
#defineMASK_BIT_SDA0x01
//#defineSetInputSCL()ClrGpioRegBit(PORT_OE_SCL,MASK_BIT_SCL)
#defineSetOutputSCL()ClrGpioRegBit(PORT_OE_SCL,MASK_BIT_SCL)
#defineSetSCL()SetGpioRegBit(PORT_OUT_SCL,MASK_BIT_SCL)
#defineClrSCL()ClrGpioRegBit(PORT_OUT_SCL,MASK_BIT_SCL)
//#defineGetSCL()(GetGpioReg(PORT_IN_SCL)&MASK_BIT_SCL)
#defineSetInputSDA()SetGpioRegBit(PORT_OE_SDA,MASK_BIT_SDA)
#defineSetOutputSDA()ClrGpioRegBit(PORT_OE_SDA,MASK_BIT_SDA)
#defineSetSDA()SetGpioRegBit(PORT_OUT_SDA,MASK_BIT_SDA)
#defineClrSDA()ClrGpioRegBit(PORT_OUT_SDA,MASK_BIT_SDA)
#defineGetSDA()(GetGpioReg(PORT_IN_SDA)&MASK_BIT_SDA)
#defineKtIICDelay()//WaitUs
(2)
//sendSTARTsignal.
VOIDI2C_Start()
{
SetSDA();
SetSCL();
SetOutputSCL();
SetOutputSDA();
SetSDA();
SetSCL();
KtIICDelay();
ClrSDA();
ClrSCL();
}
//sendSTOPsignal.
VOIDI2C_Stop()
{
//DBG(("I2C_Stop()\n"));
SetOutputSCL();
SetOutputSDA();
ClrSDA();
KtIICDelay();
SetSCL();
SetSDA();
SetInputSDA();
}
//sendAcknowledgement(ACKorNACK)signal.
VOIDI2C_SendAck()
{
//DBG(("I2C_SendAck()\n"));
ClrSDA();
SetSCL();
KtIICDelay();
ClrSCL();
}
//sendAcknowledgement(ACKorNACK)signal.
VOIDI2C_SendNoAck()
{
SetSDA();
SetSCL();
KtIICDelay();
ClrSCL();
}
//CheckAckowledgesignal(ACK/NACK).
BOOLI2C_ChkAck()
{
BOOLAck;
ClrSCL();
SetInputSDA();
SetSCL();
KtIICDelay();
Ack=!
GetSDA();
ClrSCL();
returnAck;
}
//SendonebyteviaI2C(checkACK).
BOOLI2C_WriteByte(BYTEDat)
{
BYTEi=8;
//DBG(("I2C_WriteByte(%-.2BX)\n",Dat));
SetOutputSDA();
ClrSCL();
while(i--)
{
if(Dat&0x80)//MSBoutputfirst
{
SetSDA();
}
else
{
ClrSDA();
}
Dat<<=1;
SetSCL();
KtIICDelay();
ClrSCL();
}
returnI2C_ChkAck();
}
//ReceiveonebyteviaI2C.
BYTEI2C_ReadByte()
{
BYTEi=8;
BYTEDat=0;
SetInputSDA();
while(i--)
{
Dat<<=1;
if(GetSDA())
{
Dat|=0x01;
}
SetSCL();
KtIICDelay();
ClrSCL();
}
SetOutputSDA();
returnDat;
}
BOOLI2C_WriteBytes(BYTE*Buf,BYTELen)
{
while(Len--)
{
if(!
I2C_WriteByte(*(Buf++)))
{
DBG(("writedataerr\n"));
returnFALSE;
}
}
returnTRUE;
}
//ReaddataviaI2C.
BOOLI2C_ReadBytes(BYTE*Buf,BYTELen)
{
while(Len--)
{
*(Buf++)=I2C_ReadByte();
if(Len==0)
{
I2C_SendNoAck();
}
else
{
I2C_SendAck();
}
}
returnTRUE;
}
//Writedatatoeepromfrombuffer
BOOLI2C_WriteNByte(BYTEdevAddr,WORDAddr,BYTE*Buf,BYTELen)
{
#ifdefIIC_SENDADDRMACRO_EN
BOOLacktemp=FALSE;
acktemp=I2C_SendAddr(devAddr,Addr,IIC_WRITE);
acktemp&=I2C_WriteBytes(Buf,Len);
I2C_Stop();
//DBG_APP(("I2C_WriteNByte,ACK:
%bu\n",(BYTE)acktemp));
returnacktemp;
#else
BYTEPageAddr=(((BYTE*)&Addr)[0]&0x07)<<1;
I2C_Start();
if(!
I2C_WriteByte(devAddr|PageAddr))
{
WaitMs(EEPROM_WRITE_TIME);
I2C_Start();
if(!
I2C_WriteByte(devAddr|PageAddr))
{
I2C_Stop();
returnFALSE;
}
}
if(I2C_WriteByte(((BYTE*)&Addr)[1]))
{
if(I2C_WriteBytes(Buf,Len))
{
I2C_Stop();
returnTRUE;
}
}
I2C_Stop();
returnFALSE;
#endif
}
//Readdatafromeeprom.
BOOLI2C_ReadNByte(BYTEdevAddr,WORDAddr,BYTE*Buf,BYTELen)
{
#ifdefIIC_SENDADDRMACRO_EN
BOOLacktemp=FALSE;
acktemp=I2C_SendAddr(devAddr,Addr,IIC_READ);
acktemp&=I2C_ReadBytes(Buf,Len);
I2C_Stop();
returnacktemp;
#else
BYTEPageAddr=(((BYTE*)&Addr)[0]&0x07)<<1;
I2C_Start();
if(!
I2C_WriteByte(devAddr|PageAddr))
{
WaitMs(EEPROM_WRITE_TIME);
I2C_Start();
if(!
I2C_WriteByte(devAddr|PageAddr))
{
I2C_Stop();
returnFALSE;
}
}
if(I2C_WriteByte(((BYTE*)&Addr)[1]))
{
I2C_Start();
if(I2C_WriteByte(devAddr|0x01|PageAddr))
{
if(I2C_ReadBytes(Buf,Len))
{
I2C_Stop();
returnTRUE;
}
}
}
I2C_Stop();
returnFALSE;
#endif
}
//sendaddressviaIIC.
#ifdefIIC_SENDADDRMACRO_EN
BOOLI2C_SendAddr(
unsignedcharicAddr,
unsignedintwAddr,
unsignedcharucRW
)
{
I2C_Start();
if(!
I2C_WriteByte(icAddr))
{
WaitMs(EEPROM_WRITE_TIME);//WairtforProgramming-time.
I2C_Start();
if(!
I2C_WriteByte(icAddr))//|PageAddr))
{
I2C_Stop();
returnFALSE;
}
}
if(!
I2C_WriteByte((unsignedchar)wAddr))
{
I2C_Stop();
returnFALSE;
}
if(ucRW==IIC_READ)
{
I2C_Start();
if(!
I2C_WriteByte(icAddr|IIC_READ))
{
I2C_Stop();
returnFALSE;
}
}
returnTRUE;
}
#endif//I2C_SendAddr
/********************************RDA5807P.c************************************/
#include"syscfg.h"
#include"RDA5807P.h"
#include"i2c.h"
#include"radio_ctrl.h"
#include"utility.h"
#include"debug.h"
#ifdefFUNC_RADIO_EN
WORDCODERDA5807P_RegMap[32]=
{
//0x02,0x0401,//MUTEon//highimpendance32768
0x03,0x0000,//freq0//band875--1080//space100k//turnoff//turnon0x0010
0x04,0x0400,
0x05,0x86AF,//0x8AAF//SEEKthreshold//VOL
0x06,0x8000,
0x07,0x5F1A,
0x12,0xF000,
0x13,0x7F0B,
0x14,0x0071,
0x15,0x42C0,
0x1A,0x10C0,
0x1C,0x6015,
0x21,0x4580,
0x24,0x0601,
0x26,0x0D04,
0x2C,0x3C3B,
0x35,0x3877
};
BOOLRDA5807WriteReg(WORDaddr,WORDdat)
{
returnI2C_WriteNByte(RDA5807_CHIP_ADDR,addr,(BYTE*)&dat,2);
}
WORDRDA5807ReadReg(BYTERegister_Address)
{
WORDTempData;
I2C_ReadNByte(RDA5807_CHIP_ADDR,Register_Address,(BYTE*)(&TempData),2);
returnTempData;
}
VOIDRDA5807P_Init()
{
BYTEi;
WORDtemp;
RDA5807WriteReg(0x02,0x0002);
WaitMs(50);
#ifMACRADIO_XTAL_12M
RDA5807WriteReg(0x02,0x0411);
#else
RDA5807WriteReg(0x02,0x0001);
WaitMs(650);
#endif
for(i=0;i { RDA5807WriteReg(*(RDA5807P_RegMap+i),*(RDA5807P_RegMap+1+i)); i+=2; } temp=((gRadioCtrl.Freq-870)<<6)|0x0010; RDA5807WriteReg(0x03,temp);//FREQ//tune//band//space WaitMs(40); } BOOLRDA5807P_ReadID() { WORDREADID; DBG(("RDA5807P_ReadID()\n")); if(! RDA5807WriteReg(0x02,0x0002))//reset { DBG(("RDA5807P_ReadID()FALSE! \n")); returnFALSE; } WaitMs(300); READID=RDA5807ReadReg(0x0E); DBG(("readID: %X\n",READID)); if(READID==0x5804) { DBG(("FM_ReadID,RDA5807P! \n")); returnTRUE; } returnFALSE; } VOIDRDA5807P_Mute(BOOLMuteFg) { WORDtemp; temp=RDA5807ReadReg(0x02); if(MuteFg) { temp&=0xBFFF;//muteon } else { temp|=0x4000;//muteoFF } RDA5807WriteReg(0x02,temp); } VOIDRDA5807P_PowerDownDis() { RDA5807WriteReg(0x02,(RDA5807ReadReg(0x02)|0xC000)); } VOIDRDA5807P_PowerDownEn() { RDA5807WriteReg(0x02,(RDA5807ReadReg(0x02)&0x3FFF)); } VOIDRDA5807P_FreqSet() { WORDFreq; WORDtemp; Freq=gRadioCtrl.Freq; RDA5807P_Mute(TRUE);// if((Freq<875)||(Freq>1080)) { Freq=875; } temp=((Freq-870)<<6)|0x0010; RDA5807WriteReg(0x03,temp);//FREQ//tune//band//space } BYTERDA5807P_SeekResultGet() { WORDreadData0B; readData0B=RDA5807ReadReg(0x0B); if(readData0B&0x0080)//ready { if(readData0B&0x0100) { returnRADIO_SEEK_VALIDSTATION; } returnRADIO_SEEK_STC; } returnRADIO_SEEK_FALSE; } #endif 数字存台,用at24c02芯片即可,驱动代码如下: #include #include #include #include"type.h" #include"utility.h" #include"debug.h" #include"i2c.h" #include"24Cxx.h" #defineEEPROM_WRITE_TIME10//10ms #defineEEPROM_PAGE_SIZE8//8bytes/page #if1 //Readdatatobufferfromeeprom BOOLEEPROM_ReadBytes(BYTEAddr,BYTE*Buf,BYTELen) { #ifdefIIC_SENDADDRMACRO_EN returnI2C_ReadNByte(EEPROM_WRITE_ADDR,((WORD)Addr),((BYTE*)Buf),(BYTE)Len); #else//! IIC_SENDADDRMACRO_EN I2C_Start(); if(! I2C_WriteByte(EEPROM_WRITE_ADDR)) { WaitMs(EEPROM_WRITE_TIME); I2C_Start(); if(! I2C_WriteByte(EEPROM_WRITE_ADDR)) { I2C_Stop(); returnFALSE; } } if(I2C_WriteByte(Addr)) { I2C_Start(); if(I2C_WriteByte(EEPROM_READ_ADDR)) { if(I2C_ReadBytes(Buf,Len)) { I2C_Stop(); returnTRUE; } } } I2C_Stop(); returnFALSE; #endif//! IIC_SENDADDRMACRO_EN } #endif//EEPROM_ReadBytes //Readonebytefromeeprom BYTEEEPROM_ReadByte(BYTEAddr) { BYTETemp=0; EEPROM_ReadBytes(Addr,&Temp,1); returnTemp; } //Writedatatoeepromfrombuffer #if1 BOOLEEPROM_WriteBytesInOnePage(BYTEAddr,BYTE*Buf,BYTELen) { #ifdefIIC_SENDADDRMACRO_EN returnI2C_WriteNByte(EEPROM_WRITE_ADDR,((WORD)Addr),((BYTE*)Buf),((BYTE)Len)); #else I2C_Start(); if(! I2C_WriteByte(EEPROM_WRITE_ADDR)) { WaitMs(EEPROM_WRITE_TIME); I2C_Start(); if(! I2C_WriteByte(EEPROM_WRITE_ADDR)) { I2C_Stop(); returnFALSE; } } if(I2C_WriteByte(Addr)) { if(I2C_WriteBytes(Buf,Len)) { I2C_Stop(); returnTRUE; } } I2C_Stop(); returnFALSE; #endif } #endif//EEPROM_WriteBytesInOnePage //Writedatatoeepromfrombuffer BOOLEEPROM_WriteBytes(BYTEAddr,BYTE*Buf,BYTELen) { while(Len) { BYTEn=EE
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- RDA5807p 收音 芯片 完整 驱动程序
![提示](https://static.bdocx.com/images/bang_tan.gif)