Example program for CanNucleoF0 library. Can download same program onto multiple Nucleo-F091RC devices. Devices will maintain number of messages sent and send that number to the other device(s).
Dependencies: mbed-src-CanNucleoF0
main.cpp@1:cc465eab3e69, 2015-12-17 (annotated)
- Committer:
- ptpaterson
- Date:
- Thu Dec 17 03:20:19 2015 +0000
- Revision:
- 1:cc465eab3e69
- Parent:
- 0:c76257ab6331
example created
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptpaterson | 0:c76257ab6331 | 1 | |
ptpaterson | 0:c76257ab6331 | 2 | /** @file |
ptpaterson | 0:c76257ab6331 | 3 | * @brief main program entry |
ptpaterson | 0:c76257ab6331 | 4 | */ |
ptpaterson | 0:c76257ab6331 | 5 | |
ptpaterson | 0:c76257ab6331 | 6 | #include "mbed.h" |
ptpaterson | 0:c76257ab6331 | 7 | |
ptpaterson | 0:c76257ab6331 | 8 | DigitalOut boardLed (LED1); |
ptpaterson | 0:c76257ab6331 | 9 | Ticker inputScanner; |
ptpaterson | 0:c76257ab6331 | 10 | int volatile input; |
ptpaterson | 0:c76257ab6331 | 11 | |
ptpaterson | 0:c76257ab6331 | 12 | void InputScan () |
ptpaterson | 0:c76257ab6331 | 13 | { |
ptpaterson | 0:c76257ab6331 | 14 | boardLed = !boardLed; |
ptpaterson | 0:c76257ab6331 | 15 | } |
ptpaterson | 0:c76257ab6331 | 16 | |
ptpaterson | 0:c76257ab6331 | 17 | int main() |
ptpaterson | 0:c76257ab6331 | 18 | { |
ptpaterson | 1:cc465eab3e69 | 19 | printf ("\r\n----- MAIN -----\r\n"); |
ptpaterson | 0:c76257ab6331 | 20 | |
ptpaterson | 0:c76257ab6331 | 21 | /* blinker task*/ |
ptpaterson | 0:c76257ab6331 | 22 | boardLed = 0; |
ptpaterson | 0:c76257ab6331 | 23 | input = 0; |
ptpaterson | 0:c76257ab6331 | 24 | inputScanner.attach_us (&InputScan, 50000); |
ptpaterson | 0:c76257ab6331 | 25 | |
ptpaterson | 0:c76257ab6331 | 26 | /*========================================================================= |
ptpaterson | 0:c76257ab6331 | 27 | * test echo |
ptpaterson | 0:c76257ab6331 | 28 | *========================================================================= |
ptpaterson | 0:c76257ab6331 | 29 | */ |
ptpaterson | 0:c76257ab6331 | 30 | CAN can (PA_11, PA_12); |
ptpaterson | 0:c76257ab6331 | 31 | |
ptpaterson | 0:c76257ab6331 | 32 | char counter = 255; |
ptpaterson | 0:c76257ab6331 | 33 | if (! (can.write (CANMessage (1337, &counter, 1)))) { |
ptpaterson | 0:c76257ab6331 | 34 | printf ("can.write FAILURE!\r\n"); |
ptpaterson | 0:c76257ab6331 | 35 | } |
ptpaterson | 0:c76257ab6331 | 36 | counter = 0; |
ptpaterson | 0:c76257ab6331 | 37 | |
ptpaterson | 0:c76257ab6331 | 38 | CANMessage msgRx; |
ptpaterson | 0:c76257ab6331 | 39 | |
ptpaterson | 1:cc465eab3e69 | 40 | printf ("----- READY -----\r\n"); |
ptpaterson | 0:c76257ab6331 | 41 | while (1) { |
ptpaterson | 0:c76257ab6331 | 42 | if (can.read (msgRx)) { |
ptpaterson | 0:c76257ab6331 | 43 | |
ptpaterson | 0:c76257ab6331 | 44 | printf("Message received: %d ", msgRx.data[0]); |
ptpaterson | 0:c76257ab6331 | 45 | wait (0.4); printf("."); |
ptpaterson | 0:c76257ab6331 | 46 | wait (0.4); printf("."); |
ptpaterson | 0:c76257ab6331 | 47 | wait (0.4); printf(". \r\n"); |
ptpaterson | 0:c76257ab6331 | 48 | |
ptpaterson | 0:c76257ab6331 | 49 | counter++; |
ptpaterson | 0:c76257ab6331 | 50 | if (! (can.write (CANMessage (1337, &counter, 1)))) { |
ptpaterson | 0:c76257ab6331 | 51 | printf ("can.write FAILURE!\r\n"); |
ptpaterson | 0:c76257ab6331 | 52 | } |
ptpaterson | 0:c76257ab6331 | 53 | } |
ptpaterson | 0:c76257ab6331 | 54 | |
ptpaterson | 0:c76257ab6331 | 55 | wait (0.05); |
ptpaterson | 0:c76257ab6331 | 56 | } |
ptpaterson | 0:c76257ab6331 | 57 | } |