Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Can_sniffer_BMS4 by
Diff: main.cpp
- Revision:
- 19:872e304d7e17
- Parent:
- 18:22977a898fe9
- Child:
- 20:eb1a8042605e
--- a/main.cpp Thu Aug 11 12:07:34 2016 +0000 +++ b/main.cpp Sat Aug 13 12:45:16 2016 +0000 @@ -19,14 +19,15 @@ * */ -#define TARGET_STM32F103C8T6 1 // comment out this line when using official NUCLEO boards! +//#define TARGET_STM32F103C8T6 1 // uncomment this line when using STM32F103C8T6 boards! #define BOARD1 1 // comment out this line when compiling for board #2 #if defined(TARGET_STM32F103C8T6) - #include "stm32f103c8t6.h" + #define LED_PIN PC_13 const int OFF = 1; const int ON = 0; #else + #define LED_PIN LED1 const int OFF = 0; const int ON = 1; #endif @@ -39,8 +40,8 @@ const unsigned int TX_ID = 0x100; #endif +#include "CANnucleo.h" #include "mbed.h" -#include "CANnucleo.h" /* * To avaoid name collision with the CAN and CANMessage classes built into the mbed library @@ -50,7 +51,7 @@ CANnucleo::CAN can(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name CANnucleo::CANMessage rxMsg; CANnucleo::CANMessage txMsg; -DigitalOut led(LED1); +DigitalOut led(LED_PIN); int ledState; Timer timer; int counter = 0; @@ -74,9 +75,6 @@ * @retval */ int main() { -#if defined(TARGET_STM32F103C8T6) - confSysClock(); -#endif can.frequency(1000000); // set bit rate to 1Mbps can.attach(&onMsgReceived); // attach 'CAN receive-complete' interrupt handler @@ -108,14 +106,14 @@ if(msgAvailable) { msgAvailable = false; // reset flag for next use can.read(rxMsg); // read message into Rx message storage - printf("CAN message received:\r\n"); - printf(" ID = 0x%.3x\r\n", rxMsg.id); - printf(" Type = %d\r\n", rxMsg.type); - printf(" Format = %d\r\n", rxMsg.format); - printf(" Length = %d\r\n", rxMsg.len); - printf(" Data ="); + printf("CAN message received\r\n"); + printf(" ID = 0x%.3x\r\n", rxMsg.id); + printf(" Type = %d\r\n", rxMsg.type); + printf(" Format = %d\r\n", rxMsg.format); + printf(" Length = %d\r\n", rxMsg.len); + printf(" Data ="); for(int i = 0; i < rxMsg.len; i++) - printf(" 0x%.2x", rxMsg.data[i]); + printf(" %.2x", rxMsg.data[i]); printf("\r\n"); // Filtering performed by software: if(rxMsg.id == RX_ID) { // See comments in CAN.cpp for filtering performed by hardware