![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Manchester receiver demo.
Dependencies: Manchester mbed CRC16 ManchesterMsg
Diff: main.cpp
- Revision:
- 5:3dc7d8e25c89
- Parent:
- 4:649d9a4219c0
- Child:
- 6:d1191c39b418
--- a/main.cpp Sun May 21 19:28:00 2017 +0000 +++ b/main.cpp Mon May 22 09:59:41 2017 +0000 @@ -3,18 +3,15 @@ #include "CRC16.h" DigitalOut led(LED1); +Manchester man(p11, p12, 9600); // Tx pin, Rx pin, speed [bps] +ManchesterMsg msg(100); // Message container (max bytes) +char str[80]; // Storage for the received array of char +uint32_t val; // Storage for the value received +CRC16 crc16; // CRC16 object +unsigned short recvCRC16; // CRC16 received in the message +unsigned short calcCRC16; // CRC16 calculated int main(void) { - Manchester man(p11, p12, 9600); // Tx pin, Rx pin, speed [bps] - ManchesterMsg msg(100); // Message container (max bytes) - char str[80]; // Storage for the received array of char - uint32_t val; // Storage for the value received - CRC16 crc16; // CRC16 object - unsigned short recvCRC16; // CRC16 received in the message - unsigned short calcCRC16; // CRC16 calculated - - //pc.baud(9600); - while(1) { if(man.receive(msg)) { // Receive message @@ -29,18 +26,17 @@ } printf("\r\n\r\n"); - // Calculate CRC16 (exclude CRC bytes (last two bytes) from calculation) - calcCRC16 = crc16.calc(msg.data, msg.len - 2); + // Calculate CRC16. Exclude CRC bytes (last two bytes) from calculation. + calcCRC16 = crc16.calc(msg.data, msg.len - 2); + printf("Calculated CRC16 = %d\r\n", calcCRC16); // Extract data and CRC16 from the message msg >> str >> val >> recvCRC16; - printf("Calculated CRC16 = %d\r\n", calcCRC16); printf("Received CRC16 = %d\r\n", recvCRC16); - printf("\r\n"); - + printf("\r\n"); - if( calcCRC16 = recvCRC16) { + if( calcCRC16 == recvCRC16) { printf("Received data :\r\n"); printf(" str = %s\r\n", str); printf(" val = 0x%x\r\n", val);