![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CAN a enviar_TLMoto
Fork of CANnucleo_Hello by
Diff: main.cpp
- Revision:
- 13:77261ea62081
- Parent:
- 12:4f5cec652e77
- Child:
- 14:ff9c77b97bad
diff -r 4f5cec652e77 -r 77261ea62081 main.cpp --- a/main.cpp Sun Jun 26 13:59:00 2016 +0000 +++ b/main.cpp Sun Jun 26 14:14:01 2016 +0000 @@ -6,12 +6,15 @@ DigitalOut led(PA_5); int ledState; -CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name +CAN can1(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name +CAN can2(PB_12, PB_13); // CAN Rx pin name, CAN Tx pin name CANMessage txMsg; +CANMessage rxMsg; int counter = 0; int main() { - can.frequency(100000); // set bit rate to 1Mbps + can1.frequency(100000); // set bit rate to 1Mbps + can2.frequency(100000); // set bit rate to 1Mbps led = 1; // turn LED on while(1) { @@ -25,10 +28,18 @@ txMsg << counter; // append first data item (32? bits?=4bytes) txMsg << ledState; // append second data item (total data lenght must be <= 8 bytes!) (=4bytes) - if(can.write(txMsg)) // transmit message - led = 1; // turn LED on - else - led = 0; // turn LED off + + can1.write(txMsg); + // if(can1.write(txMsg)) // transmit message + // led = 1; // turn LED on + // else + // led = 0; // turn LED off + + if(can2.read(rxMsg)) { + //printf("Message received: %d\n", msg.data[0]); + led = !led; + } + } } \ No newline at end of file