connecting pyboard to CAN BUS

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
User avatar
dhylands
Posts: 2097
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: connecting pyboard to CAN BUS

Postby dhylands » Fri Sep 02, 2016 5:36 pm

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.

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Fri Sep 02, 2016 9:40 pm

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

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Sep 03, 2016 2:01 am

no... even with transceivers it doesn't work and fails in the same way

PappaPeppar
Posts: 30
Joined: Thu Dec 18, 2014 10:38 pm

Re: connecting pyboard to CAN BUS

Postby PappaPeppar » Sat Sep 03, 2016 3:19 am

How do you wire your P1 to the pyboard connectors. Have you measured whats on the pins of the transceivers?

PappaPeppar
Posts: 30
Joined: Thu Dec 18, 2014 10:38 pm

Re: connecting pyboard to CAN BUS

Postby PappaPeppar » Sat Sep 03, 2016 3:27 am

Here is a skin that I know Works.
https://github.com/HenrikSolver/pybcanskin

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Sep 03, 2016 2:35 pm

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

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Sep 03, 2016 3:03 pm

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?

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Sep 03, 2016 3:15 pm

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)

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sat Sep 03, 2016 5:44 pm

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

User avatar
kamikaze
Posts: 105
Joined: Tue Aug 16, 2016 10:10 am
Location: СССР
Contact:

Re: connecting pyboard to CAN BUS

Postby kamikaze » Sun Sep 04, 2016 2:48 am

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


Return to “The MicroPython pyboard”

Who is online

Users browsing this forum: chrismas9 and 2 guests