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.
main.cpp
00001 /* 00002 * An example showing how to use the mbed CAN API: 00003 * 00004 * Two affordable (about $2 on ebay) STM32F103C8T6 boards (20kB SRAM, 64kB Flash), 00005 * (see [https://developer.mbed.org/users/hudakz/code/STM32F103C8T6_Hello/] for more details) 00006 * are connected to the same CAN bus via transceivers (MCP2551 or TJA1040, or etc.). 00007 * CAN transceivers are not part of NUCLEO boards, therefore must be added by you. 00008 * Remember also that CAN bus (even a short one) must be terminated with 120 Ohm resitors at both ends. 00009 * 00010 * 00011 * The same code is used for both mbed boards, but: 00012 * For board #1 compile the example without any change. 00013 * For board #2 comment out line 21 before compiling 00014 * 00015 * Once the binaries have been downloaded to the boards reset both boards at the same time. 00016 * 00017 */ 00018 00019 //#define TARGET_STM32F103C8T6 1 // uncomment this line to use STM32F103C8T6 boards 00020 00021 #define BOARD1 1 // comment out this line when compiling for board #2 00022 00023 #if defined(TARGET_STM32F103C8T6) 00024 #define LED_PIN PC_13 00025 const int OFF = 1; 00026 const int ON = 0; 00027 #else 00028 #define LED_PIN LED1 00029 const int OFF = 0; 00030 const int ON = 1; 00031 #endif 00032 const unsigned int RX_ID = 0x101; 00033 const unsigned int TX_ID = 0x100; 00034 00035 #include "mbed.h" 00036 #include "CANMsg.h" 00037 #include "CANJpa.h" 00038 00039 //Serial pc(PA_2, PA_3); 00040 00041 void init_can(); 00042 void can_write(); 00043 00044 00045 /** 00046 * @brief Main 00047 * @note 00048 * @param 00049 * @retval 00050 */ 00051 int main(void) 00052 { 00053 pc.baud(9600); // set serial speed 00054 init_can(); 00055 led = ON; // turn the LED on 00056 timer.start(); // start timer 00057 while(1) { 00058 if(timer.read_ms() >= 2000) { // check for timeout 00059 timer.stop(); // stop timer 00060 timer.reset(); // reset timer 00061 can_write(); 00062 00063 } 00064 } 00065 }
Generated on Fri Aug 5 2022 20:53:30 by
1.7.2