2
\$\begingroup\$

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);
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ The problem with your code is that unless someone is an expert and knows how MBED works, we can't be sure if MBED initializes everything for you, or if the MCU clocks to appropriate buses and peripherals are properly set to correct frequencies and enabled, or do you have to do that init yourself. Try toggling the CAN TX pin as GPIO to see if even GPIO works or not. \$\endgroup\$
    – Justme
    Commented Feb 11, 2022 at 8:55
  • \$\begingroup\$ Well, I assume Mbed handles all lower level things to make their library work. I haven't toggled the TX pin as a digital output, but I have as a PWM output, which works fine \$\endgroup\$ Commented Feb 12, 2022 at 0:48

0

Browse other questions tagged or ask your own question.