CAN bus not working on Nucleo H743

Hello, I have been trying to use CAN bus with Mbed on a Nucleo H743 using Mbed OS 6.13 (I have tried with other versions too). And it is not working at all. That is: when sending a signal, the TX pin doesn’t output anything, and when receiving I can see the input signal with the oscilloscope going to the chip, but it is not reading anything.

I know setting up the CAN bus can be problematic, but I don’t think that is the problem. The transceiver seems to work fine, and the bus has the termination resistors. Also, I have been able to communicate Arduinos with this setup.

I have tried with Arduino, and a USB2CAN converter to test sending communication to the Nucleo board.

The as-simple-as-possible code I have been using for testing is the following:

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

Hello,

I tried CAN loop communication between both CAN Controllers of on my Nucleo and it is working.

CAN can1(PB_5, PB_6, 500000);
CAN can2(PD_0, PD_1, 500000);

Eq.: Nucleo-H743ZI2, homemade shield with 2x MCP2551, MbedOS 6.13 and 6.15.1 and KeilStudio

BR, Jan

1 Like

Does it also work if you send Extended CAN messages?
I have also tried looping the CANs via my h743 and it works only for standard Id’s, receives nothing for extended messages (J1939).

Although, I have also tried the same code compiled in mbed os 5, and it seemed to work for both standard and extended.

Hello,

nope, but CAN Extended Frame 29-Bit · Issue #15252 · ARMmbed/mbed-os (github.com)

BR, Jan

1 Like

Hello ,

found the solution in that thread needed to change the following in can_api.c found in targets

obj->CanHandle.Init.StdFiltersNbr = 128; // to be aligned with the handle parameter in can_filter
obj->CanHandle.Init.ExtFiltersNbr = 64; // to be aligned with the handle parameter in can_filter

thought I’d leave this here for any future readers that may come across it.

thank you JohnnyK, much appreciated, you saved my project.

Ok, I had little bit more time for this.
@stevebuhagiar can you tell me what Mbed-OS version you are using?
From my point of view you use MbedOs lower than 6.14 because this issue was already solved in MbedOS 6.14 (link below).
Also the person from the issue #15252 used older than is the latest one.

Fix Extended Message Filter count in STM CAN API by SamuA-AP · Pull Request #15000 · ARMmbed/mbed-os (github.com)

BR, Jan

It seems that i was using Mbed version 6.13, I was completley unaware that Mbed studio does not update the version of your projects even though the mbed compiler is updated to the latest Mbed-OS 6.16.

is there a way to this automatically or does it have to be done manualy ? The only way I know how, is to change the MBED_MINOR_VERSION in mbed_version.h and then start a clean build, Although I’m not sure if this is the way I need to do it.

Is there another way to completely rebuild the project using a different Mbed-OS?

Let me explain…

Automatically it is not possible I think, because when you choose File->New program..., the program is composed from sources what are already on your HardDrive. That makes sense because it is Offline tool. Also when you look to Help->Check for tools updates... you will found items like Example projects and Mbed Library Cache. These both were probably not updated for a while (Not by you, but by Mbed Studio team).
tools

That is not the same, these are two different things and it is a coincidence they have same version number.

  • ARM Compiler 6.16, which is really compiler tool
  • MbedOS 6.16

Definitely not, that does not have any effect. You just change value of the macro with this, but that will change nothing in MbedOS code. Macros like this are good for things like below, but shouldn’t be changed. This is only information about the current version of MbedOS and are changed with new release of MbedOS.

printf("Running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);

About how to do that - Managing libraries - Managing libraries | Mbed Studio Documentation

BR, Jan

1 Like