Hi PJ. I can post some portions of the code, but not the whole file (TOO complex).
BUT, the issue isn’t the code, it’s specific to the RP2350 chip.
Understand that EVERY XIAO board Seeed makes have the SAME basic exposed functions, on the SAME pins.
A0/D0 -A5/D5
SDA
SCL
TX
RX
SCK
MISO
MOSI
You can take any of the XIAO boards and replace them with any other in your project. AND if the code is written in CircuitPython, the board. is the same pin/function for every CP configuration.
SO, when I say that I can run the EXACT same code on an XIAO ESPC3/S3/C6 or even XIAO RP2040 without issue but, when the code runs on an XIAO RP2350… I get the can timeout.
Anyway, here’s a code snippet.
#The following is in a config file called board_cfg
ConfigDict = {
---
# CAN Bus Configs
'USE_CAN':1,
'CAN_SCK':board.SCK,
'CAN_MISO':board.MISO,
'CAN_MOSI':board.MOSI,
'CAN_CS':board.A3,
'CAN_STBY':None, #board.A1,
'CAN_INT':None, #board.A0,
'CAN_RST':None, #board.A2,
---
}
# function board_cfg.getConfigField(field) returns None if not found in the dictionary. If found it returns the value associated with the key <field>
#This is the CAN Initializtion code.
#When run on a XIAO RP2350, it fails in the try except block.
#I originally didn't have that and the exception code raised was TIMEOUT in setting Mode
from digitalio import DigitlInOut, Direction, Pull
from busio import SPI
from adafruit_mcp2515 import MCP2515 as CAN
from adafruit_mcp2515.canio import Message, RemoteTransmissionRequest
spi=None
can_bus=None
can_cs=None
can_id=0
def initCAN():
global spi, can_bus, can_cs, can_id
print('initCAN()')
tcs = board_cfg.getConfigField("CAN_CS")
if tcs:
can_id = board_cfg.getConfigField("CAN_ID")
can_cs = DigitalInOut(tcs)
can_cs.switch_to_output()
spi = SPI(board_cfg.getConfigField("CAN_SCK"),
board_cfg.getConfigField("CAN_MOSI"),
board_cfg.getConfigField("CAN_MISO"))
try:
can_bus = CAN(spi, can_cs, loopback=False, silent=False)
except:
print('FAILED to setup CAN bus')
useCAN = False
can_bus=None
else:
useCAN = False
can_bus=None