openMV H7 CAN shield extended frames

Hi Everyone,

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:

Is this still the case?


Yes, it’s on the todo list.

I might take a look at it, is there an information you can point me at about the issue? Apart from the forum post and Receive Extended CANBus Frame on H7/H7+ · Issue #1071 · openmv/openmv · GitHub

You have to implement it in the fdcan.c file in the mov/src/MicroPython/ports/stm32 dir.

I have something working but not sure if I like it (looking for your opinion :smiley: ).

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

In pyb_can.c:684

    //filter.IdType = FDCAN_STANDARD_ID;
    filter.IdType = self->extframe ? FDCAN_EXTENDED_ID : FDCAN_STANDARD_ID;


# 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.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

while (True):
        # Receive messages on FIFO 0
        msg = can.recv(0, timeout=10000)
        print("exception occured")

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. :slight_smile:

I did confirm that the CAN.MASK mode works for the extended frames, eg:
can.setfilter(0, CAN.MASK, 0, (0x0000EE01, 0x0000FFFF))

The micropython documentation seems a little confusing, MASK is the only mode that should work for extended right?