CAN BUS STM32F767 Nucleo-144 not working

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Nielssc
Posts: 1
Joined: Fri Mar 13, 2020 11:24 am

CAN BUS STM32F767 Nucleo-144 not working

Post by Nielssc » Mon Mar 16, 2020 5:40 pm

Dear All,
I working on project and I am trying to get two STM32F767 Nucleo-144 to communicate through CAN bus. Nevertheless I cannot get them to communicate, I made the following circuit using MCP2551 :
https://drive.google.com/open?id=1GnbpI ... K_Wzlt8DIk
I flashed micropython using Dfuse from STMicroelectronics. The following code is on the transmitting microcontroller:

Code: Select all

# main.py
import pyb 
from pyb import CAN
led = pyb.LED(3)
while True:
    led.toggle()
    pyb.delay(500)
    can = CAN(1, CAN.NORMAL, extframe=True, prescaler=8, sjw=4, bs1=13, bs2=13)
    can.send('1', 123)
    pyb.delay(500)
The following code is on the receiving microcontroller:

Code: Select all

# main.py -- put your code here!
import pyb
from pyb import CAN
led = pyb.LED(3)
aled = pyb.LED(2)
while True:
    try:
        can = CAN(1, CAN.LOOPBACK, extframe=True, prescaler=8, sjw=4, bs1=13, bs2=13)
        (idr, isRTR, filterMatchIndex, telegram) = can.recv(0) 
        if idr == 123 :
            aled.toggle()
        else:
            print("NOT working")       
    except:
        led.toggle()
I was connecting to the wrong pins on the Nucleo-144 in the beginning but this seems to be fixed, I was also using the Analog read pins of an Arduino UNO to check the voltages on the CAN bus and the RX TX of both controllers. I Also tried to make the Nucleo-144 communicate with the Arduino UNO using the MCP2515 as shown on the picture below:
https://drive.google.com/open?id=1_gD6p ... KEOfU6ZlxP
Communication between two Arduinos is fine because they use the same libraries but even after playing around with the bit timing I did not manage to get the Arduino to read the right message and the right ID from the Nucleo board because I did not manage to find information on the bit timing from the mcp_can.h libraries.
https://drive.google.com/open?id=1WZuel ... 6DaoSxw1Q4
https://drive.google.com/open?id=1Ay_OM ... UVx0p-zO_Y
Something that I noticed is when I connect both Nucleo boards on the CAN bus in ''NORMAL'' mode with the command can = CAN(1, CAN.NORMAL, extframe=True, prescaler=8, sjw=4, bs1=13, bs2=13), then the CAN bus is silent having CANH and CANL remaining at 2.5V.

I would really appreciate some advice to continue on this project.

Stay healthy,

Niels

User avatar
TravisT
Posts: 61
Joined: Sun Feb 23, 2014 2:31 pm
Location: Portland, OR
Contact:

Re: CAN BUS STM32F767 Nucleo-144 not working

Post by TravisT » Sun Mar 22, 2020 9:46 pm

Hello

Two most common problems I have seen with CAN
- Default pin assignments in firmware incorrect
- CAN is not configured for the clock settings on your board.

Check to make sure the CAN is assigned correctly based on the board config
https://github.com/micropython/micropyt ... figboard.h

Sometimes you also need to check to make sure the pins are defined in the pins.csv for them to work correctly.
https://github.com/micropython/micropyt ... I/pins.csv

The CAN bus uses one of the peripheral clocks which will be different on the Nucleo board compared to the pyboards. Once you confirm the clock rate you can use this calculator to figure out your CAN configuration using ST bxCAN from the dropdown.

Hope this helps
_______________
Travis Travelstead

Post Reply