CAN bus is not working on my project. We are using a Nucleoh743 (STM32h743) programming it with mbed (Mbed OS 6.13)
I have made sure the bus is properly made, with the correct termination resistors, and the transceiver also seems to work (I have checked with an oscilloscope)
The signal I send to it reaches the correct pin of the microcontroller, but it doesn't read anything. And when I try to send any signal the Tx pins doest output anything (always high)
This is the simplified code I have been using to test it:
Sending
#include "mbed.h"
#include <CAN.h>
//CAN can2(PB_5, PB_6); //RD, TD
CAN can1(PD_0, PD_1, 500000);
int main(){
while (1){
can1.write(CANMessage(1337, "abcdefgh", 8));
ThisThread::sleep_for(500);
}
}
Receiving
#include "mbed.h"
#include <CAN.h>
//CAN can2(PB_5, PB_6, 500000); //RD, TD
CAN can1(PD_0, PD_1, 500000);
int main(){
while (1){
CANMessage msg;
if (can1.read(msg))
printf("Message received: %X\n", msg.data[0]);
else
printf("No Mesage: %X\n", msg.data[0]);
ThisThread::sleep_for(500);
}
}