can.py

# Questo lavoro è concesso in licenza MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Tutti i diritti riservati.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Esempio CAN
#
# Questo esempio dimostra le comunicazioni CAN tra due fotocamere.
# NOTA: sono necessari due shield transceiver CAN e un cavo DB9 per eseguire questo esempio.

import time
import omv
from pyb import CAN

# NOTA: impostare su False sul nodo ricevente.
TRANSMITTER = True

can = CAN(1, CAN.NORMAL, baudrate=125_000, sample_point=75)
# NOTA: decommentare per impostare manualmente il bit timing, ad esempio:
# can.init(CAN.NORMAL, prescaler=32, sjw=1, bs1=8, bs2=3)
can.restart()

if TRANSMITTER:
    while True:
        # Invia il messaggio con id 1
        can.send("Hello", 1)
        time.sleep_ms(1000)

else:
    # Viene eseguito sul nodo ricevente.
    if omv.board_type() == "H7":  # FDCAN
        # Imposta un filtro per ricevere messaggi con id=1 -> 4
        # Indice del filtro, modalità (RANGE, DUAL o MASK), FIFO (0 o 1), parametri
        can.setfilter(0, CAN.RANGE, 0, (1, 4))
    else:
        # Imposta un filtro per ricevere messaggi con id=1, 2, 3 e 4
        # Indice del filtro, modalità (LIST16, ecc..), FIFO (0 o 1), parametri
        can.setfilter(0, CAN.LIST16, 0, (1, 2, 3, 4))

    while True:
        # Ricevi messaggi sulla FIFO 0
        print(can.recv(0, timeout=10000))

results matching ""

    No results matching ""