![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Transmitter demo for the Manchester encoding library using UART's hardware.
Dependencies: CRC16 ManchesterMsg ManchesterUART mbed
Example of a Manchester code transmitter using the ManchesterUART library.
main.cpp@2:2b031e7e30e9, 2018-10-17 (annotated)
- Committer:
- hudakz
- Date:
- Wed Oct 17 16:17:37 2018 +0000
- Revision:
- 2:2b031e7e30e9
- Parent:
- 1:1d2b38950e98
Number of start patterns in preamble can be set.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hudakz | 0:85e4298d91d6 | 1 | #include "mbed.h" |
hudakz | 0:85e4298d91d6 | 2 | #include "ManchesterUART.h" |
hudakz | 0:85e4298d91d6 | 3 | #include "CRC16.h" |
hudakz | 0:85e4298d91d6 | 4 | |
hudakz | 2:2b031e7e30e9 | 5 | static ManchesterUART man(D8, D2, 115200); // Tx pin name, Rx pin name, speed [bps] |
hudakz | 2:2b031e7e30e9 | 6 | static ManchesterMsg msg(256); // Message container (max bytes) |
hudakz | 2:2b031e7e30e9 | 7 | static CRC16 crc16; // CRC16 object |
hudakz | 2:2b031e7e30e9 | 8 | static DigitalOut led(LED1); |
hudakz | 2:2b031e7e30e9 | 9 | |
hudakz | 2:2b031e7e30e9 | 10 | /** |
hudakz | 2:2b031e7e30e9 | 11 | * @brief |
hudakz | 2:2b031e7e30e9 | 12 | * @note |
hudakz | 2:2b031e7e30e9 | 13 | * @param |
hudakz | 2:2b031e7e30e9 | 14 | * @retval |
hudakz | 2:2b031e7e30e9 | 15 | */ |
hudakz | 2:2b031e7e30e9 | 16 | int main(void) |
hudakz | 2:2b031e7e30e9 | 17 | { |
hudakz | 2:2b031e7e30e9 | 18 | man.setPreamble(20); // Set number of start patterns |
hudakz | 2:2b031e7e30e9 | 19 | while (1) |
hudakz | 2:2b031e7e30e9 | 20 | { |
hudakz | 2:2b031e7e30e9 | 21 | msg.clear(); // Clear the message |
hudakz | 2:2b031e7e30e9 | 22 | msg << 0xfa74c309; // Add some binary data to the message |
hudakz | 2:2b031e7e30e9 | 23 | msg << "Hello, World!"; // Add some string to the message |
hudakz | 2:2b031e7e30e9 | 24 | msg << crc16.calc(msg.data, msg.len); // Append CRC16 to the message |
hudakz | 2:2b031e7e30e9 | 25 | man.transmit(msg); // Transmit the message |
hudakz | 2:2b031e7e30e9 | 26 | led = !led; |
hudakz | 0:85e4298d91d6 | 27 | wait_ms(1000); |
hudakz | 0:85e4298d91d6 | 28 | } |
hudakz | 0:85e4298d91d6 | 29 | } |
hudakz | 0:85e4298d91d6 | 30 |