Page 2 of 5

Re: connecting pyboard to CAN BUS

Posted: Fri Sep 02, 2016 5:36 pm
by dhylands
I would find such a shield useful, but I'd prefer to see a separate output for each port, and perhaps have the option of connecting them together using jumpers.

Re: connecting pyboard to CAN BUS

Posted: Fri Sep 02, 2016 9:40 pm
by kamikaze
dhylands wrote:I would find such a shield useful, but I'd prefer to see a separate output for each port, and perhaps have the option of connecting them together using jumpers.
the only reason there would be separate outputs needed - if you want to join separate CAN buses... otherwise single output is the same as two separate - in the end they will be connected to the same two wires of the CAN bus

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 2:01 am
by kamikaze
no... even with transceivers it doesn't work and fails in the same way

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 3:19 am
by PappaPeppar
How do you wire your P1 to the pyboard connectors. Have you measured whats on the pins of the transceivers?

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 3:27 am
by PappaPeppar
Here is a skin that I know Works.
https://github.com/HenrikSolver/pybcanskin

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 2:35 pm
by kamikaze
PappaPeppar wrote:How do you wire your P1 to the pyboard connectors. Have you measured whats on the pins of the transceivers?
I have updated scheme image, added PyBoard pins onto P1

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 3:03 pm
by kamikaze
PappaPeppar wrote:Here is a skin that I know Works.
https://github.com/HenrikSolver/pybcanskin
could you please provide the code which you test this skin with?

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 3:15 pm
by kamikaze
after 3 send() calls I'm getting OSError 16. So it looks like all 3 TX mailboxes are filled and nothing being sent to the bus/receiver.

Then I've connected my DSO Quad oscilloscope to CAN2 TX and GND, and captured folloring stuff:

Image
Image

the code was:

Code: Select all

def cb1(bus, reason):
    print('cb1', bus, reason)


def cb2(bus, reason):
    print('cb2', bus, reason)


def init_cans():
    can1 = CAN(1, CAN.SILENT)
    can2 = CAN(2, CAN.NORMAL)
    can1.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))

    can1.rxcallback(0, cb1)
    can1.rxcallback(1, cb1)

    can2.rxcallback(0, cb2)
    can2.rxcallback(1, cb2)

    return can1, can2
    
can1, can2 = init_cans()

can2.send('magic', 123)

Re: connecting pyboard to CAN BUS

Posted: Sat Sep 03, 2016 5:44 pm
by kamikaze
ok. my fault. Now it works. MCP2562`s Vdd should be connected to V+, while Vio to 3V3. Will fix a scheme soon ) Thank you for help

Re: connecting pyboard to CAN BUS

Posted: Sun Sep 04, 2016 2:48 am
by kamikaze
Another question. Is it fine to do bus.recv(0) in rx callback?
With following code

Code: Select all

from pyb import CAN


def cb10(bus, reason):
    print('cb1_0', bus, reason)
    print(bus.recv(0))


def cb11(bus, reason):
    print('cb1_1', bus, reason)
    print(bus.recv(1))


def cb2(bus, reason):
    print('cb2', bus, reason)


def init_cans():
    can1 = CAN(1, CAN.NORMAL)
    can2 = CAN(2, CAN.NORMAL)
    can1.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
    can1.setfilter(1, CAN.LIST16, 1, (113, 114, 115, 116))


    can1.rxcallback(0, cb10)
    can1.rxcallback(1, cb11)

    can2.rxcallback(0, cb2)
    can2.rxcallback(1, cb2)

    return can1, can2
I am getting following exception when rx callback is being executed on bus.recv():
>>> can1, can2 = init_cans()
>>> can2.send('magic', 113)
>>> cb1_1 CAN(1, CAN.NORMAL, extframe=False) 0
uncaught exception in CAN(1) rx interrupt handler
MemoryError:
and then callback stops working silently while I still can do can1.recv() and receive data manually