5 years, 8 months ago.

Nucleo F411RE - compiler error 20 "Identifier "CAN" is undefined in "main.cpp", Line: 6, Col: 2"

Hello! I loaded CAN example, but it does not compiling correctly. Can you tell, whats wrong?

CAN example code

#include "mbed.h"

Ticker ticker;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(p9, p10);    <here coppiler stoped
CAN can2(p30, p29);

char counter = 0;

void send() {
    if(can1.write(CANMessage(1337, &counter, 1))) {
        printf("Message sent: %d\n", counter);
        counter++;
    }
    led1 = !led1;
}

int main() {
    ticker.attach(&send, 1);
   CANMessage msg;
    while(1) {
        if(can2.read(msg)) {
            printf("Message received: %d\n\n", msg.data[0]);
            led2 = !led2;
        }
        wait(0.2);
    }
}

Error: Identifier "CAN" is undefined in "main.cpp", Line: 6, Col: 2

1 Answer

5 years, 8 months ago.

Hello JB,

Unfortunately the NUCLEO-F411RE is not equipped with CAN peripheral. To experiment with CAN bus consider to use low cost STM32F103C8T6 boards. Remember that at least two nodes have to be connected to the CAN bus to make it operational and that CAN transceivers are needed to connect the mbed CAN controller to the CAN bus.