單片機和can收發器之間tx、rx不需要交叉接線!!!
tja1050的rx接Y3、tx接Y4
from pyb import CANcan = CAN(1)
can.init(mode=can.NORMAL, prescaler=6, sjw=1, bs1=4, bs2=2, auto_restart=True) # 1Mbps的配置,本文使用的micropython1.12.0中沒有baudrate參數,版本可使用os.uname()查看
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126)) # set a filter to receive messages with id=123, 124, 125 and 126
can.send('message!', 123) # send a message with id 123
print(can.recv(0)) # 需要配置過濾器才能接收到