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

Dependencies:   mbed

Committer:
robt
Date:
Sun Jun 16 15:40:00 2013 +0000
Revision:
0:b9b71a68570e
by Rob Toulson and Tim Wilmshurst from textbook "Fast and Effective Embedded Systems Design: Applying the ARM mbed"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
robt 0:b9b71a68570e 1 /* Program Example 13.5: CAN data read – reads CAN messages from the CAN bus
robt 0:b9b71a68570e 2 */
robt 0:b9b71a68570e 3 #include "mbed.h"
robt 0:b9b71a68570e 4 Serial pc(USBTX, USBRX); // tx, rx for Tera Term output
robt 0:b9b71a68570e 5 DigitalOut led2(LED2); // status LED
robt 0:b9b71a68570e 6 CAN can1(p9, p10); // CAN interface
robt 0:b9b71a68570e 7 int main() {
robt 0:b9b71a68570e 8 CANMessage msg; // create empty CAN message
robt 0:b9b71a68570e 9 printf("read...\n");
robt 0:b9b71a68570e 10 while(1) {
robt 0:b9b71a68570e 11 if(can1.read(msg)) { // if message is available, read into msg
robt 0:b9b71a68570e 12 printf("Message received: %d\n", msg.data[0]); // display message data
robt 0:b9b71a68570e 13 led2 = !led2; // toggle status LED
robt 0:b9b71a68570e 14 }
robt 0:b9b71a68570e 15 }
robt 0:b9b71a68570e 16 }
robt 0:b9b71a68570e 17