2 years, 9 months ago.

Example using CAN bus on a NUCLEO-F767ZI (or any NUCLEO board)?

I've seen posts saying that mbed now supports the NUCLEO boards for sending CAN messages without using the third party CAN nucleo library. I'm having problems getting this to work however.

I have PD_0 and PD_1 connected to a CAN transceiver and properly powered using the 3.3V off the board.

I'm using the following code:

main.cpp

#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
CAN can1(PD_0,PD_1);
char counter = 0;

main()
{
	
	can1.frequency(500000);
	can1.reset();
	led2 = true;
	
	while(true){
		if(can1.write(CANMessage(1337, &counter, 1))){
			counter++;
		}
		led1 = !led1;
		wait(0.5);
	}
}

Led2 lights up. Led1 blinks. No CAN messages. I even hooked up a logic analyzer to the TX and RX pins and I see no activity at all on PD_0 and PD_1.

Am I missing something?

Someone from STM mentioned they were going to post an example back in December, but I haven't seen it. Is there working code out there for any of the NUCLEOs?

I managed to get this working by removing the can1.reset(). Its strange. Even if I put this function call at the beginning, the can interface does not work.

posted by John Sabean 01 Mar 2017

1 Answer

3 months, 3 weeks ago.

Thank you for your question and answer, because it helped me a lot. I have other question: Have you ever tested the function read with the CAN BUS? I don't know how I have to manage that. Thanks in advanced.