Test Code for TEA5767 radio module

Dependencies:   MODSERIAL TEA5767 mbed

Files at this revision

API Documentation at this revision

Comitter:
edodm85
Date:
Thu Oct 03 19:18:22 2013 +0000
Child:
1:6ad6d1d3bbdf
Commit message:
First version

Changed in this revision

MODSERIAL.lib Show annotated file Show diff for this revision Revisions of this file
TEA5767.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
main.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MODSERIAL.lib	Thu Oct 03 19:18:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TEA5767.lib	Thu Oct 03 19:18:22 2013 +0000
@@ -0,0 +1,1 @@
+TEA5767#bb7cae1d62ce
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Oct 03 19:18:22 2013 +0000
@@ -0,0 +1,128 @@
+#include "main.h"
+
+
+
+void rxCallback(MODSERIAL_IRQ_INFO *q) 
+{
+     new_send = true;
+}
+
+
+int main()
+{
+    // INIT WATCHDOG
+    w.kick(2.5);
+    
+    pc.baud(921600);
+    pc.attach(&rxCallback, MODSERIAL::RxIrq);
+    
+    if(radio.CheckDevice() == 0)
+    {   
+        pc.printf("Addr I2C found\r\n");
+        led2 = 1;
+    }else
+    {
+        pc.printf("Addr I2C not found\r\n");
+        led2 = 0;    
+    }
+    
+    while(1) 
+    { 
+        if(new_send){
+            int i = 0;
+       
+            while(pc.readable())
+            {
+                word[i] = pc.getc();
+                i++;
+            }
+            parse_cmd(); 
+        }            
+        wait_ms(50);
+        w.kick();
+    }
+}
+
+
+// US/EUROPE 87.5-108MHz   JAPANESE 76-91MHz
+float i = 0.2;
+void parse_cmd()
+{
+        new_send = false;
+        
+        if(strncmp("freq", word, 4) == 0)              
+        {
+            char word_temp[6];
+            strncpy(word_temp, &word[5], 6);
+  
+            n = atof(word_temp);                        // Convert string to double
+            
+            if((n >= StartFreq) && (n <= EndFreq))
+            {
+                radio.SetFrequency(n);
+                
+                wait_ms(200);
+
+                pc.printf("signal: %2.0d", radio.SignalLevel());
+                pc.printf("freq: %000.2f ", radio.FreqCurrent());
+                delete [] reg;
+                wait_ms(100);
+                    
+            }else
+            {
+                pc.printf("Out of range \r\n");       
+            }
+        }else
+        if(strncmp("available", word, 9) == 0)              
+        {
+            pc.printf("\r\n"); 
+            pc.printf("Current_Frequency: %.2fMHz\r\n", radio.FreqCurrent());
+            pc.printf("Signal_Level: %2.0d\r\n", radio.SignalLevel());
+        }else
+        if(strncmp("search_up", word, 9) == 0)              
+        {
+            float freq_av = radio.FreqCurrent();
+            if(freq_av-i > 108)
+            {
+                freq_av = 108;
+            }
+            radio.SearchUp(freq_av+i);
+            wait_ms(300);
+            pc.printf("signal: %2.0d", radio.SignalLevel());
+            pc.printf("freq: %000.2f ", radio.FreqCurrent());
+        }else
+        if(strncmp("search_down", word, 11) == 0)              
+        {    
+            float freq_av = radio.FreqCurrent();
+            if(freq_av-i < 87.5)
+            {
+                freq_av = 87.5;
+            }
+            radio.SearchUp(freq_av-i);
+            wait_ms(300);
+            pc.printf("signal: %2.0d", radio.SignalLevel());
+            pc.printf("freq: %000.2f ", radio.FreqCurrent());                      
+        }else
+        if(strncmp("band", word, 4) == 0)              
+        {
+            char word_temp[2];
+            strncpy(word_temp, &word[5], 2);      
+            pc.printf("string: %s\r\n", word_temp);
+            
+            if(strncmp("EU", word_temp, 2) == 0)
+            {
+                radio.SetBand('e');
+                StartFreq = 87.5;
+                EndFreq = 108;
+            }else
+            if(strncmp("JP", word_temp, 2) == 0)
+            {
+                radio.SetBand('j');
+                StartFreq = 76;
+                EndFreq = 91;
+            }
+        }
+            
+        memset(word, 0, sizeof(word));
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Thu Oct 03 19:18:22 2013 +0000
@@ -0,0 +1,51 @@
+#pragma once 
+#include "mbed.h"
+#include "TEA5767.h"
+#include "MODSERIAL.h"
+
+DigitalOut led2(LED2);
+DigitalOut led4(LED4);
+
+//WATCHDOG
+class Watchdog 
+{
+public:
+    void kick(float s) 
+    {
+        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+        uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4 
+        LPC_WDT->WDTC = s * (float)clk;         
+        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset        
+        kick();
+    }
+    
+    void kick() 
+    {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+ 
+Watchdog w;
+
+
+
+// TEA5767  IC2 address is 0x60, reading is 0x61
+#define W_ADDR 0xC0
+
+MODSERIAL pc(USBTX,USBRX);
+
+TEA5767 radio(p28, p27, W_ADDR);        // sda - scl
+bool new_send = false;
+char word[25];
+float n = 0;
+char reg[5];
+float StartFreq = 87.5;
+float EndFreq = 108;
+
+//RESET
+extern "C" void mbed_reset();
+
+
+
+void parse_cmd();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Oct 03 19:18:22 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file