Alfred Lind-Anderton
/
CAN_Hello_XAVIER
Using CAN bus with (not just NUCLEO) mbed boards
Diff: main.cpp
- Revision:
- 9:3211e88e30a5
- Parent:
- 8:c65afde7f7f5
- Child:
- 10:4b0101c6763c
--- a/main.cpp Tue Feb 05 19:03:26 2019 +0000 +++ b/main.cpp Fri Feb 08 13:16:55 2019 +0000 @@ -22,8 +22,6 @@ #if defined(TARGET_STM32F103C8T6) #define LED_PIN PC_13 - #define USBTX PA_2 - #define USBRX PA_3 const int OFF = 1; const int ON = 0; #else @@ -45,6 +43,7 @@ Serial pc(USBTX, USBRX); CAN can(PB_8, PB_9); // CAN Rx pin name, CAN Tx pin name +//CAN can(p30, p29); // CAN Rx pin name, CAN Tx pin name CANMsg rxMsg; CANMsg txMsg; DigitalOut led(LED_PIN); @@ -80,6 +79,8 @@ void onCanReceived(void) { can.read(rxMsg); + pc.printf("-------------------------------------\r\n"); + pc.printf("CAN message received\r\n"); printMsg(rxMsg); if (rxMsg.id == RX_ID) { @@ -116,7 +117,7 @@ pc.printf("CAN_Hello board #2\r\n"); #endif while(1) { - if(timer.read_ms() >= 1000) { // check for timeout + if(timer.read_ms() >= 2000) { // check for timeout timer.stop(); // stop timer timer.reset(); // reset timer counter++; // increment counter @@ -130,6 +131,7 @@ if(can.write(txMsg)) { // transmit message led = OFF; // turn the LED off pc.printf("-------------------------------------\r\n"); + pc.printf("-------------------------------------\r\n"); pc.printf("CAN message sent\r\n"); printMsg(txMsg); pc.printf(" counter = %d\r\n", counter);