![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Manchester receiver demo.
Dependencies: Manchester mbed CRC16 ManchesterMsg
main.cpp@0:91017f5f5cb3, 2017-05-17 (annotated)
- Committer:
- hudakz
- Date:
- Wed May 17 07:59:46 2017 +0000
- Revision:
- 0:91017f5f5cb3
- Child:
- 1:2ce05484e526
Initial issue.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:91017f5f5cb3 | 1 | #include "mbed.h" |
hudakz | 0:91017f5f5cb3 | 2 | #include "Manchester.h" |
hudakz | 0:91017f5f5cb3 | 3 | |
hudakz | 0:91017f5f5cb3 | 4 | DigitalOut led(LED1); |
hudakz | 0:91017f5f5cb3 | 5 | Manchester man(p11, p12, 9600); // Tx pin, Rx pin, speed [bps] |
hudakz | 0:91017f5f5cb3 | 6 | ManchesterMsg msg(255); // Message container (max bytes) |
hudakz | 0:91017f5f5cb3 | 7 | char str[255]; // Array of char |
hudakz | 0:91017f5f5cb3 | 8 | uint32_t val; |
hudakz | 0:91017f5f5cb3 | 9 | |
hudakz | 0:91017f5f5cb3 | 10 | int main(void) { |
hudakz | 0:91017f5f5cb3 | 11 | |
hudakz | 0:91017f5f5cb3 | 12 | while(1) { |
hudakz | 0:91017f5f5cb3 | 13 | if(man.receive(msg)) { // Receive message |
hudakz | 0:91017f5f5cb3 | 14 | // Print data length and raw data |
hudakz | 0:91017f5f5cb3 | 15 | printf("\r\n----------------------\r\n"); |
hudakz | 0:91017f5f5cb3 | 16 | printf("len = %d\r\n", msg.len); |
hudakz | 0:91017f5f5cb3 | 17 | printf("raw data :\r\n"); |
hudakz | 0:91017f5f5cb3 | 18 | for(int i = 0; i < msg.len; i++) |
hudakz | 0:91017f5f5cb3 | 19 | printf("\t0x%.2x\r\n", msg.data[i]); |
hudakz | 0:91017f5f5cb3 | 20 | |
hudakz | 0:91017f5f5cb3 | 21 | // Extract data from message and print |
hudakz | 0:91017f5f5cb3 | 22 | msg >> str >> val; |
hudakz | 0:91017f5f5cb3 | 23 | printf("data :\r\n"); |
hudakz | 0:91017f5f5cb3 | 24 | printf("\tstr = %s\r\n", str); |
hudakz | 0:91017f5f5cb3 | 25 | printf("\tval = 0x%x\r\n", val); |
hudakz | 0:91017f5f5cb3 | 26 | } |
hudakz | 0:91017f5f5cb3 | 27 | else |
hudakz | 0:91017f5f5cb3 | 28 | printf("Error\r\n"); |
hudakz | 0:91017f5f5cb3 | 29 | |
hudakz | 0:91017f5f5cb3 | 30 | led = !led; |
hudakz | 0:91017f5f5cb3 | 31 | } |
hudakz | 0:91017f5f5cb3 | 32 | } |