LPC1114 driver RDA5820 FM radio program

Publisher:rnm888Latest update time:2016-12-09 Source: eefocusKeywords:lpc1114 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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
        }
    }
}


Keywords:lpc1114 Reference address:LPC1114 driver RDA5820 FM radio program

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

LPC1114 System Timer (SysTick)
There is a special timer inside LPC1114 - System Timer (SysTick), which is located in the Cortex-M0 core and is part of the ARM core. It is mainly used to provide the operating system with a time slice rotation timing, which is generally fixed to 10ms, so it is also called the "tick" timer in Chinese. When the operatin
[Microcontroller]
LPC1114 System Timer (SysTick)
Comparison between LPC1114/LPC11U14 and LPC1343 (V) UART
LPC1114/LPC1343 serial port features: 16-byte transmit and receive FIFO; The register location complies with the 16C550 industrial standard; The receiver FIFO trigger point can be 1, 4, 8, and 14 bytes; Built-in baud rate generator; Fractional divider for precise baud rate control, with automatic baud ra
[Microcontroller]
Comparison between LPC1114/LPC11U14 and LPC1343 (V) UART
LPC1114 MCU OLED Driver
The contents of the oled.c file are as follows: #include "oled.h" #include "lpc11xx.h" #include "w25q16.h" //YOU ARE // // 0 1 2 3 ... 127     // 0 1 2 3 ... 127     // 0 1 2 3 ... 127     // 0 1 2 3 ... 127 uint8_t OLED_GRAM ; const unsigned char menu_op ={ {0x08,0x08,0x1C,0x1C,0x3E,0x08,0x08,0x08,0x08,0x08,0x08,0x
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号