Hello,
I am trying to receive something on OpenMV H7 via CAN-bus. I am using the example for CAN on the IDE, and if configured as transmitter, I can successfully transmit messages and see them on the bus using a CAN-Analyzer tool. However, when I send messages from the tool, or any other device, I can’t seem to make it receive anything if they are extended messages. If I initialize CAN with extframe=False, and I transmit standard ID messages, I can receive them. But if I use extframe=True, and I transmit extended ID messages, I can’t receive anything. Does anyone know if there is something else missing to make it work with receiving extended ID CAN messages?
This is the code I’m using currently:
# CAN Shield Example
#
# This example demonstrates CAN communications between two cameras.
# NOTE: you need two CAN transceiver shields and DB9 cable to run this example.
import time, omv
from pyb import CAN
from pyb import LED
RED_LED_PIN = 1
# NOTE: Set to False on receiving node.
TRANSMITTER = False
#TRANSMITTER = True
can = CAN(2)#, CAN.NORMAL)
# Set a different baudrate (default is 250Kbps)
# NOTE: The following parameters are for the H7 only.
#
# can.init(CAN.NORMAL, prescaler=32, sjw=1, bs1=8, bs2=3) # 125Kbps
#can.init(CAN.NORMAL,extframe=True, prescaler=16, sjw=1, bs1=8, bs2=3,auto_restart=True) # 250Kbps
can.init(CAN.NORMAL,extframe=True, prescaler=16, sjw=1, bs1=8, bs2=3,auto_restart=True) # 250Kbps
# can.init(CAN.NORMAL, prescaler=8, sjw=1, bs1=8, bs2=3) # 500Kbps
# can.init(CAN.NORMAL, prescaler=4, sjw=1, bs1=8, bs2=3) # 1000Kbps
#can.restart()
LED(RED_LED_PIN).off()
if (TRANSMITTER):
while (True):
# Send message with id 1
can.send('Hello', 2)
time.sleep(1000)
else:
# Runs on the receiving node.
if (omv.board_type() == 'H7'): # FDCAN
# Set a filter to receive messages with id=1 -> 4
# Filter index, mode (RANGE, DUAL or MASK), FIFO (0 or 1), params
can.setfilter(0,CAN.MASK,0,(0,0))
#can.setfilter(1,CAN.MASK,1,(0,0))
LED(RED_LED_PIN).on()
#can.setfilter(0, CAN.RANGE, 0, (1, 4))
else:
# Set a filter to receive messages with id=1, 2, 3 and 4
# Filter index, mode (LIST16, etc..), FIFO (0 or 1), params
can.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))
while (True):
# Receive messages on FIFO 0
if (can.any(0)):
print(can.recv(0,timeout=20))
#else:
# print(can.info())
# time.sleep(100)
# print(can.recv(0, timeout=100))
# except:
# print("no receive\n")