Sterling
Sterling
DIIDevHeads IoT Integration Server
Created by Sterling on 9/3/2024 in #firmware-and-baremetal
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?
3 replies