Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
hamaint
Date:
Sat May 05 17:33:28 2018 +0000
Commit message:
serial yolo

Changed in this revision

main.cpp 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
diff -r 000000000000 -r 55f43c87934f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat May 05 17:33:28 2018 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+UARTSerial driver(D1,D0,9600);
+uint16_t crc16(uint8_t *packet, int nBytes);
+
+int main()
+{
+    uint8_t packet[5] = {0x80,25};
+    uint8_t response[48];
+    uint8_t i,to=4;
+    uint16_t crc;
+    
+    driver.write(packet,2);
+    driver.read(response,to);
+    
+    for(i=0;i<to;i++){
+        printf("%d",response[i]);}
+    
+    
+    /*crc = crc16(packet,3);
+    packet[3] = crc>>8;
+    packet[4] = crc;*/
+    
+    /*
+    printf("CRC16 : 0x%02x 0x%02x\n",packet[3],packet[4]);
+    printf("0x%02x\n",driver.write(packet,5));*/
+    
+
+}
+
+uint16_t crc16(uint8_t *packet, int nBytes) {
+    uint8_t byte,bit;
+    uint16_t crc=0;
+    for (byte = 0; byte < nBytes; byte++) {
+        crc = crc ^ (packet[byte] << 8);
+        
+        for (bit = 0; bit < 8; bit++) {
+            if (crc & 0x8000) {
+                crc = (crc << 1) ^ 0x1021;
+            } else {
+                crc = crc << 1;
+            }
+        }
+    }
+    printf("crc16 : 0x%04x \n",crc);
+return crc;
+}
diff -r 000000000000 -r 55f43c87934f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat May 05 17:33:28 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file