I’ve written CircuitPython code to utilize the XIAO RP2350 board with the Adafruit CAN BFF. Problem is, it doesn’t work. I get the dreaded TIMEOUT failure when just initializing the board.
YET, if I take the SAME CP code and run it on an XIAO ESP32C3 board, it works fine.
WHAT could be the difference in the boards that one works and the other doesn’t?
Hi there,
Can you post the code?
Use the code tags above, "</> " paste it in there.
We can take a look.
How is it connected , Are you using the 5v from Xiao?
If power is only 3.3V or logic mismatch exists, TIMEOUT will occur.
maybe show a picture too.
HTH
GL PJ
import adafruit_mcp2515
mcp = adafruit_mcp2515.MCP2515(spi, cs, int_pin=digitalio.DigitalInOut(board.D9))
Make sure int_pin is connected (typically D9), otherwise communication won’t proceed even if SPI is correct.
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
After going over the pinouts of the RP2350, I realized that my “assumption” in fact made an ass of me.
Following the examples from Adafruit, they have you using A3 as the SPI CS.
BUT… Not ALL XIAO boards have an A3. They all DO have a D3 pin.
SO, while I followed the Adafruit example code, turns out RP2040 and ESPC3 boards have an A3 pin but NOT the RP2350.
So, changing the defines to use D instead of A (D3 instead of A3) in the code…
RP2350 no longer gets a timeout.
Hi there,
Normally I would agree, However Not all of the BSP reflect ALL of the pin macros the same.
Try this, use the GPIO pin numbers in your code instead of the Logical names. Use that actual GpioX number and see if you get the same failure .
HTH
GL PJ
Hey PJ…
I think I have resolved the problem.
Turns out that OFFICIALLY… the XIAO RP2350 doesn’t HAVE an A3 pin.
At least not according to the Wiki page.
It DOES have a D3 pin.
The CircuitPython “board” for the XIAO RP2350 has a pin entry for A3.
I used A3 according to the Adafruit Tutorial page for the CAN BFF (they used all Ax pin definitions).
When I used A3, I got the timeout error message.
Seeing there is no A3 defined on Seeeds wiki page, but there is a D3… I changed my code to use the Dx designations.
Guess what… THAT worked.
I posted to the Adafruit learning page and told them they need to change their example code since ALL XIAO boards do not have an A3 and since these are digital connections (interrupt, reset, standby AND cs)… WHY would they use Analog pin definitions?
Well… as Inspector Clouseau liked to remark… another mystery is solved.
Hi there,
Great Job. and thanks for contributing… Sometimes it’s those little nuances we all need to get a handle on. Way to test it out to a solution
Very good piece to add to the RP2350 tool box.
GL PJ