FM-test

Dependencies:   MODSERIAL mbed-rtos mbed

Fork of Master by Ohnishi_Gundan

Files at this revision

API Documentation at this revision

Comitter:
9uS7
Date:
Sat Sep 13 09:42:55 2014 +0000
Parent:
7:67720739ca77
Child:
9:6057314dc8ec
Commit message:
bluetoothable

Changed in this revision

bluetooth.cpp Show annotated file Show diff for this revision Revisions of this file
control.cpp Show annotated file Show diff for this revision Revisions of this file
fm.cpp Show annotated file Show diff for this revision Revisions of this file
fm.h 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
--- a/bluetooth.cpp	Fri Sep 12 23:01:17 2014 +0000
+++ b/bluetooth.cpp	Sat Sep 13 09:42:55 2014 +0000
@@ -1,17 +1,15 @@
 #include "mbed.h"
 #include "bluetooth.h"
 #include "control.h"
-#include "MODSERIAL.h"
+#include "RawSerial.h"
 
-//master
-//Serial bt(p13, p14);  // tx, rx
-//slave
-Serial bt(p28, p27);
+RawSerial bt(p28, p27);  // tx, rx
 
-Serial pc(USBTX, USBRX);   // tx, rx
+RawSerial pc(USBTX, USBRX);   // tx, rx
 
 DigitalOut l1(LED1);
 DigitalOut l2(LED2);
+DigitalOut l3(LED3);
 DigitalOut l4(LED4);
 
 void btSetup(int role)
@@ -36,7 +34,7 @@
     Cvt temp;
     
     //making pac
-    pac[0] = option;
+    pac[0]=option;
     if( option==SYNC_MOTOR ){
         //PACK:     [option/function/pwm*4]
         //function
@@ -73,11 +71,15 @@
     
     wait(1/1000.0);
     
-    l1=( l1 ? 0 : 1 );
+    //l1=( l1 ? 0 : 1 );
+    
+    l4=1;
     
     for( int i=0 ; i<PACK_SIZE ; i++ ){
         buf[i]=bt.getc();
-    }  
+    }
+    
+    l3=1;
  
     if( buf[0]==SYNC_MOTOR ){
         //PACK:     [option/function/pwm*4]
@@ -91,14 +93,14 @@
         //PACK:     [option/request]
         ;       //not yet
     }
-    else if( buf[0]==SYNC_SENSOR ){        
+    else if( buf[0]==SYNC_SENSOR ){
+        l2=1;    
         getSensor( &(val[0]), &(val[1]) );
         //PACK:     [option/ir*4/fsr*4];
         //option
         pac[0] = SYNC_SENSOR;
         //ir
         temp.fl = val[0];
-        temp.fl = ++i%2;
         for( int i=0 ; i<4 ; i++ ){
             pac[1+i] = temp.byte[i];    
         }
@@ -107,7 +109,7 @@
         for( int i=0 ; i<4 ; i++ ){
             pac[5+i] = temp.byte[i];    
         }
-        
+        pc.printf( "%f\n", val[1] );
         //send pac
         for( int i=0 ; i<PACK_SIZE ; i++ ){
             bt.putc( pac[i] );
@@ -132,31 +134,43 @@
     char buf[PACK_SIZE]={};
     Cvt temp;
     
-    wait(0.05);
+    sync(SYNC_SENSOR,NULL,NULL);
+    wait(0.0001);
     
     l1= l1 ? 0 : 1;
-    
-    for( int i=0 ; ; i++ ){
+           
+    //Read
+    for(int i=0 ;;){
         if( bt.readable() ){
+            buf[0]=bt.getc();
             pc.printf("readable\n");
-            wait(0.05);
+            for( int j=1 ; j<PACK_SIZE ;){
+                if(bt.readable()){
+                    buf[j]=bt.getc();
+                    j++;
+                }else{
+                    pc.printf("hoge:%d\n",j);   
+                    break; 
+                }
+            }
             break;
         }
-        else if( i>5 ){
-            l4 = 0;
-            pc.printf("not readable\n");
-            return;
+        else{
+            i++;
+            if( i>5 ){
+                l4 = 0;
+                pc.printf("not readable\n");
+                return;
+            }
         }    
     }
     
-    l4 = 1;
-
-    //Read
+   
     for( int i=0 ; i<PACK_SIZE ; i++ ){
-        buf[i]=bt.getc();
+        pc.printf("%02x ",buf[i]);
     }
-    
-    return;
+    pc.printf("\n");
+    l4 = 1;
     
     //PACK:     [option/ir*4/fsr*4];
     //option
@@ -175,5 +189,7 @@
         temp.byte[i] = buf[5+i];    
     }
     *_fsr = temp.fl;
+    
+    pc.printf( "%f %f\n", *_ir, *_fsr );
         
 }
\ No newline at end of file
--- a/control.cpp	Fri Sep 12 23:01:17 2014 +0000
+++ b/control.cpp	Sat Sep 13 09:42:55 2014 +0000
@@ -2,14 +2,16 @@
 #include "control.h"
 
 //sensor
-AnalogIn IR(p17);
-AnalogIn FSR(p18);
+AnalogIn IR(p20);
+AnalogIn FSR(p19);
 
 //motor
 DigitalOut Sig1(p21);
 DigitalOut Sig2(p23);
 PwmOut Pwm(p22);
 
+RawSerial c_pc(USBTX, USBRX);   // tx, rx
+
 void motorSetup(void){
     resetPos();    
 }
@@ -76,4 +78,5 @@
 void getSensor(float* _ir,float* _fsr){
     *_ir = IR;
     *_fsr = FSR;
+    c_pc.printf("%f\n",*_fsr);
 }
\ No newline at end of file
--- a/fm.cpp	Fri Sep 12 23:01:17 2014 +0000
+++ b/fm.cpp	Sat Sep 13 09:42:55 2014 +0000
@@ -4,12 +4,14 @@
 
 I2C i2c(p9,p10);    // SDA,SCI
 
+DigitalOut f_led1(LED1);
+
 void fmSetup(unsigned int _f)
 {
     char freqH = 0, freqL = 0;//, c, i;
     unsigned int frequencyB, freq, freqB;
     const int addr = 0x11 << 1;
-    
+        
     freq = _f;         //freq/10.MHz   760~910
     if(freq > 870){
         freqB = freq - 870;
@@ -24,7 +26,7 @@
     i2c.start();
     i2c.write(addr);
     i2c.write(0x02);
-    i2c.write(0xC0);
+    i2c.write(0xF0);
     i2c.write(0x03);
     i2c.stop();
     wait(0.5);                        // wait 500ms
@@ -32,7 +34,7 @@
     i2c.start();
     i2c.write(addr);
     i2c.write(0x02);
-    i2c.write(0xC0);
+    i2c.write(0xF0);
     i2c.write(0x0D);
     i2c.stop();
     wait(0.5);   
@@ -69,8 +71,8 @@
     i2c.start();
     i2c.write(addr);
     i2c.write(0x42);
-    i2c.write(0x03);
-    i2c.write(0x0F);
+    i2c.write(0x00);    // Vin PtP set max:111b(0.009V) min000b(1.2V) 
+    i2c.write(0x07);    // FMout Antena Gain max:111111b(0x3F) min:000000b
     i2c.stop();
    
     wait(0.5);
--- a/fm.h	Fri Sep 12 23:01:17 2014 +0000
+++ b/fm.h	Sat Sep 13 09:42:55 2014 +0000
@@ -5,7 +5,7 @@
 
 //define frequency 760~910
 #define FM_FREQUENCY1 792
-#define FM_FREQUENCY2 898
+#define FM_FREQUENCY2 856
 
 void fmSetup(unsigned int);     //setup i2c (int frequency) frequency:760~910
 
--- a/main.cpp	Fri Sep 12 23:01:17 2014 +0000
+++ b/main.cpp	Sat Sep 13 09:42:55 2014 +0000
@@ -44,7 +44,6 @@
 void masterLoop(){
     float ir_m,fsr_m;   //sensor of master
     float ir_s,fsr_s;   //sensor of slave
-    sync(SYNC_SENSOR,NULL,NULL);
     recieveSensor( &ir_s, &fsr_s );
     led4 = ( ir_s>0.5 ? 1 : 0 );
     led2 = ( led2 ? 0 : 1 );