Page 1 of 5

connecting pyboard to CAN BUS

Posted: Fri Aug 26, 2016 6:38 pm
by kamikaze
Hi. I want to play with my Audi A6 (C5, 2004) CAN BUS. So I'm planning to connect pyboard to car`s CAN bus wires... what would you recommend me to use? Something like https://www.sparkfun.com/products/13262 or is it just fine to connect pyboard directly ?

Re: connecting pyboard to CAN BUS

Posted: Fri Aug 26, 2016 6:48 pm
by dhylands
You'll need something half way in between.

The sparkfun board has bot a CAN controller (MCP2515) and a CAN transceiver (MCP2551).

The pyboard has a builtin CAN controller. If you want to use that, then you just need a CAN transceiver.

If you want, you can connect to the Sparkfun board using the SPI bus, but then you'll need to write your own driver (pyb.CAN only talks to the builtin CAN controller).

Re: connecting pyboard to CAN BUS

Posted: Sat Aug 27, 2016 2:33 pm
by kamikaze
is it a better idea to find a 3.3V CAN tranceiver like from TI? http://www.ti.com/lsds/ti/interface/can ... oducts-wwe# the only problem here is that it is SOIC, not DIP

Re: connecting pyboard to CAN BUS

Posted: Sat Aug 27, 2016 11:15 pm
by dhylands
The MCP2551 is available in DIP and SOIC formats, although it looks like its a 5V device, and 3.3v doesn't look like it will be interpreted as a logic high, so you'd need a voltage converter.

Using an SOIC with an SOIC to DIP adapter like this: https://www.sparkfun.com/products/13655 might be the best way if you want to use an SOIC device.

Re: connecting pyboard to CAN BUS

Posted: Sun Aug 28, 2016 1:41 am
by chrismas9
I use the Microchip MCP series DIP CAN transceivers regularly with STM32. They are a 5V device but fully compatible with 5V tolerant 3.3V MCU's. No level translator is required.

The transmitter input requires <0.8V and >2V for logic 0 and 1 respectively which the STM32 can do.
The receiver output gives <0.8 and >3.5V out for logic 0 and 1 respectively and the 5V tolerant STM32 inputs will read these correctly.

Note that other brands of DIP CAN transceiver, eg TI SN65 series won't work with STM32. They need 3.5V logic 1 on the transmitter input.

Re: connecting pyboard to CAN BUS

Posted: Sun Aug 28, 2016 5:46 am
by folke
Hi,

I used a MCP2562 transceiver that has separate pins for logic supply and bus supply, so it fits any controller using 1.8–5.5V.
It's available in PDIP and SOIC.

Greetings
Folke

Re: connecting pyboard to CAN BUS

Posted: Thu Sep 01, 2016 12:41 am
by kamikaze
I have connected CAN1 and CAN2 (Rx1->Tx2, Tx1->Rx2) with wires directly and trying to send/receive a message. With no luck.

Code: Select all

from pyb import CAN

can1 = CAN(1, CAN.NORMAL)
can2 = CAN(2, CAN.NORMAL)

can1.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))
can2.setfilter(0, CAN.LIST16, 0, (123, 124, 125, 126))

can1.send('magic', 123)
can2.recv(0)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 110] ETIMEDOUT
any ideas?

Re: connecting pyboard to CAN BUS

Posted: Thu Sep 01, 2016 10:49 pm
by kamikaze
sometimes I'm getting OSError 16 which is device or resource busy. But can1/can2.any(0) is always False. What is wrong? when playing with CAN.LOOPBACK - everything works. Why CAN1 <-> CAN2 doesn't?

Re: connecting pyboard to CAN BUS

Posted: Fri Sep 02, 2016 2:08 am
by dhylands
I suspect that it has something to do with the fact that the recv is synchronous. So you can't send while receiving.

In order to send and receive with the existing code, you'd probably need to use 2 pyboards.

That's just a guess on my part, and not backed by anything more than a hunch.

Re: connecting pyboard to CAN BUS

Posted: Fri Sep 02, 2016 1:50 pm
by kamikaze
what do you think about following scheme?

Image

I'm going to create a CAN bus shield PCB that will be able to join my car`s CAN bus. And to make both PyBoard CAN buses to interconnect even if nothing is connected to P2. Looks like it is no go to connect CAN1 with CAN2 directly.

Also... do I need to add termination resistors into the scheme for both tranceivers?