lazaro camargo
/
L476teste
teste
main.cpp@0:9ecfabfc4077, 2018-05-10 (annotated)
- Committer:
- lazarocamargo
- Date:
- Thu May 10 03:43:07 2018 +0000
- Revision:
- 0:9ecfabfc4077
teste
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lazarocamargo | 0:9ecfabfc4077 | 1 | #include "mbed.h" |
lazarocamargo | 0:9ecfabfc4077 | 2 | #include "CAN.h" |
lazarocamargo | 0:9ecfabfc4077 | 3 | |
lazarocamargo | 0:9ecfabfc4077 | 4 | /* |
lazarocamargo | 0:9ecfabfc4077 | 5 | Transmitter code |
lazarocamargo | 0:9ecfabfc4077 | 6 | CANBus Tutorial based on lots of example code |
lazarocamargo | 0:9ecfabfc4077 | 7 | */ |
lazarocamargo | 0:9ecfabfc4077 | 8 | |
lazarocamargo | 0:9ecfabfc4077 | 9 | |
lazarocamargo | 0:9ecfabfc4077 | 10 | Serial pc(PA_9, PA_10); // tx, rx for Tera Term output |
lazarocamargo | 0:9ecfabfc4077 | 11 | |
lazarocamargo | 0:9ecfabfc4077 | 12 | DigitalOut led1(PA_6); // LED1 displays messsage sent Status |
lazarocamargo | 0:9ecfabfc4077 | 13 | CAN can1(PA_11,PA_12); // rx, tx , CAN interface |
lazarocamargo | 0:9ecfabfc4077 | 14 | char counter = 0; // Counter Variable to store number of sent messages |
lazarocamargo | 0:9ecfabfc4077 | 15 | |
lazarocamargo | 0:9ecfabfc4077 | 16 | int main() { |
lazarocamargo | 0:9ecfabfc4077 | 17 | printf("sending a message via CANbus... "); |
lazarocamargo | 0:9ecfabfc4077 | 18 | while (1) { |
lazarocamargo | 0:9ecfabfc4077 | 19 | // send value to CAN bus and monitor return value to check if CAN |
lazarocamargo | 0:9ecfabfc4077 | 20 | // message was sent successfully. If so display, increment and toggle |
lazarocamargo | 0:9ecfabfc4077 | 21 | if (can1.write(CANMessage(1, &counter, 1))) { |
lazarocamargo | 0:9ecfabfc4077 | 22 | pc.printf("CANBus Message sent: %d\n", counter); // display message |
lazarocamargo | 0:9ecfabfc4077 | 23 | counter++; // increment message counter value |
lazarocamargo | 0:9ecfabfc4077 | 24 | led1 = !led1; // toggle LED1 to show message sent |
lazarocamargo | 0:9ecfabfc4077 | 25 | }else{ |
lazarocamargo | 0:9ecfabfc4077 | 26 | can1.reset(); // Reset CANbus if there is a problem |
lazarocamargo | 0:9ecfabfc4077 | 27 | } |
lazarocamargo | 0:9ecfabfc4077 | 28 | wait(1); // wait a second |
lazarocamargo | 0:9ecfabfc4077 | 29 | } |
lazarocamargo | 0:9ecfabfc4077 | 30 | } |