Sending dummy message on CAN bus.

Dependencies:   TextLCD USBDevice mbed

Fork of CAN_Send_ra by Arpan Das

main.cpp

Committer:
tusharbhanarkar
Date:
2017-06-11
Revision:
1:8b013b70c879
Parent:
0:4097729a7390

File content as of revision 1:8b013b70c879:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p15,p16,p17,p18,p19,p20); // rs, e, d4,d5,d6,d7
 
Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(p30,p29);
CAN can2(p9, p10);
char counter = 0;
 
void send() {
    printf("send()\n");
    if(can2.write(CANMessage(1337, &counter, 1))) {
        //lcd.locate(0,0);
        //lcd.printf("wloop()\n");
        counter++;
        lcd.locate(0,0);
        lcd.printf("Message sent: %d\n", counter);
    } 
    led1 = !led1;
}
 
int main() {
    printf("main()\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1) {
        printf("loop()\n");
        if(can1.read(msg)) {
            lcd.locate(0,1);
            lcd.printf("Message received: %d\n", msg.data[0]);
            led2 = !led2;
        } 
        wait(0.2);
    }
    //wait(0.2);
}