logo

openmv H7 plus 使用CAN模块通信,一直不通报错ETIMEOUT???

2022-08-08 14:57
K
ipz6

import time

from pyb import CAN,LED

led = LED(3)

#can = CAN(2, CAN.LOOPBACK)

#can = CAN(2, CAN.SILENT_LOOPBACK)

can = CAN(2, CAN.NORMAL,prescaler=8, sjw=1, bs1=8, bs2=3) # 500Kbps

#can.setfilter(0, CAN.RANGE|CAN.DUAL, 0, (0x701, 0x708))

can.setfilter(0, CAN.RANGE, 0, (0x701, 0x708))

#can.restart()

time.sleep_ms(2000)

led.on()

time.sleep_ms(100)

led.off()

time.sleep_ms(100)

cnt = 0

while True:

time.sleep_ms(100)

try:

cnt+=1

can.send(b'\x00\x00\x00\x00', 0x701,timeout=500) #发送 ID 为 123 的消息

#print(can.info())

#print(cnt,can.recv(0,timeout=200)) # 在FIFO 0上接收消息

except Exception as e:

print("error",e)

led.on()

time.sleep_ms(100)

led.off()

time.sleep_ms(100)

2022-08-08 21:24
I
网红小智智 星瞳科技

https://github.com/openmv/openmv-boards/blob/master/shields/can/can.pdf

看一下原理图。