TVZ test

Dependencies:   mbed

Fork of SerialMBEDtoMSP430 by Ljubivoj Cvitas

Revision:
3:a4a5d9c0bc13
Parent:
2:2e261aa02cd0
Child:
4:4620184bbb1f
--- a/main.cpp	Wed Jan 08 14:09:05 2014 +0000
+++ b/main.cpp	Tue Jan 21 18:40:20 2014 +0000
@@ -9,26 +9,30 @@
 DigitalIn switch_ip2(p6);
 Serial pc(USBTX, USBRX);
 
-char switch_word ;                   //the word we will send
+char header_read ;                   //first byte we will send
+char param_ads;                      // parameter address
 char recd_val;                       //the received value 
 int valueADC;
-char Outbuff[2];
-char Inbuff[2];
-int valueSensA;
+char Outbuff[12];
+char Inbuff[12];
+int valueSensA, valueSensB;
   
 int main() {
   async_port.baud(9600);             //set baud rate to 9600 (ie default)
   //accept default format, of 8 bits, no parity
   while (1){
     //Set up the word to be sent, by testing switch inputs
-    switch_word=0xa0;                 //set up a recognisable output pattern
+    header_read=0x10;                 //set up a recognisable output pattern
+    param_ads = 0;
     if (switch_ip1==1)
-      switch_word=switch_word|0x01;   //OR in lsb
+      param_ads =param_ads | 0x01;   //OR in lsb
     if (switch_ip2==1)
-      switch_word=switch_word|0x02;   //OR in next lsb
+      param_ads =param_ads | 0x02;   //OR in next lsb
+      
     strobe =1;                        //short strobe pulse 
     wait_us(10);
     strobe=0;
+    
     valueADC = 0x0302;
     Outbuff[0] = valueADC;
     Outbuff[1] = valueADC >> 8;
@@ -39,12 +43,34 @@
     async_port.putc(Outbuff[0]);     //transmit switch_word
     */
     while (async_port.writeable()==0);  //is there a place to write?
-    async_port.putc(switch_word);     //transmit switch_word
+    async_port.putc(header_read);       //transmit haeder
+    while (async_port.writeable()==0);  //is there a place to write?
+    async_port.putc(param_ads);         //transmit parameter address
+    
+    
+    
+    if (async_port.readable()==1){     //is there a character to be read?
+      Inbuff[0] = async_port.getc();     //if yes, t
+      }
     if (async_port.readable()==1){     //is there a character to be read?
       Inbuff[1] = async_port.getc();     //if yes, t
+      }  
+    if (async_port.readable()==1){     //is there a character to be read?
+      Inbuff[2] = async_port.getc();     //if yes, t
       }
     if (async_port.readable()==1){     //is there a character to be read?
-      Inbuff[0] = async_port.getc();     //if yes, t
+      Inbuff[3] = async_port.getc();     //if yes, t
+      
+    if (async_port.readable()==1){     //is there a character to be read?
+      Inbuff[4] = async_port.getc();     //if yes, t
+      }
+    if (async_port.readable()==1){     //is there a character to be read?
+      Inbuff[5] = async_port.getc();     //if yes, t
+      }  
+    if (async_port.readable()==1){     //is there a character to be read?
+      Inbuff[6] = async_port.getc();     //if yes, t  
+      }
+      
       RXDIN = 1;
       }  
     /*if (async_port.readable()==1){     //is there a character to be read?
@@ -64,9 +90,10 @@
       red_led=1;
       green_led=1;
     }
-    wait(0.5);
+    wait(1);
     RXDIN = 0;
-    valueSensA = Inbuff[1]+ Inbuff[0]*256;
-    pc.printf("SensA:  %d  \n\r", valueSensA);
+    valueSensA = Inbuff[2]+ Inbuff[3]*256;
+    valueSensB = Inbuff[4]+ Inbuff[5]*256;
+    pc.printf("SensA:  %d  SensB:  %d \n\r", valueSensA, valueSensB);
   }    
 }