CAN BUS STM32 Nucleo F429ZI CAN Write Fail

Hi,
It is Veysel My board is STM32 Nucleo F429ZI and I use Mbed-os 6.6.0. I can read from my car CANBus data but I am not able to write on the bus. I tried it with two STM32 (same boards) and my trancivers are SN65HVD230
So I know that I can read on the CANBus , but I cannot write.

I have tried , CAN - Getting Started | Mbed with one STM32 and I have tried

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

I switch writing address for both stm32
This is fulling mailbox three times and stop. None read.

I have tried directly connect with one jumper from Crx to Ctx but nothing changes.

I also tried it with STM32 to Teensy ( Teensy is controing my cars LED Screen it can also read ) , but failed.

Please Help ?

Hello,

  • I tried one board (Nucleo-F767ZI MbedOS6.7) loopback from one interface to second one via two MCP2551 - OK.
  • I tried read/write between Nucleo-F767ZI and Nucleo-F429ZI (MbedOS6.6 and 6.7) - OK

And if I remember correctly, you must to set up the frequency after reset not before.

For Example click Here
#include "mbed.h"
 
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
CAN can1(PB_8, PB_9);
//CAN can1(PB_12, PB_13);
EventQueue queue(32 * EVENTS_EVENT_SIZE);
Thread t;
 
char counter = 0;
 
void send() {
    printf("send()\n");
    if(can1.write(CANMessage(767, &counter, 1))) {
    //if(can1.write(CANMessage(429, &counter, 1))) {
        counter++;
        printf("Msg sent: %d\n", counter);
        led3 = !led3;
    } 
}
 
int main() {
    printf("F767\n");
    //printf("F429\n");
    can1.frequency(1000000);
    t.start(callback(&queue, &EventQueue::dispatch_forever)); 
    queue.call_every(1s, send); 
    
    CANMessage msg;
    while(1) {
        if(can1.read(msg)) {
            printf("Msg ID: %d, data: %d\n",msg.id, msg.data[0]);
            led2 = !led2;
        } 
        thread_sleep_for(100);
        led1 = !led1;
    }
}

BR, Jan

1 Like

Hello

I tried it with your example with MbedOS 6.6 and 6.7 but nothing changed. I switched the comment lines for each STM32 and after tried to do that, I tried change PB8 and PB9 to PD0 and PD1. I don’t really understand what the problem is.

I use that with Logic Analyzer but no response at all. I tried changing transiver but seems like only transiver I have

is working for reading. But I cannot write.

Maybe I can’t see it wrong but the left Nucleo seems to be wired incorrectly - PB_8 (RD) is connected to tranciever’s CTX.

BR, Jan

You can also verifie that without transcievers - CAN bus without transceivers | Mbed

BR, Jan

Transmitters are mirrored in the photo, orange write is behind the purple one. I tried other combinations for CRX and CTX.

Hello Veysel,

As Jan says, the Rx, Tx (pink, orange) wires of the CAN node on the left-hand side seems to be swapped. Although the grounds of the CAN nodes are most likely connect to each other over the USB cable and grid, it’s better to connect them with a wire (like you did for the CANBUS_LOW, CANBUS_HIGH). It will make the bus more reliable.
Try the code + wiring (including the terminating resistors) as shown here. Import and compile the Mbed OS 2 program as it is (do not update the mbed library). Once it works use the same wiring for your Mbed OS 6 program (match the wiring pins).

Best regards, Zoltan

Zoltan, I was wrong, The left Nucleo is rotated about 180°.
I thought he was using PB_8 and PB_9 but he use PD_0 and PD_1 on both boards.

BR, Jan

Right I tried both canbus. The photo for PD0 PD1
I take a quick video for more explaining my problem.

I can read all data from my car but I cant write on it. I checked adresses and changed them by the way. It is for JohnnyK code. Still, I can read but not able to write. I am trying it almost for 1 mount.

It is better to try it without car (it looks like cool Formule) at the moment.

I see you use two notebooks, do you have connected all ground together? How Zoltan wrote.
In real car are all ECUs, as CAN-BUS nodes, connected to same ground (Car body).

BR, Jan

SOLVED

I buy a new tranciver ( VP 230 only chip ) and added 220 ohm to RS → GND and now I can write & read on CANBus.

Thank you all.