i want use a CAN bus between my micropython and my PC, i can send a message but i can't receive my message whereas the message is acknowledge
i use the CAN 1 (Y3 and Y4) and the driver MCP2562
my program is:
Code: Select all
# main.py -- put your code here!
import pyb
from pyb import CAN
import os
file=open('motion.txt','w')
pyb.LED(1).toggle()
pyb.delay(500)
pyb.LED(1).toggle()
#prescaler=40=>50kBaud
can = CAN(1, CAN.NORMAL, extframe=False, prescaler=40, sjw=1, bs1=14, bs2=6)
can.setfilter(0,CAN.LIST16,1,(123,124,125,126))
def namelabel():
data=b'1'
try:
can.send(data,12)
pyb.LED(1).toggle()
except:
pyb.LED(2).toggle()
tim =pyb.Timer(4) # crée un objet minuterie à l'aide de la minuterie 4
tim.init(freq = 2) # déclenche à 2Hz donc 500ms
tim.callback(lambda t:namelabel())
while True:
try:
(msg_id, rtr, filter_index, data) = can.recv(0)
pyb.LED(4).on()
except:
pyb.LED(3).on()
file.write('{}\n'.format(data))
but the orange LED (LED 3) is on whereas my PC send my message with adress 123 without error so the function 'recv' don't operate
moreover when i run without the 'try' function the micropython is put in error (green LED and red LED flash quickly then the program stop)
it's the same with the restart function
i don't know where i my error, can you tall me if you want more information? can you tall me your supposition/answer?
thank you in advance