RDA5807M FM RDS radio using the Gecko Segment LCD display. PC serial is used to display the RDS text on a pc terminal program if required (115200 baud). The two press buttons to tune up or down, touch slider to change volume. Top numeric displays frequency, bottom alpha displays station name. Ring segment displays signal level, antenna segment indicates stereo received.

Dependencies:   EFM32_CapSenseSlider EFM32_SegmentLCD RDA5807M mbed-src

Files at this revision

API Documentation at this revision

Comitter:
star297
Date:
Sat May 23 14:48:15 2015 +0000
Parent:
1:2bca6370ae45
Child:
3:1220287bcbd7
Commit message:
V1.0

Changed in this revision

EFM32_CapSense.lib Show annotated file Show diff for this revision Revisions of this file
EFM32_SegmentLCD.lib Show annotated file Show diff for this revision Revisions of this file
RDA5807M.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
mbed.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EFM32_CapSense.lib	Sat May 23 14:48:15 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/SiliconLabs/code/EFM32_CapSenseSlider/#8d096e5bc045
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EFM32_SegmentLCD.lib	Sat May 23 14:48:15 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/SiliconLabs/code/EFM32_SegmentLCD/#114aa75da77b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RDA5807M.lib	Sat May 23 14:48:15 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/star297/code/RDA5807M/#cf256181972f
--- a/main.cpp	Wed Apr 29 07:33:32 2015 -0700
+++ b/main.cpp	Sat May 23 14:48:15 2015 +0000
@@ -1,15 +1,173 @@
+/*
+RDA5807M FM RDS Radio using the EFM32 Gecko Segment LCD
+RDS information is displayed using a PC terminal
+
+Use:
+switches PB0 and PB1 for frequency search
+Volume controlled by the Touch Slider
+Indicators: 
+Signal level - Ring Segement Display
+Stereo received - Antenna Segment Display
+RDS available - LED0
+*/
+
 #include "mbed.h"
+#include "RDA5807M.h"
+#include "EFM32_SegmentLCD.h"
+#include "EFM32_CapSenseSlider.h"
+
+ 
+RDA5807M radio(PC4, PC5);   // sda - scl
+
+Serial pc(USBTX, USBRX);
+
+InterruptIn scan_up(SW1);
+InterruptIn scan_down(SW0); 
+
+DigitalOut led1(LED1);
+DigitalOut led0(LED0);
+
+silabs::EFM32_SegmentLCD segmentDisplay;
+silabs::EFM32_CapSenseSlider capSlider;
+
+Timer t1;
  
-DigitalOut myled(LED1);
-LowPowerTicker toggleTicker;
+int n,i,l,signal,lastsignal,volume,lastrds,laststereo,rdstextgood;
+float lastfreq;
+char Station[10],lastStationName[10],vol[4];
+char RDStxt[70],RDStxt1[70],RDStxt2[70],text1[50],lasttext1[50],text2[50],lasttext2[50];
+
+void displayrefresh(),getrds();
+
+void scan_upIRQ() {
+    radio.SeekUp(); 
+}  
+
+void scan_downIRQ() {
+    radio.SeekDown();    
+}
 
-void ledToggler(void) {
-    myled = !myled;
+void slideCallback(void) {
+    volume = capSlider.get_position()/3;        
+    if(volume > 15){volume = 15;}
+    if(volume < 0){volume = 0;}  
+    radio.Volume(volume);
+    sprintf(vol,"Vol %d", volume);
+    segmentDisplay.Write(vol);
+    t1.reset();t1.start();  
+}  
+ 
+int main() { 
+
+    radio.Reset();      // reset and power up radio chip 
+    segmentDisplay.Write("RdA5807");
+    wait(1); 
+    segmentDisplay.Write("RDS FM");
+    wait(1);
+    segmentDisplay.Write("Radio");    
+    capSlider.start();
+    capSlider.attach_slide(-1, slideCallback);   
+    scan_up.fall(scan_upIRQ);     
+    scan_down.rise(scan_downIRQ); 
+    wait(1);     
+    
+    while(1){    
+        radio.processData();
+        displayrefresh();
+        getrds();              
+        wait_ms(50);
+        if(t1.read()>3){strcpy(lastStationName," ");t1.stop();}        
+    }
 }
+
+void displayrefresh()
+{   
+    if (strcmp(lastStationName, radio.StationName) != 0){
+        if(strlen(radio.StationName)<9){
+            n=0;for(i=0;i<(8);i++){ // remove non-printable ASCCi error characters               
+                if(radio.StationName[i] > 31){          
+                    Station[n] = radio.StationName[i];         
+                    n++;
+                    }
+                }              
+            segmentDisplay.Write(Station);
+            strcpy(lastStationName,radio.StationName);
+            }
+        }    
+    if(lastfreq != radio.freq/1000){lastfreq = radio.freq/1000;
+        if(radio.freq<100000){            
+            segmentDisplay.Number(radio.freq/10);segmentDisplay.Symbol(LCD_SYMBOL_DP10,1);
+            }
+            else {segmentDisplay.Number(radio.freq/100);segmentDisplay.Symbol(LCD_SYMBOL_DP10,0);}
+        rdstextgood=0;lastrds=!lastrds;
+        }
+    if(laststereo != radio.stereo){
+        if(radio.stereo){segmentDisplay.Symbol(LCD_SYMBOL_ANT,1);}
+            else{segmentDisplay.Symbol(LCD_SYMBOL_ANT,0);}
+        laststereo = radio.stereo;
+        }        
+    if(lastsignal != radio.signal){
+        signal=radio.signal;
+        for (i = 0; i < 8; i++)
+            {segmentDisplay.ARing(i, 0);}    
+        if(signal>4){segmentDisplay.ARing(0, 1);}
+        if(signal>9){segmentDisplay.ARing(1, 1);}
+        if(signal>14){segmentDisplay.ARing(2, 1);}
+        if(signal>19){segmentDisplay.ARing(3, 1);}
+        if(signal>25){segmentDisplay.ARing(4, 1);}
+        if(signal>30){segmentDisplay.ARing(5, 1);}
+        if(signal>35){segmentDisplay.ARing(6, 1);}
+        if(signal>40){segmentDisplay.ARing(7, 1);}        
+        lastsignal=radio.signal;       
+        }
+    if(lastrds != radio.rds){
+        if(radio.rds){
+            if(rdstextgood){led0=1;}
+                else{led0=0;}
+                }
+            else{led0=0;rdstextgood=0;}               
+        lastrds=radio.rds;
+        }                          
+    if (strcmp(text1, lasttext1) != 0){        
+        pc.printf(Station);
+        pc.printf("\n %s\n",text1);
+        memset(lasttext1, '\0', sizeof(lasttext1));strcpy(lasttext1, text1);}
+    if (strcmp(text2, lasttext2) != 0){
+        pc.printf(" %s\n\n",text2);
+        memset(lasttext2, '\0', sizeof(lasttext2));strcpy(lasttext2, text2);}    
+}       
+
+void getrds()
+{    
+    if(strlen(radio.RDSText)==64 && signal>23){               
+        memset(text1, '\0', sizeof(text1));
+        memset(text2, '\0', sizeof(text2));
+        if(!rdstextgood){rdstextgood=1;lastrds=!lastrds;}        
+    // remove non-printable ASCCi error characters        
+        n=0;
+        for(i=0;i<(64);i++){                
+            if(radio.RDSText[i] > 31){          
+                RDStxt[n] = radio.RDSText[i];         
+                n++;
+            }
+        }                              
+    // slit into 2 lines of text seperated by 'space'
+        strcpy(RDStxt1,RDStxt);    
+        for ( i = 0; i < (n); i++ ){
+            if (i>30 && (RDStxt1[i] == ' ') ){              
+                RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';               
+                l=strlen(RDStxt1);
+                i=n;
+            } }                 
+        strcpy (RDStxt2, RDStxt + l);
+        while(RDStxt2[0]==' '){
+            strcpy (RDStxt2, (RDStxt2 + 1));
+            }
+        if(strlen(RDStxt1)<40){strcpy (text1, RDStxt1);}
+        if(strlen(RDStxt2)<40){strcpy (text2, RDStxt2);}
+        
+        memset(radio.RDSText, '\0', sizeof(radio.RDSText));      
+    }
+}
+
  
-int main() {
-    toggleTicker.attach(&ledToggler, 0.2f);
-    while(1) {
-        sleep();
-    }
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Sat May 23 14:48:15 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/mbed_official/code/mbed-src/#7f313a59e20c
--- a/mbed.lib	Wed Apr 29 07:33:32 2015 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://developer.mbed.org/users/mbed_official/code/mbed-src/#8bb0742e5907
\ No newline at end of file