can-doc
can-doc copied to clipboard
Issue with bus.send_periodic
Hi, I'm trying to send CAN messages with the function send_periodic. however i got the error
can.exceptions.CanOperationError: Couldn't send CAN BCM frame due to OS Error: Invalid argument You are probably referring to a non-existing frame. [Error Code 22]
The code i used is :
import can
import time
try:
bus = can.interface.Bus(channel = 'can0',
bustype = 'socketcan',
bitrate = 500000)
except OSError as e:
print(e)
message = can.Message(arbitration_id=0x37A, data=[0x0A, 0x00, 0x3B, 0x00, 0xFF, 0x0B, 0x00, 0x00], is_extended_id= False)
message1 = can.Message(arbitration_id=0x379, data=[0x0C, 0x00, 0x0A, 0x00, 0xFF, 0x00, 0x0A, 0x00], is_extended_id= False)
message2 = can.Message(arbitration_id=0x372, data=[0x00, 0xD0, 0x50, 0x80, 0xCC, 0x00, 0xAA, 0xB0], is_extended_id= False)
period = 0.1
while True:
bus.send_periodic(msgs = message, period = 0.1)
bus.send_periodic(msgs = message1, period = 0.1)
bus.send_periodic(msgs = message2, period = 0.1)
When i tried to send it via bus.send it seems to be able to work
import can
import time
bus = can.interface.Bus(channel='can0', bustype='socketcan')
message = can.Message(arbitration_id=0x37A, data=[0x0A, 0x00, 0x3B, 0x00, 0xFF, 0x0B, 0x00, 0x00], is_extended_id= False)
message1 = can.Message(arbitration_id=0x379, data=[0x0C, 0x00, 0x0A, 0x00, 0xFF, 0x00, 0x0A, 0x00], is_extended_id= False)
message2 = can.Message(arbitration_id=0x372, data=[0x00, 0xD0, 0x50, 0x80, 0xCC, 0x00, 0xAA, 0xB0], is_extended_id= False)
period = 0.1
while True:
bus.send(message)
time.sleep(period)
bus.send(message1)
time.sleep(period)
bus.send(message2)
time.sleep(period)
Here are some of the configurations that my CAN device is working on RPI-4B 8GB Ram, kernel version : 6.1.19-v8+ CAN transceiver device, MCP2515 (modified, changed VP230 for TJA1050)
ip -d -s link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0 minmtu 0 maxmtu 0
can state ERROR-ACTIVE restart-ms 100
lsmod | grep spi
spidev 20480 2
spi_bcm2835 20480 0
ifconfig can0
can0: flags=193<UP,RUNNING,NOARP> mtu 16
unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 txqueuelen 10 (UNSPEC)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
/boot/config.txt
dtparam=spi=on
dtoverlay=mcp2515, spi0-0, interrupt=25,oscillator=8000000
dtoverlay=spi-dma
dtoverlay=spi-bcm2835
Upon boot up, RPI did say that it is unable to load spi-dma & bcm2835
failed to load dtoverlay=spi-dma failed to load dtoverlay=spi-bcm2835
I'm pretty new to RPI and CAN devices as well as posting issues on github, so any advice would definitely help! Thanks