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

Committer:
star297
Date:
Fri Jun 19 19:24:01 2015 +0000
Revision:
4:3bf9d70a48c8
Parent:
3:1220287bcbd7
RDS text update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 2:893e9004c547 1 /*
star297 2:893e9004c547 2 RDA5807M FM RDS Radio using the EFM32 Gecko Segment LCD
star297 2:893e9004c547 3 RDS information is displayed using a PC terminal
star297 4:3bf9d70a48c8 4
star297 2:893e9004c547 5 Use:
star297 2:893e9004c547 6 switches PB0 and PB1 for frequency search
star297 2:893e9004c547 7 Volume controlled by the Touch Slider
star297 2:893e9004c547 8 Indicators:
star297 2:893e9004c547 9 Signal level - Ring Segement Display
star297 2:893e9004c547 10 Stereo received - Antenna Segment Display
star297 2:893e9004c547 11 RDS available - LED0
star297 2:893e9004c547 12 */
star297 4:3bf9d70a48c8 13
stevew817 0:b0927d62ef70 14 #include "mbed.h"
star297 2:893e9004c547 15 #include "RDA5807M.h"
star297 2:893e9004c547 16 #include "EFM32_SegmentLCD.h"
star297 2:893e9004c547 17 #include "EFM32_CapSenseSlider.h"
star297 4:3bf9d70a48c8 18
star297 2:893e9004c547 19
star297 2:893e9004c547 20 RDA5807M radio(PC4, PC5); // sda - scl
star297 4:3bf9d70a48c8 21
star297 2:893e9004c547 22 Serial pc(USBTX, USBRX);
star297 4:3bf9d70a48c8 23
star297 2:893e9004c547 24 InterruptIn scan_up(SW1);
star297 2:893e9004c547 25 InterruptIn scan_down(SW0);
star297 4:3bf9d70a48c8 26
star297 2:893e9004c547 27 DigitalOut led1(LED1);
star297 2:893e9004c547 28 DigitalOut led0(LED0);
star297 4:3bf9d70a48c8 29
star297 2:893e9004c547 30 silabs::EFM32_SegmentLCD segmentDisplay;
star297 2:893e9004c547 31 silabs::EFM32_CapSenseSlider capSlider;
star297 4:3bf9d70a48c8 32 LowPowerTimeout wakeup;
star297 4:3bf9d70a48c8 33
star297 2:893e9004c547 34 Timer t1;
stevew817 0:b0927d62ef70 35
star297 4:3bf9d70a48c8 36 int x,n,i,l,wake,signal,lastsignal,volume,laststereo;
star297 2:893e9004c547 37 float lastfreq;
star297 3:1220287bcbd7 38 char Station[10],lastStationName[10],vol[4],lastCT[12];
star297 3:1220287bcbd7 39 char RDStxt[70],RDStxt1[70],RDStxt2[70],text1[70],lasttext1[70],text2[70],lasttext2[70];
star297 4:3bf9d70a48c8 40
star297 4:3bf9d70a48c8 41 void displayrefresh(),getrds(),RTrefresh();
star297 4:3bf9d70a48c8 42
star297 2:893e9004c547 43 void scan_upIRQ() {
star297 2:893e9004c547 44 radio.SeekUp();
star297 2:893e9004c547 45 }
star297 4:3bf9d70a48c8 46
star297 2:893e9004c547 47 void scan_downIRQ() {
star297 2:893e9004c547 48 radio.SeekDown();
star297 2:893e9004c547 49 }
stevew817 0:b0927d62ef70 50
star297 4:3bf9d70a48c8 51 void callback(void) {
star297 4:3bf9d70a48c8 52 wake = 1;
star297 4:3bf9d70a48c8 53 }
star297 4:3bf9d70a48c8 54
star297 2:893e9004c547 55 void slideCallback(void) {
star297 2:893e9004c547 56 volume = capSlider.get_position()/3;
star297 2:893e9004c547 57 if(volume > 15){volume = 15;}
star297 2:893e9004c547 58 if(volume < 0){volume = 0;}
star297 2:893e9004c547 59 radio.Volume(volume);
star297 2:893e9004c547 60 sprintf(vol,"Vol %d", volume);
star297 2:893e9004c547 61 segmentDisplay.Write(vol);
star297 2:893e9004c547 62 t1.reset();t1.start();
star297 2:893e9004c547 63 }
star297 2:893e9004c547 64
star297 2:893e9004c547 65 int main() {
star297 4:3bf9d70a48c8 66
star297 2:893e9004c547 67 radio.Reset(); // reset and power up radio chip
star297 2:893e9004c547 68 segmentDisplay.Write("RdA5807");
star297 2:893e9004c547 69 wait(1);
star297 2:893e9004c547 70 segmentDisplay.Write("RDS FM");
star297 2:893e9004c547 71 wait(1);
star297 2:893e9004c547 72 segmentDisplay.Write("Radio");
star297 2:893e9004c547 73 capSlider.start();
star297 2:893e9004c547 74 capSlider.attach_slide(-1, slideCallback);
star297 2:893e9004c547 75 scan_up.fall(scan_upIRQ);
star297 2:893e9004c547 76 scan_down.rise(scan_downIRQ);
star297 2:893e9004c547 77 wait(1);
star297 2:893e9004c547 78
star297 2:893e9004c547 79 while(1){
star297 3:1220287bcbd7 80 radio.ProcessData();
star297 2:893e9004c547 81 displayrefresh();
star297 4:3bf9d70a48c8 82 getrds();
star297 4:3bf9d70a48c8 83 if(t1.read()>3){strcpy(lastStationName," ");t1.stop();}
star297 4:3bf9d70a48c8 84 wait_ms(1);
star297 4:3bf9d70a48c8 85 wakeup.attach(callback, 0.05f); // MCU average power now 1mA
star297 4:3bf9d70a48c8 86 wake = 0;
star297 4:3bf9d70a48c8 87 while(!wake) sleep();
star297 2:893e9004c547 88 }
stevew817 0:b0927d62ef70 89 }
star297 4:3bf9d70a48c8 90
star297 2:893e9004c547 91 void displayrefresh()
star297 2:893e9004c547 92 {
star297 2:893e9004c547 93 if (strcmp(lastStationName, radio.StationName) != 0){
star297 2:893e9004c547 94 if(strlen(radio.StationName)<9){
star297 2:893e9004c547 95 n=0;for(i=0;i<(8);i++){ // remove non-printable ASCCi error characters
star297 2:893e9004c547 96 if(radio.StationName[i] > 31){
star297 2:893e9004c547 97 Station[n] = radio.StationName[i];
star297 2:893e9004c547 98 n++;
star297 2:893e9004c547 99 }
star297 2:893e9004c547 100 }
star297 2:893e9004c547 101 segmentDisplay.Write(Station);
star297 3:1220287bcbd7 102 pc.printf("Station:\n%s\n\n",Station);
star297 2:893e9004c547 103 strcpy(lastStationName,radio.StationName);
star297 2:893e9004c547 104 }
star297 2:893e9004c547 105 }
star297 2:893e9004c547 106 if(lastfreq != radio.freq/1000){lastfreq = radio.freq/1000;
star297 2:893e9004c547 107 if(radio.freq<100000){
star297 2:893e9004c547 108 segmentDisplay.Number(radio.freq/10);segmentDisplay.Symbol(LCD_SYMBOL_DP10,1);
star297 2:893e9004c547 109 }
star297 2:893e9004c547 110 else {segmentDisplay.Number(radio.freq/100);segmentDisplay.Symbol(LCD_SYMBOL_DP10,0);}
star297 3:1220287bcbd7 111 led0=0;
star297 2:893e9004c547 112 }
star297 2:893e9004c547 113 if(laststereo != radio.stereo){
star297 2:893e9004c547 114 if(radio.stereo){segmentDisplay.Symbol(LCD_SYMBOL_ANT,1);}
star297 2:893e9004c547 115 else{segmentDisplay.Symbol(LCD_SYMBOL_ANT,0);}
star297 2:893e9004c547 116 laststereo = radio.stereo;
star297 2:893e9004c547 117 }
star297 2:893e9004c547 118 if(lastsignal != radio.signal){
star297 2:893e9004c547 119 signal=radio.signal;
star297 2:893e9004c547 120 for (i = 0; i < 8; i++)
star297 2:893e9004c547 121 {segmentDisplay.ARing(i, 0);}
star297 2:893e9004c547 122 if(signal>4){segmentDisplay.ARing(0, 1);}
star297 2:893e9004c547 123 if(signal>9){segmentDisplay.ARing(1, 1);}
star297 2:893e9004c547 124 if(signal>14){segmentDisplay.ARing(2, 1);}
star297 2:893e9004c547 125 if(signal>19){segmentDisplay.ARing(3, 1);}
star297 2:893e9004c547 126 if(signal>25){segmentDisplay.ARing(4, 1);}
star297 2:893e9004c547 127 if(signal>30){segmentDisplay.ARing(5, 1);}
star297 2:893e9004c547 128 if(signal>35){segmentDisplay.ARing(6, 1);}
star297 2:893e9004c547 129 if(signal>40){segmentDisplay.ARing(7, 1);}
star297 2:893e9004c547 130 lastsignal=radio.signal;
star297 2:893e9004c547 131 }
star297 3:1220287bcbd7 132 if(strcmp(RDStxt1, lasttext1) != 0 || strcmp(RDStxt2, lasttext2) != 0){
star297 4:3bf9d70a48c8 133 RTrefresh();
star297 4:3bf9d70a48c8 134 }
star297 4:3bf9d70a48c8 135 if(strcmp(lastCT, radio.CTtime) !=0){
star297 4:3bf9d70a48c8 136 pc.printf("Time: %s\n",radio.CTtime);
star297 4:3bf9d70a48c8 137 strcpy(lastCT,radio.CTtime);
star297 4:3bf9d70a48c8 138 if(led0==1){RTrefresh();}
star297 4:3bf9d70a48c8 139 }
star297 4:3bf9d70a48c8 140 }
star297 4:3bf9d70a48c8 141
star297 4:3bf9d70a48c8 142 void RTrefresh()
star297 4:3bf9d70a48c8 143 {
star297 3:1220287bcbd7 144 pc.printf("\n-------------------------------------------\n");
star297 3:1220287bcbd7 145 pc.printf("Station:\n%s\n\n",Station);
star297 3:1220287bcbd7 146 pc.printf("RT:\n%s\n",RDStxt1);
star297 3:1220287bcbd7 147 pc.printf("%s\n\n",RDStxt2);
star297 3:1220287bcbd7 148 pc.printf("Time: %s\n",radio.CTtime);
star297 3:1220287bcbd7 149 memset(lasttext1, '\0', sizeof(lasttext1));strcpy(lasttext1, RDStxt1);
star297 3:1220287bcbd7 150 memset(lasttext2, '\0', sizeof(lasttext2));strcpy(lasttext2, RDStxt2);
star297 3:1220287bcbd7 151 led0=1;
star297 4:3bf9d70a48c8 152 }
star297 4:3bf9d70a48c8 153
star297 2:893e9004c547 154 void getrds()
star297 2:893e9004c547 155 {
star297 3:1220287bcbd7 156 if(strlen(radio.RDSText)>3){
star297 3:1220287bcbd7 157 memset(RDStxt1, '\0', sizeof(RDStxt1));
star297 3:1220287bcbd7 158 memset(RDStxt2, '\0', sizeof(RDStxt2));
star297 3:1220287bcbd7 159
star297 3:1220287bcbd7 160 // format into 2 lines of text seperated by first 'space' after 30 characters
star297 3:1220287bcbd7 161 strcpy(RDStxt1,radio.RDSText);
star297 3:1220287bcbd7 162 n=strlen(RDStxt1);
star297 2:893e9004c547 163 for ( i = 0; i < (n); i++ ){
star297 2:893e9004c547 164 if (i>30 && (RDStxt1[i] == ' ') ){
star297 2:893e9004c547 165 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';
star297 2:893e9004c547 166 l=strlen(RDStxt1);
star297 3:1220287bcbd7 167 x=1;
star297 3:1220287bcbd7 168 break; // break if more than 30 characters with space
star297 3:1220287bcbd7 169 }
star297 3:1220287bcbd7 170 if(i>39){
star297 3:1220287bcbd7 171 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';
star297 3:1220287bcbd7 172 l=strlen(RDStxt1);
star297 3:1220287bcbd7 173 x=1;
star297 3:1220287bcbd7 174 break; //break if more than 39 characters with no spaces
star297 3:1220287bcbd7 175 }
star297 2:893e9004c547 176 }
star297 3:1220287bcbd7 177 if(x==1){
star297 3:1220287bcbd7 178 strcpy (RDStxt2, radio.RDSText + l);
star297 3:1220287bcbd7 179 while(RDStxt2[0]==' '){
star297 3:1220287bcbd7 180 strcpy (RDStxt2, (RDStxt2 + 1));
star297 3:1220287bcbd7 181 }
star297 3:1220287bcbd7 182 x=0;
star297 3:1220287bcbd7 183 }
star297 3:1220287bcbd7 184 }
star297 4:3bf9d70a48c8 185 }