Arm Mbed OS support forum

F767ZI CAN BUS couldn't work

#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);
}
}


image

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

Hello,

please be so kind and for correct code formatting in your post use these symbols ``` before and after your code.
Also some informations are missing.

  • what a Mbed version you use? - probably some of 6+
  • Do you have terminators connected?

EDIT:
I also see a possible issue in your diagram.

  • PD_0 (CAN_RD) >> CTX(D)
  • PD_1 (CAN_TD) >> CRX(R)

It seems you have crossed wires of your connection between the transceiver and the Nucleo board and that is wrong, it is not like an UART.

BR, Jan

Hi,

To send a message from the mbed board, the Rs pin of the SN65HVD230 must be at Lo level.