Jetson nano MCP2515 Received data is wrong

I can transfer data between Jetson nano and raspberry pi using 2 mcp2515, however, the data from jetson nano to raspberry pi is transferred completely correctly, while the data from raspberry pi to jetson nano is not read correctly by jetson nano, although it is sent correctly. As far as I can see, a one-bit error occurs, the incoming data is multiplied by 2 or divided by 2, or the sign is read in a changed way.

I think the problem is caused by the MCP driver or the clock rate in the MCP and SPI communication.

I tried to communicate between different cards, STM32 ↔ Jetson Nano = same problem, STM32 ↔ raspberry pi = no problem, Raspberry pi ↔ Jetson nano = problem, Raspberry pi ↔ Raspberry pi = no problem.

I would be very grateful if you can help me with this, I have browsed the dtbo files related to MCP and looked at the spi clock rates, but I have no idea which one I need to change how much etc. I have no idea

It might be off by one bit. This could occur if one end thinks there is one stop bit, and the other end thinks there are either no stop bits, or two stop bits. Flow control is similar when different at two ends, but it is a complete halt of data in one direction. The default for a Jetson UART is normally 115200 8N1 and no flow control.

import can
import struct
import threading
import time
bus = can.interface.Bus("can0","socketcan")
stop = threading.Event()
def receive():
    while not stop.is_set():
        received = bus.recv() 
        print(f"Received data : {received}, {struct.unpack('f',received.data)}")
def send(data):
    msg = can.Message(
        arbitration_id= 0x103,
        is_extended_id=False,
        data=struct.pack("f",data)
    )
    print(f"Data sent : {msg}")
    bus.send(msg)

if __name__ == "__main__":
    try:
        thread_ = threading.Thread(target = receive)
        thread_.start()
        while 1:
            send(3.14)
            time.sleep(0.1)
            send(8.17)
            time.sleep(0.1)
    except KeyboardInterrupt:
        stop.set()
        
        bus.shutdown()

I test in loopback mode and the first data sent is always read correctly, but the other incoming data is read incorrectly.

output:

candump can0 :

image

What could be the reason for this and how can I solve it? help please

Based on the solution here, I set the spi max frequency values to 2 Mhz and the problem was solved. I thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.