PWRCAN
The PWRCAN is a CAN interface that can be used to communicate with other devices.
The following are the host’s support for PWRCAN:
Controller |
Status |
|---|---|
PowerHub |
✔ |
UiFlow2 Example
pwrcan_send_receive
Open the pwrcan_send_receive_powerhub_example.m5f2 project in UiFlow2.
This example demonstrates how to utilize PWRCAN interfaces to sender and receive data.
UiFlow2 Code Block:
Example output:
None
MicroPython Example
pwrcan_send_receive
This example demonstrates how to utilize PWRCAN interfaces to sender and receive data.
MicroPython Code Block:
1# SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8from hardware import PWRCAN 9 10 11pwrcan = None 12 13 14def setup(): 15 global pwrcan 16 17 M5.begin() 18 Power.setExtPortBusConfig(direction=1, output_enable=1, voltage=12000, current_limit=232) 19 pwrcan = PWRCAN(id=0, port=(40, 39), mode=PWRCAN.NORMAL, baudrate=25000) 20 21 22def loop(): 23 global pwrcan 24 M5.update() 25 if BtnA.wasPressed(): 26 pwrcan.send("uiflow2", 0, timeout=0, rtr=False, extframe=False) 27 if pwrcan.any(0): 28 print(pwrcan.recv(0, timeout=5000)) 29 30 31if __name__ == "__main__": 32 try: 33 setup() 34 while True: 35 loop() 36 except (Exception, KeyboardInterrupt) as e: 37 try: 38 from utility import print_error_msg 39 40 print_error_msg(e) 41 except ImportError: 42 print("please update to latest firmware")
Example output:
None
API
PWRCAN
- class PWRCAN(id, mode, tx, rx, prescaler=32, sjw=3, bs1=15, bs2=4, triple_sampling=False)
Initialise the CAN bus with the given parameters.
- Parameters:
id (int) – The CAN bus ID.
mode (int) – One of NORMAL, NO_ACKNOWLEDGE, LISTEN_ONLY.
tx (int) – The pin to use for transmitting data.
rx (int) – The pin to use for receiving data.
prescaler (int) – The value by which the CAN input clock is divided to generate the nominal bit time quanta. Value between 1 and 1024 inclusive for classic CAN.
sjw (int) – The resynchronisation jump width in units of time quanta for nominal bits; value between 1 and 4 inclusive for classic CAN.
bs1 (int) – Defines the location of the sample point in units of the time quanta for nominal bits; value between 1 and 16 inclusive for classic CAN.
bs2 (int) – Defines the location of the transmit point in units of the time quanta for nominal bits; value between 1 and 8 inclusive for classic CAN.
triple_sampling (bool) – Enables triple sampling when the TWAI controller samples a bit.
UiFlow2 Code Block:

MicroPython Code Block:
from hardware import PWRCAN can = PWRCAN(id=0, port=(40, 39), mode=PWRCAN.NORMAL, baudrate=25000)
PWRCAN class inherits CAN class. See
hardware.CANfor more details.
