CAN transmit test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Ticker ticker;
00004 DigitalOut led1(LED1);
00005 CAN can1(p30, p29);
00006 Serial pc(USBTX, USBRX); // tx, rx
00007 
00008 char counter = 0;
00009 
00010 void send() {
00011     static char counter = 0;
00012     if (can1.write(CANMessage(0x200, &counter, 1))) {
00013         printf("CanTx--> id: 0x200  dlc: 1  data: %x\n\r", counter);
00014         led1 = !led1;
00015         counter++;
00016     }
00017 }
00018 
00019 int main() {
00020     pc.printf("\nCAN Test\n");
00021     //250kbit/s
00022     can1.frequency(250000);
00023     // every 500ms
00024     ticker.attach(&send, 0.5);
00025     while (1);
00026 }