pdf-icon

UIFlow Guide

UIFlow 1.0 Blockly

Event

Unit

UIFlow 1.0 Project

CAN Unit

Exanoke

from m5stack import *
from m5ui import *
from uiflow import *
import time
import unit

setScreenColor(0x5c0000)
can_0 = unit.get(unit.CAN, unit.PORTC)

def buttonB_wasPressed():
  # global params
  can_0.send([10, 20, 30], 0X710)
  pass
btnB.wasPressed(buttonB_wasPressed)

can_0.can_init(0, extframe=True, mode=can_0.NORMAL, baudrate=can_0.BAUDRATE_250K, tx_io=17, rx_io=16, auto_restart=False)
label3.setText(str(can_0.state()))
while True:
  if can_0.any():
    print((str('message:') + str(can_0.recv())))
    print((str('ID:') + str(can_0.remote_id())))
  wait_ms(25)
  wait_ms(2)

API

can_0.deinit()
  • Close the CAN bus
can_0.can_init(0, extframe=True, mode=can_0.NORMAL, baudrate=can_0.BAUDRATE_250K, tx_io=17, rx_io=16, auto_restart=False)
  • Construct a CAN object on a given bus
    • mode: NORMAL, NO_ACKNOWLEDGE, LISTEN_ONLY
    • tx: pin used for transmitting data
    • rx: pin used for receiving data
    • baudrate: baud rate
    • extframe: extended frame enabled
print(can_0.any())
  • Check if there is a message waiting on the FIFO Queue
can_0.clear_filter()
  • Clear data
can_0.clear_rx_queue()
  • Reset all pending messages in the Receive Queue (RX Queue)
can_0.clear_tx_queue()
  • Reset all pending messages in the Transmit Queue (TX Queue)
print(can_0.remote_id())
  • Get the Remote ID
print(can_0.recv())
  • Retrieve received data
can_0.restart()
  • Force a software reset of the CAN controller
can_0.send('uiflow2', 0)
  • Send data
can_0.set_filter(0, can_0.FILTER_RAW_SINGLE, 'uiflow2')
  • Send data
    • bank:number
    • mode:filter raw single/filter raw dual/filter address
    • Message:string
print(can_0.state())
  • Return the status of the controller
On This Page