OpenMV H7 CAN-bus receive extended frame

Discussion related to "under the hood" OpenMV topics.
justinlsquire
Posts: 2
Joined: Sat Oct 26, 2019 1:51 pm

OpenMV H7 CAN-bus receive extended frame

Postby justinlsquire » Sat Oct 26, 2019 2:02 pm

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:

Code: Select all

# 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")
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: OpenMV H7 CAN-bus receive extended frame

Postby iabdalkader » Sat Oct 26, 2019 6:17 pm

The H7 CAN driver doesn't support extended frames, it supports the basic CAN features. You're welcome to send patches to implement that (or feature requests) to MicroPython: https://github.com/micropython/micropython
justinlsquire
Posts: 2
Joined: Sat Oct 26, 2019 1:51 pm

Re: OpenMV H7 CAN-bus receive extended frame

Postby justinlsquire » Sun Oct 27, 2019 11:08 am

Hi, thanks for the information.

No problems, I just wanted to be sure I wasn't doing something wrong.

I have recently been using FDCAN with extended message IDs on the STM32H7 for an unrelated project at work, and could potentially implement this functionality in the near future if there is a need. For now, I have been able to adjust my sensor so that it works in standard CAN frames.

-Justin
User avatar
iabdalkader
Posts: 1193
Joined: Sun May 24, 2015 3:53 pm

Re: OpenMV H7 CAN-bus receive extended frame

Postby iabdalkader » Sun Oct 27, 2019 11:15 am

justinlsquire wrote:
Sun Oct 27, 2019 11:08 am
I have recently been using FDCAN with extended message IDs on the STM32H7 for an unrelated project at work, and could potentially implement this functionality in the near future if there is a need.
If you do please let me know here and I'll merged it back in OpenMV's MicroPython fork.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 18 guests