pub
Dependencies: CANnucleo mbed-dev
Fork of CANnucleo_Hello by
Diff: main.cpp
- Revision:
- 24:069287e799cd
- Parent:
- 23:f4682a5ddda6
- Child:
- 25:e2907bcba75e
--- a/main.cpp Thu Dec 01 22:01:11 2016 +0000 +++ b/main.cpp Tue Mar 07 19:12:22 2017 +0000 @@ -18,6 +18,7 @@ * Once the binaries have been downloaded to the boards reset board #1. * */ +#include "CANnucleo.h" #define BOARD1 1 // comment out this line when compiling for board #2 //#define TARGET_STM32F103C8T6 1 // uncomment this line when using STM32F103C8T6 boards! @@ -41,7 +42,6 @@ const unsigned int TX_ID = 0x100; #endif -#include "CANnucleo.h" #include "mbed.h" /* @@ -53,7 +53,7 @@ CANnucleo::CANMessage rxMsg; CANnucleo::CANMessage txMsg; DigitalOut led(LED_PIN); -int ledState; +int ledStatus; Timer timer; int counter = 0; volatile bool msgAvailable = false; @@ -81,6 +81,7 @@ confSysClock(); //Configure system clock (72MHz HSE clock, 48MHz USB clock) #endif pc = new Serial(PA_2, PA_3); + pc->baud(115200); can = new CANnucleo::CAN(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name can->frequency(1000000); // set bit rate to 1Mbps can->attach(&onMsgReceived); // attach 'CAN receive-complete' interrupt handler @@ -95,15 +96,15 @@ #endif while(1) { - if(timer.read_ms() >= 1000) { // check for timeout + if(timer.read_ms() >= 1000) { // check for timeout timer.stop(); // stop timer timer.reset(); // reset timer counter++; // increment counter - ledState = led.read(); // get led state + ledStatus = led.read(); // get led state txMsg.clear(); // clear Tx message storage txMsg.id = TX_ID; // set ID txMsg << counter; // append first data item - txMsg << ledState; // append second data item (total data lenght must be <= 8 bytes!) + txMsg << ledStatus; // append second data item (total data lenght must be <= 8 bytes!) led = OFF; // turn LED off if(can->write(txMsg)) // transmit message pc->printf("CAN message sent\r\n"); @@ -125,7 +126,7 @@ // Filtering performed by software: if(rxMsg.id == RX_ID) { // See comments in CANnucleo.cpp for filtering performed by hardware rxMsg >> counter; // extract first data item - rxMsg >> ledState; // extract second data item + // rxMsg >> ledStatus; // extract second data item pc->printf(" counter = %d\r\n", counter); led = ON; // turn LED on timer.start(); // transmission lag @@ -133,6 +134,3 @@ } } } - - -