加速度計まで実装した相互通信動くやつ、レシーバー

Dependencies:   ADXL345_I2C mbed INA226

Fork of RS485R_2 by hiroya taura

Revision:
5:9e817c18440a
Parent:
4:dbe62d9b6087
Child:
6:f4c149a72dfb
--- a/main.cpp	Thu Dec 31 17:28:18 2015 +0000
+++ b/main.cpp	Sat Jan 02 07:13:43 2016 +0000
@@ -28,25 +28,45 @@
     switch(rec_data) {
         case 'A':
             servo_deg1 = rs485.getc();
-            pc.printf("counter1:%d\n\r",servo_deg1);
+           // pc.printf("counter1:%d\n\r",servo_deg1);
             break;
         case 'B':
             servo_deg2 = rs485.getc();
             //pc.printf("counter2:%d\n\r",servo_deg2);
             break;
         case 'C':
+        
+    counter++;
+    if(counter > 1000){
+    counter = 0;
+    }
             Receiver = 1;
-            wait_us(500);
-            rs485.putc('X');
+            wait_ms(3);
+            if(counter % 2 == 0){
+           rs485.putc('X');
+          // pc.printf("X");
             rs485.putc((signed char)acc[0]);
+            //pc.printf("%5d",(signed char)acc[0]);
             rs485.putc('Y');
+            //pc.printf("Y");
             rs485.putc((signed char)acc[1]);
+           // pc.printf("%5d",(signed char)acc[1]);
             rs485.putc('Z');
+            //pc.printf("Z");
             rs485.putc((signed char)acc[2]);
+            }
+            else{
+           // pc.printf("%5d",(signed char)acc[2]);
             rs485.putc('V');
+           // pc.printf("V");
             rs485.putc((signed char)*Voltage);
+          //  pc.printf("%5d",(signed char)*Voltage);
             rs485.putc('C');
+            //pc.printf("C");
             rs485.putc((signed char)*Current);
+            //pc.printf("%5d",(signed char)*Current);
+            }
+            //pc.printf("\n\r");
 //            rs485.printf("X%iY%iZ%i\n\r",(short)acc[0],(short)acc[1],(short)acc[2]);
             wait_ms(2);
             Receiver = 0;
@@ -54,7 +74,7 @@
             break;
         default:
             wait_us(5);
-            pc.printf("%d\n\r",rec_data);
+          //  pc.printf("%d\n\r",rec_data);
     }
 }
 
@@ -84,7 +104,6 @@
 
 int main()
 {
-    rs485.baud(14400);
     init();
     while(1) {
         accelerometer.getOutput(acc);