by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* Program Example 13.5: CAN data read – reads CAN messages from the CAN bus                    
00002                                                                             */
00003 #include "mbed.h"
00004 Serial pc(USBTX, USBRX);          // tx, rx for Tera Term output
00005 DigitalOut led2(LED2);            // status LED
00006 CAN can1(p9, p10);                // CAN interface
00007 int main() {
00008   CANMessage msg;                 // create empty CAN message
00009   printf("read...\n");
00010   while(1) {
00011     if(can1.read(msg)) {          // if message is available, read into msg
00012       printf("Message received: %d\n", msg.data[0]);   // display message data
00013       led2 = !led2;                                    // toggle status LED
00014     } 
00015   }
00016 }
00017