rda5820.h file:
#ifndef __RDA5820_H #define __RDA5820_H #define RDA5820_R00 0X00 //Read 16 bits of ID = 0X5820 #define RDA5820_R02 0X02 //DHIZ[15],DMUTE[14],MONO[13],BASS[12],SEEKUP[9],SEEK[8],SKMODE[7],CLK_MODE[6:4],ANTENNA[2],SOFTRESET[1],ENABLE[0] #define RDA5820_R03 0X03 //CHAN[15:6],TUNE[4],BAND[3:2],SPACE[1:0] #define RDA5820_R04 0X04 //STCIEN[14](search completion interrupt),DE[11],I2S_ENABLE[6],GPIO3~1[5:0] #define RDA5820_R05 0X05 //INT_MODE[15],SEEKTH[14:8](set signal strength),LNA_PORT_SEL[7:6],LNA_ICSEL_BIT[5:4],VOLUME[3:0]; #define RDA5820_R0A 0X0A //STC[14] (search completion flag), SF[13] (search failure flag), ST[10] (stereo flag), READCHAN[9:0] (frequency). #define RDA5820_R0B 0X0B //RSSI[15:9] (signal strength), FM_TRUE[8] (station flag), FM_READY[7] (FM ready flag) #define RDA5820_R40 0X40 //AUTO_SEEK[15] (full/semi-automatic channel search), CHAN_SCAN[14] (empty/busy channel search), CHIP_FUN[3:0] (working mode) #define RDA5820_R41 0X41 //MEM_CLR[15] (memory clear), RPT_TIME[14:9] (RDS response times), MEM_DEPTH[8:0] (FIFO size, maximum 256) #define RDA5820_R42 0X42 //TX_SIG_GAIN[10:8],TX_PA_GAIN[5:0] (transmit power). #define RDA5820_R4A 0X4A //MEM_INTMOD[4:0] #define RDA5820_R4B 0X4B //CHAN_NUM[7:0] (valid only in fully automatic channel search, represents the number of radio stations). #define RDA5820_R4C 0X4C //TX_AUDIO_DEV[15:0] #define RDA5820_R4D 0X4D //TX_PILOT_DEV[15:0] #define RDA5820_R4E 0X4E //TX_RDS_DEV[15:0] #define RDA5820_R53 0X53 //CHAN_BOTTON[10:0] (channel minimum frequency, 100kHZ unit) #define RDA5820_R54 0X54 //CHAN_TOP[10:0] (channel highest frequency, 100kHZ unit) #define RDA5820_R64 0X64 //RDS_RXMOD[4:3] (FIFO mode [10] or register mode [11]) #define RDA5820_READ 0X23 //Read RDA5820 #define RDA5820_WRITE 0X22 //写RDA5820 uint8_t RDA5820_Init(void); //initialization void RDA5820_WR_Reg(uint8_t addr,uint16_t val); //Write RDA5820 register uint16_t RDA5820_RD_Reg(uint8_t addr); //Read RDA5820 register void RDA5820_RX_Mode(void); //Set RDA5820 to RX mode void RDA5820_TX_Mode(void); //Set RDA5820 to TX mode uint8_t RDA5820_Rssi_Get(void); void RDA5820_Mute_Set(uint8_t mute); void RDA5820_Rssi_Set(uint8_t rssi); void RDA5820_Vol_Set(uint8_t vol); void RDA5820_TxPAG_Set(uint8_t gain); void RDA5820_TxPGA_Set(uint8_t gain); void RDA5820_Band_Set(uint8_t band); void RDA5820_Space_Set(uint8_t spc); void RDA5820_Freq_Set(uint16_t freq); uint16_t RDA5820_Freq_Get(void); #endif
rda5820.c file:
#include "lpc11xx.h" #include "rda5820.h" #include "i2c.h" //initialization //0, initialization successful; //Others, initialization failed. uint8_t RDA5820_Init(void) { uint16_t id; I2C_Init(); //Initialize I2C port id=RDA5820_RD_Reg(RDA5820_R00); //Read ID =0X5805 if(id==0X5805) //Read ID correctly { RDA5820_WR_Reg(RDA5820_R02,0x0002); //soft reset delay_ms(50); RDA5820_WR_Reg(RDA5820_R02,0xC001); //Stereo, power on delay_ms(600); //Wait for the clock to stabilize RDA5820_WR_Reg(RDA5820_R05,0X884F); //Search intensity 8, LNAN, 1.8mA, VOL max RDA5820_WR_Reg(0X07,0X7800); // RDA5820_WR_Reg(0X13,0X0008); // RDA5820_WR_Reg(0X15,0x1420); //VCO setting 0x17A0/0x1420 RDA5820_WR_Reg(0X16,0XC000); // RDA5820_WR_Reg(0X1C,0X3126); // RDA5820_WR_Reg(0X22,0X9C24); //fm_true RDA5820_WR_Reg(0X47,0XF660) ; //tx rds }else return 1; // Initialization failed return 0; } //Write RDA5820 register void RDA5820_WR_Reg(uint8_t addr,uint16_t val) { I2C_Start(); I2C_Send_Byte(RDA5820_WRITE); //Send write command I2C_Wait_Ack(); I2C_Send_Byte(addr); //Send address I2C_Wait_Ack(); I2C_Send_Byte(val>>8); //Send high byte I2C_Wait_Ack(); I2C_Send_Byte(val&0XFF); //Send low byte I2C_Wait_Ack(); I2C_Stop(); //Generate a stop condition } //Read RDA5820 register uint16_t RDA5820_RD_Reg(uint8_t addr) { uint16_t res; I2C_Start(); I2C_Send_Byte(RDA5820_WRITE); //Send write command I2C_Wait_Ack(); I2C_Send_Byte(addr); //Send address I2C_Wait_Ack(); I2C_Start(); I2C_Send_Byte(RDA5820_READ); //Send read command I2C_Wait_Ack(); res=I2C_Read_Byte(1); //Read high byte, send ACK res<<=8; res|=I2C_Read_Byte(0); //Read low byte, send NACK I2C_Stop(); //Generate a stop condition return res; //Return the read data } //Set RDA5820 to RX mode void RDA5820_RX_Mode(void) { uint16_t temp; temp=RDA5820_RD_Reg(0X40); //Read the content of 0X40 temp&=0xfff0; //RX mode RDA5820_WR_Reg(0X40,temp); //FM RX mode } //Set RDA5820 to TX mode void RDA5820_TX_Mode(void) { uint16_t temp; temp=RDA5820_RD_Reg(0X40); //Read the content of 0X40 temp&=0xfff0; temp|=0x0001; //TX mode RDA5820_WR_Reg(0X40,temp); //FM TM mode } //Get signal strength //Return value range: 0~127 uint8_t RDA5820_Rssi_Get(void) { uint16_t temp; temp=RDA5820_RD_Reg(0X0B); //Read the content of 0X0B return temp>>9; //Return signal strength } //Set the volume ok //vol:0~15; void RDA5820_Vol_Set(uint8_t vol) { uint16_t temp; temp=RDA5820_RD_Reg(0X05); //Read the content of 0X05 temp&=0XFFF0; temp|=vol&0X0F; RDA5820_WR_Reg(0X05,temp); //Set volume } //Mute settings //mute: 0, not muted; 1, muted void RDA5820_Mute_Set(uint8_t mute) { uint16_t temp; temp=RDA5820_RD_Reg(0X02); //Read the content of 0X02 if(mute)temp|=1<<14; else temp&=~(1<<14); RDA5820_WR_Reg(0X02,temp); //Set MUTE } //Set sensitivity //rssi:0~127; void RDA5820_Rssi_Set(uint8_t rssi) { uint16_t temp; temp=RDA5820_RD_Reg(0X05); //Read the content of 0X05 temp&=0X80FF; temp|=(uint16_t)rssi<<8; RDA5820_WR_Reg(0X05,temp); //Set RSSI } //Set TX transmit power //gain:0~63 void RDA5820_TxPAG_Set(uint8_t gain) { uint16_t temp; temp=RDA5820_RD_Reg(0X42); //Read the content of 0X42 temp&=0XFFC0; temp|=gain; //GAIN RDA5820_WR_Reg(0X42,temp); //Set the PA power } //Set TX input signal gain //gain:0~7 void RDA5820_TxPGA_Set(uint8_t gain) { uint16_t temp; temp=RDA5820_RD_Reg(0X42); //Read the content of 0X42 temp&=0XF8FF; temp|=gain<<8; //GAIN RDA5820_WR_Reg(0X42,temp); //Set PGA } //Set the working frequency band of RDA5820 //band:0,87~108Mhz;1,76~91Mhz;2,76~108Mhz;3,user defined (53H~54H) void RDA5820_Band_Set(uint8_t band) { uint16_t temp; temp=RDA5820_RD_Reg(0X03); //Read the content of 0X03 temp&=0XFFF3; temp|=band<<2; RDA5820_WR_Reg(0X03,temp); //Set BAND } //Set the step frequency of RDA5820 //band:0,100Khz;1,200Khz;3,50Khz;3,reserved void RDA5820_Space_Set(uint8_t spc) { uint16_t temp; temp=RDA5820_RD_Reg(0X03); //Read the content of 0X03 temp&=0XFFFC; temp|=spc; RDA5820_WR_Reg(0X03,temp); //Set BAND } //Set the frequency of RDA5820 //freq: frequency value (unit is 10Khz), for example 10805 means 108.05Mhz void RDA5820_Freq_Set(uint16_t freq) { uint16_t temp; uint8_t spc=0,band=0; uint16_t fbtm,chan; temp=RDA5820_RD_Reg(0X03); //Read the content of 0X03 temp&=0X001F; band=(temp>>2)&0x03; //get the frequency band spc=temp&0x03; //Get the resolution if(spc==0)spc=10; else if(spc==1)spc=20; else spc=5; if(band==0)fbtm=8700; else if(band==1||band==2)fbtm=7600; else { fbtm=RDA5820_RD_Reg(0X53); //Get the bottom frequency fbtm*=10; } if(freq>6; band=(temp>>2)&0x03; //get the frequency band spc=temp&0x03; //Get the resolution if(spc==0)spc=10; else if(spc==1)spc=20; else spc=5; if(band==0)fbtm=8700; else if(band==1||band==2)fbtm=7600; else { fbtm=RDA5820_RD_Reg(0X53); //Get the bottom frequency fbtm*=10; } temp=fbtm+chan*spc; return temp; //Return frequency value }
main.c file:
#include "lpc11xx.h" #include "ili9325.h" #include "w25q16.h" #include "rda5820.h" #define KEY1_DOWN (LPC_GPIO1->DATA&(1<<9))!=(1<<9) #define KEY2_DOWN (LPC_GPIO1->DATA&(1<<10))!=(1<<10) int main() { uint16_t freqset=0; uint8_t i,rssi; LCD_Init(); LCD_Clear(WHITE); W25Q16_Init(); // Initialize the font chip W25Q16 LCD_ShowString(20, 5, "START"); delay_ms(600); LCD_ShowString(20, 5, " "); if(RDA5820_Init()==0) { LCD_ShowString(20, 5, "OK"); } else { LCD_ShowString(20, 5, "NO"); } RDA5820_Band_Set(0); //Set the frequency band to 87~108Mhz RDA5820_Space_Set(0); //Set the step to 100Khz RDA5820_TxPGA_Set(3); //Set the signal gain to 3 RDA5820_TxPAG_Set(63); //The transmission power is maximum. RDA5820_RX_Mode(); //Set to receive mode freqset=8800; //Default is 88Mhz RDA5820_Freq_Set(freqset); //Set frequency while(1) { if(KEY1_DOWN) { delay_ms(30); if(KEY1_DOWN) { if(freqset>8700)freqset-=10; LCD_ShowNum(100,30,freqset,5); RDA5820_Freq_Set(freqset); //Set frequency } } else if(KEY2_DOWN) { delay_ms(30); if(KEY2_DOWN) { if(freqset<10800)freqset+=10; LCD_ShowNum(100,30,freqset,5); RDA5820_Freq_Set(freqset); //Set frequency } } i++; delay_ms(10); if(i==200) //Detect signal strength information every two seconds or so { i=0; rssi=RDA5820_Rssi_Get(); //Get signal strength LCD_ShowNum(100,230,rssi,3); //Show signal strength } } }
Previous article:ATT7053 Smart Electricity Meter Program and Circuit Design
Next article:LPC1114 MCU OLED Driver
Recommended ReadingLatest update time:2024-11-17 01:43
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- EEWORLD University ---- TINA-TI (TM) series courses
- Moto 360 Wireless Charging Base Disassembly
- What is MU-MIMO and why is it important for Wi-Fi 6 and 6E?
- 【Lazy Self-Care Fish Tank Control System】Work Submission
- [Summer benefits to celebrate the Dragon Boat Festival] A large number of technical information is waiting for you to claim, and there are also gifts to help
- Please help me find which resistor in the picture is the 1.1K resistor in the formula?
- Xiaozhi Science Popularization丨How to Correctly Understand Power Supply Ripple and Noise
- Find the maximum voltage stress of the diode when it is working
- About QQ Chat at Work
- Naming method of TMS320 chip