pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

Atomic CAN

Example

from m5stack import *
from m5ui import *
from uiflow import *
from base.CAN import CAN
import time
frame = None
atom_can = CAN()

def buttonA_wasPressed():
  global frame
  atom_can.send([0, 1, 2, 3, 4, 5, 6, 7], 0)
  pass
btnA.wasPressed(buttonA_wasPressed)

atom_can.can_init(0, extframe=True, mode=atom_can.NORMAL, baudrate=atom_can.BAUDRATE_250K, tx_io=22, rx_io=19, auto_restart=False)
while True:
  print((str('status:') + str(atom_can.state())))
  if atom_can.any():
    frame = atom_can.recv()
    print((str('data:') + str(frame)))
  wait_ms(30)
  wait_ms(2)

API

from base.CAN import CAN
atom_can = CAN()
atom_can.can_init(0, extframe=True, mode=atom_can.NORMAL, baudrate=atom_can.BAUDRATE_250K, tx_io=22, rx_io=19, auto_restart=False)
  • Initialize the CAN bus, configure whether it is in extended frame mode, set the operating mode (normal mode, loopback mode, etc.), and set the baud rate.
atom_can.any()
  • Check if there is unread data in the FIFO.
frame = atom_can.recv()
  • Receive data.
atom_can.send([0, 1, 2, 3, 4, 5, 6, 7], id)
  • Send a data frame with the specified ID. The ID length is 1 byte, and the data must be of type list or tuple, with a data frame length of 8 bytes.
atom_can.setfilter(0, CAN.FILTER_RAW_SINGLE, [])
  • Set a filter group.
atom_can.state()
  • Get the CAN controller status.
atom_can.clear_rx_queue()
  • Clear the receive queue.
atom_can.clear_tx_queue()
  • Clear the transmit queue.
atom_can.clearfilter()
  • Clear the filter group.
atom_can.restart()
  • Restart the CAN bus.
atom_can.deinit()
  • Stop the CAN bus.
On This Page