I haven’t had a chance to play with the openMV H7 CAN Bus yet (I am waiting for a CAN adaptor to arrive) and have had a quick look around the forum. I found this from Oct 2019 saying that the H7 CAN driver doesn’t support extended frames:
I have something working but not sure if I like it (looking for your opinion ).
The reason I don’t like it is you are still receiving standard or external frames (based on how you initialise the bus). I couldn’t receive either type without a filter (maybe that is expected).
In fdcan.c:72
// init->ExtFiltersNbr = 0; // Not used
init->ExtFiltersNbr = 32; // 64 / 2
# 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 Timer
global can
def cansend(timer):
can.send('Hello', 1) # Send message with id 1
print('sent hello')
#can = CAN(2, CAN.NORMAL, extframe = False, baudrate=250_000, sampling_point=75, auto_restart=True)
can = CAN(2, CAN.NORMAL, extframe = True, baudrate=250_000, sampling_point=75, auto_restart=True)
can.restart()
can.setfilter(0, CAN.MASK, 0, (0, 0))
timer = Timer(2) # Timer 2 (don't use 1, 5, 6)
timer.init(freq=1) # trigger at 1Hz
timer.callback(cansend)
while (True):
try:
# Receive messages on FIFO 0
msg = can.recv(0, timeout=10000)
print("{}".format(msg))
except:
print("exception occured")
pass
Let me know your thoughts. If you mostly like it I can put up a PR in the OpenMV micropython fork and we can go from there.
Hi, if you are going to send a PR (thanks for the effort BTW) please implement the filter logic and etc. You’ll understand better all that’s going on in these MCUs. It’s an interesting journey.