F767ZI CAN BUS couldn't work

leverleong
Sun, 27 Sep 2020 12:12:22 +0000
Mbed OS

#include “mbed.h”
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(PD_0, PD_1);
uint8_t kcc_hb = {0x1d,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
CANMessage msg_t;
CANMessage msg_r;
void send() {
if(can1.write(msg_t)){
printf(“Message sent ok\n”);
}else{
printf(“send error:%d\n”,can1.tderror());
led1 = !led1;
}
}
void read() {
if(can1.read(msg_r)) {
printf(“Message received: %d\n\n”, msg_r.data[0]);
}else{
printf(“no Message:%d\n”,can1.rderror());
led2 = !led2;
}
}
int main()
{
can1.frequency(250000);
memcpy(&msg_t.data, &kcc_hb, sizeof(kcc_hb));
msg_t.id = 01;
msg_t.format = CANStandard;
msg_t.len = 8;
while(1) {
read();
send();
ThisThread::sleep_for(1s);
}
}

i tried to communicate with my pc but was not successful,thank you in advance!

3 posts - 3 participants