1 year, 9 months ago.

CAN not working on nucleof446RE

hello

i would like to use CAN BUS for a project, in order to do this, first i tried to use example code provided in mbed library but...nothing... both of RX and TX CAN pin are pulled up to +5V, that is all... anyone have an idea ? or i forgot something ? i use nucleo F446RE

here is the code i used

Thanks

include the mbed library with this snippet

#include "mbed.h"

 Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(PA_11, PA_12);
CAN can2(PB_5, PB_6);
char counter = 0;
 
void send() {
    printf("send()\n");
    if (can1.write(CANMessage(1337, &counter, 1))) {
        printf("wloop()\n");
        counter++;
        printf("Message sent: %d\n", counter);
        wait(0.2);
    } 
    led1 = !led1;
}
int main() {
    printf("main()\n");
    ticker.attach(&send, 1);
    CANMessage msg;
    while(1) {
        printf("loop()\n");
        if (can2.read(msg)) {
            printf("Message received: %d\n", msg.data[0]);
            led2 = !led2;
        } 
    }
}
Comment on this question

1 Answer

1 year, 9 months ago.

Hello Olivier,

  • The code is OK. It's running fine on my NUCLEO-F446RE.
    However, I'd suggest to remove printf("loop()\n"); in order not to overload the serial terminal on your PC.
  • Make sure you are using CAN tranceivers (like MCP2551 or TJA1040, or etc.) for the communication over the CAN bus (see the links below how).

Some links that could be of help:

https://os.mbed.com/users/WiredHome/notebook/can---getting-started/
https://os.mbed.com/handbook/CAN
https://os.mbed.com/users/hudakz/code/CAN_Hello/
( https://os.mbed.com/users/hudakz/code/CANnucleo_Hello/ )

Hi,

Tanks for this answer it's working now.

posted by olivier flayols 25 Feb 2018