Pyboard, micropython, CAN hardware
I have a pyboard v1.1 with micropython running and I want to use CAN to communicate between modules at 250K and 500K.
I am using CAN 1(Y3 = RX = B8, Y4 = TX) = B9). The CAN transciever is terminated with a 120 resistor between CANH, CANL
The code at micropython just does not work. I get an OSError 16 after 3 transmissions!
**
Note that CAN Loopback works.**
can.info()
[128, 0, 1, 1, 0, 3, 0, 0]
This is the version of Micropython on the pyboard.
YD-MPY v1.12 on 2020-07-16; vcc-gnd(R) pyboard(R) with STM32F405RG
Type “help()” for more information.
*I am looking for some assistance in getting the pyboard to work in transmiting and receiving successfuly over CAN.
I will require code and anything else to make it work.
*
Here is sample code that throws exceptions.
import pyb
can = CAN(1, CAN.NORMAL)
can.init(CAN.NORMAL, prescaler=16, sjw=1, bs1=8, bs2=3) # Example settings
def send_message():
try:
can.send(‘Hello’, 123) # Message with ID 123
except OSError as e:
if e.args[0] == 16: # EBUSY
print(“CAN bus is busy, retrying…”)
pyb.delay(10) # Delay before retrying
send_message()
else:
print(“Unexpected error:”, e)
for _ in range(5):
send_message()
pyb.delay(100) # Delay between transmissions
The pyboard just does not work. I have tried several boards and transcievers and it does not work.
I get OS Error 16 after 3 transmissions.
Terry D’Silva is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.