Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 9 months ago. This question has been closed. Reason: Off Topic
Can bus, ethernet
<<code>>
lpc1768;
include "mbed.h"; const uint16_t MSG_ID_1 = 1; const uint16_t MSG_ID_2 = 2; const uint16_t MSG_ID_3 = 3;
Serial pc(USBTX, USBRX); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); CAN can(p30, p29); CANMessage msg = CANMessage();
uint8_t outputValue; 1 byte int main() { can.frequency(500000); pc.baud(9600); msg.len=8; msg.format=CANStandard; msg.type=CANData; while(1) { if(can.read(msg)) { led2.write(1);
switch(msg.id) { case MSG_ID_1:
led1 = !led1; pc.printf("%d", msg.id); pc.printf(" "); for(int i=0 ; i < msg.len; i++){ pc.printf("%d", msg.data[i]); pc.printf(" "); } break; case MSG_ID_2: led3=!led3; pc.printf("%d", msg.id); pc.printf(" "); for(int i = 0; i < msg.len; i++){ if (msg.data[0]>255) { pc.printf("%d", msg.data[0]+255); pc.printf(" ");} else { pc.printf("%d", msg.data[i]); pc.printf(" "); } } break; } pc.printf("\r\n"); wait(0.1);
} wait(0.1); }
<<code>>