0
\$\begingroup\$

I have set up a CAN bus between 2 STM32 Nucleo's, where one is only sending messages and the other one is only reading them. This works, I have also validated this by connecting them to another CAN Bus to receive messages.

Now I also want to read CAN messages on a Raspberry Pi. I have bought the Waveshare RS485 CAN HAT for Raspberry Pi (https://www.waveshare.com/rs485-can-hat.htm) and followed their instructions to get started.

I have connected the CAN H and L to my STM32 Nucleo CAN Bus to read the messages, however I cannot get this to work. I tried their demo code to send and receive messages (https://www.waveshare.com/wiki/File:RS485_CAN_HAT_Code.7z) and I have installed can-utils to use candump can0. Both methods don't seem to work, because I am not receiving any message from the Pi and the receiving Nucleo is also not receiving any message from the Pi.

When I run ifconfig can0 to check the CAN connection the Pi gives me the following:

can0:    flags=193<UP,RUNNING,NOARP>    mtu 16    unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
   txqueuelen 10    (UNSPEC)
    RX packets: 0    bytes 0 (0.0 B)
    RX errors 0    dropped 0    overruns 0    frame 0
    TX packets: 0    bytes 0 (0.0 B)
    TX errors: 1    dropped 1    overruns 0    carrier 1    collisions 0

I am not really familiar how to read this, but I guess no messages have been sent or received and there is a transmission error (don't know why that is, maybe because it cannot connect to a CAN Bus?).

Can anyone help me to setup the CAN Bus on Raspberry Pi with the RS485 CAN HAT correctly? Thanks in advance!

P.S. I would like to add the tag rs485-can-hat to this question for users with the same problem, but of course this is not a 'popular' tag and I don't have enough reputation to create a new tag. Can anyone do this for me?

\$\endgroup\$
1
  • \$\begingroup\$ Maybe CANH and CANL are interchanged? \$\endgroup\$
    – Milind R
    Aug 8 at 19:30

1 Answer 1

1
\$\begingroup\$

to check the state of the can interface in linux, run "ip -details link show can0"

check the can state, it should be ERROR-ACTIVE for a healthy bus.

Also ensure that you did bring up the interface with the correct baudrate and so on:

$ sudo ip link set can0 type can bitrate 125000

$ sudo ip link set up can0

\$\endgroup\$
2
  • \$\begingroup\$ Thank you for your answer. I did set the correct bitrate (500000 in my case). When I run ip -details link show can0 it says can state ERROR-PASSIVE. According to you this would not be an healthy bus? How do I create an healthy bus? \$\endgroup\$
    – suitendaal
    Nov 12, 2020 at 11:44
  • \$\begingroup\$ A node starts out in Error Active mode. When any one of the two Error Counters raises above 127, the node will enter a state known as Error Passive and when the Transmit Error Counter raises above 255, the node will enter the Bus Off state. An Error Active node will transmit Active Error Flags when it detects errors. An Error Passive node will transmit Passive Error Flags when it detects errors. A node which is Bus Off will not transmit anything on the bus at all. Could be caused by identical IDs or an incorrectly terminated bus. \$\endgroup\$
    – teb
    Nov 12, 2020 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.