flipflop test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mikevd1
Date:
Wed Jun 06 14:29:43 2018 +0000
Parent:
0:db474e15b188
Commit message:
flipflop 0x02

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r db474e15b188 -r b82afb355b62 main.cpp
--- a/main.cpp	Wed Jun 06 09:01:55 2018 +0000
+++ b/main.cpp	Wed Jun 06 14:29:43 2018 +0000
@@ -5,8 +5,8 @@
  */
 
 #include "mbed.h"
-#define slaveAdress     0xFF
-#define functioncode    0x03
+#define slaveAdress     0x07
+#define functioncode    0x02
 
 Serial pc(USBTX, USBRX);
 Serial bus(PA_9,PA_10);
@@ -35,48 +35,54 @@
         { 
             data = bus.getc();
             pc.putc(data);
-            if ( data == 0x07 && buffer == 0) 
+            if ( data == slaveAdress && buffer == 0) 
             {
-               buffer = 1;    
+               buffer = 1;      // check slava adress
             }
-            else if ( data == 0x02 && buffer == 1)
+            else if ( data == functioncode && buffer == 1)
             {
-                buffer = 2; 
+                buffer = 2;     // check functioncode
             } 
             else if ( buffer == 2 || buffer == 3 )
             {
+               // adress high and low 
                if ( buffer == 2 ) 
                {
-                   value = data ;  
-                   value = value << 8  ;
-                   buffer = 3 ;
+                   buffer = 3 ; // check starting adress hi
                }
                else
                {
-                   value = value + data ;
-                   //if ( value > 0 && value < 0xFFFF )
-                   //{
-                       buffer = 5 ; 
-                   //}    
+                    value = value + data ;
+                    buffer = 4 ; // check starting adress low
                }                      
             }
+            else if ( buffer == 4 )
+            {
+                // no of points hi 
+                buffer = 5 ;     
+            }
             else if ( buffer == 5 )
             {
-                // crc check 
-                buffer = 6 ;     
+                // no of points lo 
+                buffer = 6 ;    
             }
-            else if ( buffer == 6 )
+            else if ( buffer == 6 ) 
             {
-                // crc check 
-                buffer = 7 ;    
+                //crc check  
+                buffer = 7 ;   
             }    
+            else if ( buffer == 7 )
+            {
+                //crc check    
+                buffer = 8 ; 
+            }
             else 
             {
                 buffer = 0 ;     
             }
               
         }
-        if ( buffer == 7 )
+        if ( buffer == 8 )
         {
             if ( count < 5 )
             {
@@ -84,21 +90,24 @@
                 wait_ms(3);
                 activateSN65 = 1 ; 
                 //adress
-                bus.putc(0x07);
+                bus.putc(slaveAdress);
                 wait_us(900);
                 //send function code
-                bus.putc(0x02);
+                bus.putc(functioncode);
                 wait_us(900);
                 // Byte count
-                bus.putc(0x01);
+                bus.putc(0x02);
                 wait_us(900); 
                 //data
                 bus.putc(0x01);
                 wait_us(900);
+                //data
+                bus.putc(0x00);
+                wait_us(900);
                 // crc check 
-                bus.putc(0x60);
+                bus.putc(0x31);
                 wait_us(900);
-                bus.putc(0xC0);
+                bus.putc(0xD4);
                 buffer = 0 ; 
                 wait_ms(2) ;
                 activateSN65 = 0 ; 
@@ -110,10 +119,10 @@
                 wait_ms(3);
                 activateSN65 = 1 ; 
                 //adress
-                bus.putc(0x07);
+                bus.putc(slaveAdress);
                 wait_us(900);
                 //send function code
-                bus.putc(0x02);
+                bus.putc(functioncode);
                 wait_us(900);
                 // Byte count
                 bus.putc(0x02);
@@ -124,9 +133,9 @@
                 bus.putc(0x02);
                 wait_us(900);
                 // crc check 
-                bus.putc(0xB1);
+                bus.putc(0xB0);
                 wait_us(900);
-                bus.putc(0x19);
+                bus.putc(0xE5);
                 buffer = 0 ; 
                 wait_ms(2) ;
                 activateSN65 = 0 ;