Can bus between two pyboards



  • Hello,

    I try to communicate two pyboards with CAN bus protocol with micropython but I don`t know where is my problem .
    This is the code to send

    import pyb
    import time
    from pyb import CAN,LED
    from pyb import Pin

    #inicializaciones
    led=LED(1)
    control=pyb.Pin(pyb.Pin.cpu.B9,pyb.Pin.OUT_PP)
    control.off()#habilita el pin del trans

    can1=CAN(1,CAN.NORMAL,extframe=False,prescaler=18,sjw=1,bs1=8,bs2=3)

    can1.setfilter(1,CAN.LIST16,0,[0x700,0x701,0x702,0x703],rtr=[0,1,0,0])

    data=b'\x01\x50'

    while True:
    print('enviando...')
    can1.send(data,id=0x702,timeout=0,rtr=False)
    time.sleep(2)
    print('enviado')
    time.sleep(2)
    control.on()
    and this is the code to receive

    #inicializaciones
    led=LED(1)
    control=pyb.Pin(pyb.Pin.cpu.B9,pyb.Pin.OUT_PP)
    control.off()#habilita el pin del trans

    can1=CAN(1,CAN.NORMAL,extframe=False,prescaler=18,sjw=1,bs1=8,bs2=3)

    can1.setfilter(1,CAN.LIST16,0,[0x700,0x701,0x702,0x703],rtr=[0,1,0,0])

    while True:
    print('Entrando al ciclo')
    if can.any(0):
    a=can1.recv(0)
    print(a)

    The problem is that the second pyboard never receive nothing , I use a transiver MCP2562 . any suggestion?

    thanks
    iosman


    Shark ION Review



  • @iosman123

    I haven't tried CANBUS on the Pycom. The filters look a bit concerning, is it possible to try it without filters to start with. They are generally used on a very busy bus were the micro is unable to cope with the rate of messages arriving.

    It is also worth checking some physical things. Do you have the 120ohm terminating resistors on your bus? Pin 8 to ground to take the MCP2562 out of standby mode? Also the MCP2562 needs 5V supply (but can operate at 3.3v logic level). I have used SN65HVD230DR with esp32 successfully, it has 3v3 supply and logic level.

    It might also be worth getting a simple scope to look at what is happening on your bus, even a really cheap one will be okay, as you just need to see the pattern and levels are roughly okay.


Log in to reply
 

Pycom on Twitter