Issues Writing to CANBus with STM32 Nucleo F429ZI Using Mbed OS 6.6.0

Hi guys, despite using Mbed OS 6.6.0 with an STM32 Nucleo F429ZI board, I'm experiencing difficulty writing to my car's CANBus while being able to read data from it successfully. Confirming this issue across two similar STM32 boards and utilizing SN65HVD230 transceivers on the bus for reading indicates that there is a problem in write functionality specifically rather than any broader issues affecting communication over the system as a whole. I followed the instructions from this guide: CAN - Getting Started with one STM32 board, and also tried the following code:
#include "mbed.h"

//Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
//CAN can1(PD_0, PD_1);
CAN can2(PB_8, PB_9);
DigitalOut led3(LED3);

char counter = 0;

void messageReceivedISR() {
CANMessage msg;
if(can2.read(msg)) {
printf("Message received: %d, from %d\r\n", msg.data[0], msg.id);
if(msg.id == 1100)
led2 = !led2;
if(msg.id == 1102)
led3 = !led3;
}
}

int main() {
can2.frequency(1000000);
can2.reset();
can2.attach(&messageReceivedISR, CAN::RxIrq);
while(1) {
if(can2.write(CANMessage(1130, &counter, 1))) {
printf("loop send()\r\n");
counter++;
printf("Message sent: %d\r\n", counter);
led1 = !led1;
}
// wait_ms(500);
}
}
#include "mbed.h"

//Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
//CAN can1(PD_0, PD_1);
CAN can2(PB_8, PB_9);
DigitalOut led3(LED3);

char counter = 0;

void messageReceivedISR() {
CANMessage msg;
if(can2.read(msg)) {
printf("Message received: %d, from %d\r\n", msg.data[0], msg.id);
if(msg.id == 1100)
led2 = !led2;
if(msg.id == 1102)
led3 = !led3;
}
}

int main() {
can2.frequency(1000000);
can2.reset();
can2.attach(&messageReceivedISR, CAN::RxIrq);
while(1) {
if(can2.write(CANMessage(1130, &counter, 1))) {
printf("loop send()\r\n");
counter++;
printf("Message sent: %d\r\n", counter);
led1 = !led1;
}
// wait_ms(500);
}
}
By interchanging the writing address of both STM32 boards, I filled up the mailbox thrice before it ceased processing any further reads. Additionally, to resolve this issue, I attempted connecting the Crx and Ctx pins using a jumper; however, there was no effect on my predicament. I even attempted connecting the STM32 to a Teensy board (which controls my car's LED screen and can also read CANBus), but that also failed. Could anyone please help me figure out why I can't write to the CANBus?
2 Replies
Enthernet Code
Enthernet Code3mo ago
@Sterling It looks like you're having trouble writing messages to the CANBus on your STM32 board, even though reading works fine. You've followed the correct setup steps and tried with multiple STM32 boards, but writing still fails. This problem might be due to incorrect CAN bus termination, a mismatch in baud rates, or some hardware configuration issue.
Sterling
Sterling3mo ago
Will look over this and get back to you @Enthernet Code
Want results from more Discord servers?
Add your server