samirFSR
Posts: 1
Joined: Sun Feb 12, 2017 8:48 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Sun Feb 12, 2017 8:52 pm

Hi,
can we add more nodes as we want?

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon Feb 13, 2017 9:22 pm

samirFSR wrote:Hi,
Hi.
samirFSR wrote: can we add more nodes as we want?
Excuse me, what nodes?!
CAN-BUS is multi-node bus so there can be connected more than 2 nodes, just remember about terminating resistors (circa 120R ?) at end nodes - the devices that are the most apart from each other.

Leseratte10
Posts: 1
Joined: Mon Apr 10, 2017 5:22 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon Apr 10, 2017 5:26 pm

I bought the exact same module mentioned in the first post. However I don't quite understand how I can make the power supply work. The one trace on the back of the board is used to provide the second, smaller chip with +5V, right?

That would mean I'd just need to cut that trace and provide power to the second chip myself and it would work. However, in the pictures in the first post it looks like the 5V power has just been soldered on top of the trace, in addition to the 3.3V already there?

Or can we cut the trace, then scrape off some of the protective blue stuff on the board to expose the metal, and *then* solder 5V to the trace? If yes, on which side? I guess it's the left side when I look at the bottom of the board with the CAN connector left, is that correct?

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Thu Apr 20, 2017 8:19 pm

HI,

Sorry for late answer -_-

The trace is cut, in this image you see there is a part of trace removed: http://postimg.org/image/wqile3twv/

Verify with schematic how it should be done - photos are just for reference.

wiebel
Posts: 1
Joined: Fri Apr 28, 2017 7:35 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Fri Apr 28, 2017 8:44 am

Thank you very much. I would have spent ages debugging the 5V transmitter issue. Especially as I am using a perfectly fine 3V3 transmitter with the teensy for the rest of my nodes and simply assumed a compatible type on that module. That brings me to an other comment on your article. You're saying the transmitter needs 5V as CAN must be driven at 5V, which is not exactly true. While the actual transmitter on this popular MCP2514 module must be driven at 5V there are others. So it may be a valid option to simply swap the transmitter by a pin compatible type (which most are), eg. http://www.ti.com/product/SN65HVD232.
You can read about the interoperability between 5V and 3V3 transmitters here: https://e2e.ti.com/support/interface/in ... 2/t/230101

leocat3
Posts: 7
Joined: Sat Jan 14, 2017 11:02 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Wed May 03, 2017 3:27 pm

Hi All!
I continue to develop the idea of working with a can bus through an adapter USB-UART-CAN.
On Raspberry PI you can use UART-CAN adapter directly, witout USB-UART.
An introduction to what's done: http://open-plc.blogspot.ru/2016/12/ope ... logic.html
You can use up to 100 devices on the CAN bus.

darkestday
Posts: 2
Joined: Tue May 09, 2017 3:09 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Wed May 10, 2017 3:05 pm

> because CAN bus operates on 0V and 5V levels, lower high level is considered as noise/distortion (this is defined by CAN Bus specification).

No. you only need a difference between can high and low of 2.5v. There is absolutly no problem in mixing 3.3 and 5v in a bus.

The specification is by th way ISO 11898 . 3.3v Trancievers are ISO 11898 -2 compliant.

darkestday
Posts: 2
Joined: Tue May 09, 2017 3:09 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Fri May 12, 2017 9:39 am

On second thought - where do you have the schematics from? the MCP2515 runs from 2.7 to 5.5v...therefore it can be directly used with an 3.3 arm m0 (for example)

mIwav
Posts: 2
Joined: Mon May 15, 2017 7:13 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon May 15, 2017 7:47 am

Hi all,

has anyone of you experienced the following issue with a setup using the NiRen MCP2515_CAN with 8 MHz crystal in combination with a Raspberry Pi Zero W:
After modifying the circuit as described, I can set the usual CAN bus clock frequencies 125kHz, 250kHz and 500kHz and I can verify the operation using candump. Everything is fine

However when I try to set the bus frequency to 1MHz using the following command

Code: Select all

sudo ip link set can0 up type can bitrate 1000000 
I get the following response

Code: Select all

RTNETLINK answers: Numerical argument out of domain
and dmesg shows

Code: Select all

[   77.213639] mcp251x spi0.0 can0: bitrate error 33.3% too high
Has anyone seen this already? Could this be a bug, an issue with the circuit or a SPI issue?

leocat3
Posts: 7
Joined: Sat Jan 14, 2017 11:02 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon May 15, 2017 11:47 am

# uname -a
Linux buildroot 2.6.35.3-1129-g691c08a #529 PREEMPT Wed Mar 1 02:30:27 NOVT 2017 armv7l GNU/Linux

# /sbin/ip -d link sho dev can1
3: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN qlen 10
link/can
can <TRIPLE-SAMPLING> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
bitrate 1000000 sample-point 0.750
tq 83 prop-seg 4 phase-seg1 4 phase-seg2 3 sjw 1
flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
clock 24000000

leocat3
Posts: 7
Joined: Sat Jan 14, 2017 11:02 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon May 15, 2017 12:05 pm

If on mcp2515 set quartz 8 MHz, then:
The desired CAN bus speed is not possible with the specified CAN clock frequency and tolerance.
May be 16 or 24 MHz.
On 8 MHz max = 500 KBit/Sec

mIwav
Posts: 2
Joined: Mon May 15, 2017 7:13 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon May 15, 2017 2:46 pm

Thank you very much leocat3!

I did not read the mcp2515 specs consciously enough, I'm sorry...

It is stated there that the theoretical minimum CAN bit time consists of 5 CAN time quanta (TQ). 1 TQ for Sync, 1 TQ for Propagation Segment, 2 TQ for Phase Segment 1 and 1 TQ for Phase Segment 2.

With an oscillator frequency of 8 MHz, the resulting TQ time is TQ = 2 * BRP / Fosc, with the Baud Rate Prescaler BRP.
Therefore the minimum time quantum at 8 MHz is 2 / 8 MHz = 250 ns. As five time quanta are needed the theoretical minimum bit time is 1250 ns resulting in a CAN bus bit frequency of 800 kHz.

Therefore I will try to replace the crystal by a higher value (i.e. 16 MHz and above). Thank you again!

mamuti
Posts: 6
Joined: Fri May 19, 2017 10:21 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon May 22, 2017 1:43 am

Hi

I hope you are still tracking this post; I had a stupid question: suppose I want to setup CAN interface with a baudrate like 125k, using the following command:

Code: Select all

sudo ip link set can0 up type can bitrate 125000
Do I need to connect the mcp2515 and all the rest of network? or it is a software step?

Thanks

toannt
Posts: 1
Joined: Tue Jul 11, 2017 6:08 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Tue Jul 11, 2017 6:58 am

Thank you very much for sharing, all your steps work properly in my case.
If anyone trying the system like: PI3 -- MCP2515---MCP2515---Arduino Uno, the following information would help.
1. Saper_2 was totally right on modifying the power supplying wires. because TJA1050 requires minimum 4.78V.
Instead of cutting the wire on board, you can just do like this: https://www.youtube.com/watch?v=_v3GumyXbhw
it is better to my welding skill. And just for sharing, I just picked up the VDD pin of MCP2515 and welded it to a line that I can supply 3.3V. Yeah follow fully the video will give you a very beautiful board thought, :D.

2. On Raspbian 4.1.18 and 4.9.35, every steps works fine. The difference thing in my case:
-On 4.1.18: when the INT was wrongly wired: "can0" appeared in "ifconfig can0" and even the first "cansend" successfully sent and received. Then later "cansend" was never received by other CAN module. My bad-luck that I'm just a software developer and there was typo on my new-bought Pi3 GPIO cable that label wrongly the GPIO 12 pin...
-On 4.9.35: when the INT was wrongly wired: "can0" could not be seen.

3. On Arduino: there are 2 points to be considered.
-INT pin must be wired to Arduino, usually to D2 but it may depends on the CAN lib.
(I stared with a guide that not use INT pin like this http://henrysbench.capnfatz.com/henrys- ... -tutorial/. if my feeling was correct, the INT pin at least used to check if data is available to be read. Anyway, this is a good post and I did not test the Arduino-Arduino case).
-Oscillator 8MHz is also the problem, because Arduino CAN libs usually configured to work with default 16MHz module. you can use this lib https://github.com/Flori1989/MCP2515_lib with a modification to It's example code: CAN0.begin(CAN_125KBPS, MCP_8MHz);

4. moreover, for QT user.
from QT5.8, there is CAN module and a CAN example.
following this link, https://wiki.qt.io/RaspberryPi2EGLFS, I've built QT5.9 successfully and run the CAN module successfully to test my hardware.

vnrgoli
Posts: 15
Joined: Sat Apr 01, 2017 7:57 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Sun Jul 23, 2017 1:04 am

Hi,
I am using Raspi3 <----> Pican <---->ECUsim 2000 OBD simulator.

Not receiving any packets/response from ECUSim (tested good.) No errors from cansend or candump (please see below.)
Any suggestions?

Code: Select all

[email protected]:~/python/pican2duo $ ifconfig
can1      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          UP RUNNING NOARP  MTU:16  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4825 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10 
          RX bytes:0 (0.0 B)  TX bytes:38600 (37.6 KiB)
I see no errors when I send a request in cansend:

Code: Select all

cansend can1 7DF#02010C0000000000
candump displays the message without any returned value

Code: Select all

[email protected]:~ $ candump can1
  can1  7DF   [8]  02 01 0C 00 00 00 00 00
The simulator is working fine (tested with Bluetooth ELM127 dongle)
CAN-H (OBDII pin 6), CAN-L(OBDII pin 14) and Chassis Ground (OBDII pin 4) from ECUSim's OBDII port are connected to Pican to their corresponding connectors.
CANbus on Pican are terminated with 120Ohm resistors.

ahmedawad
Posts: 42
Joined: Mon Apr 18, 2016 11:44 am
Location: Bremen, DE

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon Jul 24, 2017 8:23 am

@vnrgoli, check the baud rate on the PiCAN adapter side is the same as the one configured in /etc/network/interfaces on the RPI.
I can well asure that following this post till the end and I had every thing working fine.

vnrgoli
Posts: 15
Joined: Sat Apr 01, 2017 7:57 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon Jul 24, 2017 11:17 pm

ahmedawad wrote:@vnrgoli, check the baud rate on the PiCAN adapter side is the same as the one configured in /etc/network/interfaces on the RPI.
I can well asure that following this post till the end and I had every thing working fine.
It did not help. Below is the can entry in /etc/network/interfaces

Code: Select all

auto can0
iface can0 can static 
bitrate 500000
 
auto can1 
iface can1 can static 
bitrate 500000
I am using skpangs PiCan Duo http://skpang.co.uk/catalog/p ... -1480.html
Does it require a different bitrate? I don't see any such indication in their user docs. Their customer support is not helpful either.

haseel
Posts: 1
Joined: Fri Jun 09, 2017 9:28 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Wed Jul 26, 2017 5:22 pm

Hey, I am using raspberry pi 3 with MCP2515 for reading and sending CAN messages via SPI.I am following all the steps as specified above but I'm neither able to send nor read any CAN message.While using the candump and cansend command i don't receive any error but I'm not any getting any output also. How should i proceed now ???? :?

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Wed Jul 26, 2017 7:54 pm

Might be:
  • you set wrong bitrate (different that is on the bus that you connect to)
  • No ground - without GND connected should work but... Personally I had problems without connecting GND of nodes.

iwl
Posts: 26
Joined: Mon Dec 17, 2012 5:35 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Sun Sep 03, 2017 1:31 am

Hi,

I've just got out if I cansend a frame and it is not Acked it is retransmitted forever and the buffer fills until no more space available.

I've red somewhere switching the loopback on makes Nacks ignored, but messages are not send over the bus at all then.

Can I change this somehow? I've just wanted to send messages and get it logged with an elm327 at the other end, sniffing only, not acking.

iwl

pnb990
Posts: 1
Joined: Thu Oct 19, 2017 11:30 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Thu Oct 19, 2017 11:34 am

Hello,

I was follow this tutorial successfully on Debian Jessie.
But with Debian Stretch I cannot find net folder in :
ls /sys/bus/spi/devices/spi0.0/
or
ls /sys/bus/spi/devices/spi0.1/

Someone I have same problem ? or any ides to test ?

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Thu Oct 19, 2017 6:33 pm

pnb990 wrote:
Thu Oct 19, 2017 11:34 am
Hello,

I was follow this tutorial successfully on Debian Jessie.
But with Debian Stretch I cannot find net folder in :
ls /sys/bus/spi/devices/spi0.0/
or
ls /sys/bus/spi/devices/spi0.1/

Someone I have same problem ? or any ides to test ?
Check connections.... If On deb 8.x works then on 9.1 should too....

Just tested:
rpi-canbus-debian91-work.png
rpi-canbus-debian91-work.png (46.95 KiB) Viewed 7972 times
I used in config only one line (without the 2nd with bcm2835) - seems works ok (dmesg ok, net/can0 driver loaded).
Why only first line? I'm just too lazy to type too much :lol:

muekno
Posts: 13
Joined: Sat Mar 04, 2017 2:46 pm

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Mon Nov 06, 2017 3:26 pm

Hi I get can0 and MCP initialized, I can enter the send lien with no error. The only difference to you setup is I hab a 16MHz quartz, but I have changed the line in config.txt

Code: Select all

dtoverlay=mcp2515-can0,oscilator=16000000,interrup=12
but I get

Code: Select all

~# ip -d -s link  show dev can0
3: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state BUS-OFF restart-ms 0 
          bitrate 125000 sample-point 0.875 
          tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
          mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
          clock 8000000
          re-started bus-errors arbit-lost error-warn error-pass bus-off
          0          0          0          1          1          1         numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0 
    
what tells me the 16Mhz clock is not accepted.

further question I think for my application I need a LISTENONLY Mode, how can I get this mode.

Thanks for any help
Rainer

User avatar
saper_2
Posts: 232
Joined: Sun Aug 03, 2014 10:08 am
Location: PL

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Tue Nov 14, 2017 6:02 pm

muekno wrote:
Mon Nov 06, 2017 3:26 pm
Hi I get can0 and MCP initialized, I can enter the send lien with no error. The only difference to you setup is I hab a 16MHz quartz, but I have changed the line in config.txt

Code: Select all

dtoverlay=mcp2515-can0,oscilator=16000000,interrup=12
... CUT ...
what tells me the 16Mhz clock is not accepted.

further question I think for my application I need a LISTENONLY Mode, how can I get this mode.
Hmmm, your overlay params syntax is bad :D
check again "carefully": https://github.com/raspberrypi/firmware ... t/overlays 8-)

I don't know about using can from userapp , but

Code: Select all

candump
can "dump" everything that happening on CAN bus.

galicin
Posts: 7
Joined: Wed Dec 09, 2015 3:47 am

Re: [quick-guide] CAN bus on raspberry pi with MCP2515

Thu Nov 30, 2017 6:38 pm

I did patch the same MCP2515 PCB and using PiZero W.
candump and cansniffer works fine, but when I try cansend at 500000 speed I receive on the PC with USB CAN interface frame with some wrong bits.
Do you know what could be the reason? I see a lot of discussions about SPI latency ...

Return to “Interfacing (DSI, CSI, I2C, etc.)”