Pretty new to micropython but trying to do my best to learn things as I work on small projects.
I am working on a small project where I want to read CAN bus data or write CAN bus data. I have a device that already talks over CAN. I have included the specification of the CAN bus in the code.
I am using a SN65HVD230 to connect between external device and the uPython board and tried to run the below code to see if I get any response. But so far no luck.
CAN_TX on SN65HVD230 is connected to Y3 and CAN_RX is connected to Y4 terminals on the uPython board. I have enabled the terminating resistor on the SN65HVD230 using the jumper.
Does anyone have any inputs on this?
I am little confused about the time quanta, not sure if I have selected the prescale correctly or not.
Code: Select all
#External Device Settings
#Propagation Segment: 7, Phase Segment 1= 4, Phase Segment 2= 4, RJW: 1
#time quantum = 250 ns
#bit rate = 250kbps, 29 bit identifier, 8 bytes of data.
import pyb
from pyb import CAN
can = CAN(1, CAN.NORMAL)
#extframe=True for 29bit identifier, PCL1=42000000 (42MHz, 23.8095nsec),250kbps #prescale = 250/23.809
can.init(CAN.NORMAL,True,10,sjw=1,bs1=4,bs2=4)
can.setfilter(0, CAN.LIST16, 0, (65366)) # set a filter to receive messages with id=65366= 0XFF56
#can.send('message!', 123) # send a message with id 123
can.recv(0,timeout=5000) # receive message on FIFO 0