Pyboard D-Series and CAN Bus
Posted: Sun May 03, 2020 6:30 pm
Hi. Getting pyboard to communicate with a CAN Bus has been challenging. I am hoping someone with experience can look at my effort and identify an omission or error, or ways to diagnose the problem.
Hardware
Pyboard D-Series
WBUS-Dip28
SN65HVD230 CAN Board
Wired as:
WBUS pins Y3 and Y4 to CAN Board also tried Y5 and Y6
Power to CAN Board is off WBUS Pin 1 (VIN) also tried Pin 2 (3.3V) though both seem to measure closer to 2.9V than 3.3
CAN Bus is grounded, shielded twisted-pair cabling, with 120 Ohm resister on each end.
The other bus node is an 8devices Korlan CAN2USB and Linux terminals running Candump and Cansend
The python code is:
import pyb
from pyb import CAN
baud = 125000
bittime = 1/baud
bs1, bs2 = 6, 8
# bittime = (1+ bs1 + bs2) * tq
tq = bittime / (1+bs1+bs2)
PCLK1 = pyb.freq()[2] # 30,000,000
# tq = prescaler/PCLK1
prescaler = PCLK1 * tq # 16
can = CAN(1, CAN.NORMAL, auto_restart=True, prescaler=int(prescaler), bs1=bs1, bs2=bs2)
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
can.send('message', 123)
An oscilloscope will see square wave signals on the bus (between CANH and CANL) when the linux terminal sends a message, and also on the RX line into the WBUS.
But testing the above code does not result in a message received in the Candump terminal, nor does it put any signal on the TX line observable to the oscilloscope.
On a related note, attempting to create CAN(2) produces an error message, that CAN(2) does not exist. Aren't there two CAN buses on the ST32 chip?
Thanks in advance for any constructive advice.
David
Hardware
Pyboard D-Series
WBUS-Dip28
SN65HVD230 CAN Board
Wired as:
WBUS pins Y3 and Y4 to CAN Board also tried Y5 and Y6
Power to CAN Board is off WBUS Pin 1 (VIN) also tried Pin 2 (3.3V) though both seem to measure closer to 2.9V than 3.3
CAN Bus is grounded, shielded twisted-pair cabling, with 120 Ohm resister on each end.
The other bus node is an 8devices Korlan CAN2USB and Linux terminals running Candump and Cansend
The python code is:
import pyb
from pyb import CAN
baud = 125000
bittime = 1/baud
bs1, bs2 = 6, 8
# bittime = (1+ bs1 + bs2) * tq
tq = bittime / (1+bs1+bs2)
PCLK1 = pyb.freq()[2] # 30,000,000
# tq = prescaler/PCLK1
prescaler = PCLK1 * tq # 16
can = CAN(1, CAN.NORMAL, auto_restart=True, prescaler=int(prescaler), bs1=bs1, bs2=bs2)
can.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
can.send('message', 123)
An oscilloscope will see square wave signals on the bus (between CANH and CANL) when the linux terminal sends a message, and also on the RX line into the WBUS.
But testing the above code does not result in a message received in the Candump terminal, nor does it put any signal on the TX line observable to the oscilloscope.
On a related note, attempting to create CAN(2) produces an error message, that CAN(2) does not exist. Aren't there two CAN buses on the ST32 chip?
Thanks in advance for any constructive advice.
David