msperl
Posts: 325
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Tue May 19, 2015 9:10 am

If you go that route then you might just as well go all the way to use USB directly and leave SPI behind.
Then the device is not focused on one specific HW (=RPI) and can get just as easily get reused with other boards as well...
slcan is then probably the best choice.

nitin30
Posts: 2
Joined: Thu May 28, 2015 10:59 am

Re: CAN controller

Thu May 28, 2015 11:23 am

what is irq id for spi interrupt ?

cr08
Posts: 6
Joined: Wed Jun 10, 2015 1:29 pm

Re: CAN controller

Wed Jun 10, 2015 1:41 pm

I've been skimming through this thread and I am curious what the cliffnotes version of the progress is. I've been eyeing doing some CAN work for a while but it's been hard to find anything relatively inexpensive and compatible with the Pi. I do see a handful of mentions of the Futurlec board and being used with the Pi but I see nothing about how to interface or setting up the software/driver side which is throwing me. If I had even a prod in a particular direction that it is doable I'd pick up a board in a heartbeat and start hacking away. :P

skpang
Posts: 18
Joined: Mon Jul 29, 2013 10:09 pm
Location: Essex, UK
Contact: Website

Re: CAN controller

Wed Jun 10, 2015 2:03 pm

There is a PiCAN board for the Raspberry Pi.
http://skpang.co.uk/catalog/pican-canbu ... -1196.html

Installing drivers for Raspberry Pi 2.
http://skpang.co.uk/blog/archives/1165

Example of writing your own software.
http://skpang.co.uk/blog/archives/1199

VGutnik
Posts: 1
Joined: Fri Jun 12, 2015 3:19 pm

Re: CAN controller

Fri Jun 12, 2015 3:32 pm

Mcp2515 chip can replace the controller pic18f25k80.
It has a 3kB RAM which can be used as a buffer.
We need to write a simple program in PIC assembler.

danjperron
Posts: 2878
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: CAN controller

Fri Jun 12, 2015 5:50 pm

Mcp2515 chip can replace the controller pic18f25k80.
It has a 3kB RAM which can be used as a buffer.
We need to write a simple program in PIC assembler.
??? Is the MCP2515 is what we are using?
I think you mean the opposite.

I know that chip I used it on my lamp post.

Code: Select all

https://www.raspberrypi.org/forums/viewtopic.php?p=444938#p444938
The PIC cpu is very good on the other end of the bus but I don't see the advantage to replace the MCP2515. Maybe the buffer made by ram will help?

cr08
Posts: 6
Joined: Wed Jun 10, 2015 1:29 pm

Re: CAN controller

Mon Jun 22, 2015 3:25 pm

I have a related question to ask: Ultimately my intent is to try and communicate with two buses. I see with the SPI bus on the Pi and some diagrams in theory it should be doable. Two CS pins to a canbus board each and the rest of the SPI pins tied together between them. Is the existing software capable of handling this or would something need to be custom coded? I'd like to try and use socketcan and essentially have two can 'network interfaces' to work with.

msperl
Posts: 325
Joined: Thu Sep 20, 2012 3:40 pm

Re: CAN controller

Mon Jun 22, 2015 3:34 pm

If you are asking: can I run multiple can boards (mcp251x or otherwise)?

Then the answer is yes: you can easily do that - right now I run 2 mcp2515 and it works fine (with the correct device-tree).

You can even add some kernel based CAN-bridging between the two interfaces by using the cangw tool to configure the routing inside the kernel (including some modifications to the data in the middle).

cr08
Posts: 6
Joined: Wed Jun 10, 2015 1:29 pm

Re: CAN controller

Mon Jun 22, 2015 3:38 pm

Thanks! That's what I was hoping for. :)

bertieuk
Posts: 2
Joined: Thu Jul 02, 2015 7:31 pm

Re: CAN controller

Thu Jul 02, 2015 7:48 pm

Hi all

Apologies if some/all of this has been covered, but you'll appreciate this thread is now quite long, and whilst I've read through quite a lot, I haven't found an answer to my problem.

Background - I'm trying to connect a Pi + SKPang PICAN to my Solar Thermal controller, a unit that measures temperatures in my water tank & roof, and turns on pumps, bypass relays, etc. It's a LTDC from Sorel.de (http://www.sorel.de/en/products/solar-thermal/ltdc/) and has a CAN-Interface for their own (expensive!) network connector.

I've build a Raspbian memory card and got the PICAN interface recognised, etc. (light comes on it)

Main problems I have are

1) I don't know which is Can_H & Can_L coming from the Sorel
2) I don't know the bitrate
3) I can't get any output in candump

I've tried loads of different bitrate settings with ip link, and tried the can wires both way round, but all I can get in candump is controller-problem{rx-error-warning} or controller-problem{rx-error-passive} and only when I flash touch the can wires to the terminals.

I have both a 1st gen Pi B and a Pi 2 to play with - not sure if this makes a difference.

ANY help / pointers would be gratefully received! Thanks.

edo1
Posts: 136
Joined: Sun Jun 15, 2014 3:33 pm
Location: Russia

Re: CAN controller

Fri Jul 03, 2015 1:03 am

3) I can't get any output in candump
you could check your config with any CAN-aware car.
1) I don't know which is Can_H & Can_L coming from the Sorel
2) I don't know the bitrate
an oscilloscope might help a lot.

bertieuk
Posts: 2
Joined: Thu Jul 02, 2015 7:31 pm

Re: CAN controller

Fri Jul 03, 2015 9:01 am

you could check your config with any CAN-aware car.
Will try this over the weekend, thanks

lau
Posts: 1
Joined: Tue Jul 07, 2015 9:36 pm

Re: CAN controller

Tue Jul 07, 2015 9:52 pm

Hi,

I've been following and read most of the posts in this thread, but dind't find a solution to my problem. I have a RPI Model b+ and an arduino CAN shield from Sparkfun (https://www.sparkfun.com/products/10039). I've succesfully used the shield on my arduino uno, but would like to hook this shield up to my RPI to analyze messages on the bus.

I've hooked the shield up to the RPI as follows:

P1-01 3V3 -> MCP2515 VCC
P1-02 5V -> MCP2551 VCC
P1-06 GND -> MCP25xx GND
P1-19 GPIO10 -> MOSI
P1-21 GPIO9 -> MISO
P1-22 GPIO25 -> MCP2515 INT
P1-23 GPIO11 -> SCK
P1-24 GPIO8 -> CS0

I've used the bit banging bash script in this thread to test the shield with some success, but the result is not stable. Most of the time is doesn't work and sometimes i get the correct result:

Resetting MCP2515
RESET 0 0x00
Read MCP2515 registers
CMD-READ 0 0x00
REG-CNF3 0 0x00
CNF3 0 0x00
CNF2 0 0x00
CNF1 0 0x00
INTE 0 0x00
INTF 0 0x00
EFLG 0 0x00
CANSTAT 128 0x80
CANCTRL 135 0x87

I'm a bit confused why the results aren't stable. The wires and connections seems to be stable. Am i missing something?

Kind regard, Laurens

User avatar
bomba5
Posts: 10
Joined: Thu Jul 09, 2015 1:58 pm
Location: Catania, IT

Re: CAN controller

Mon Jul 13, 2015 12:06 pm

Hello,

I'm stuck in SPI guys:

Code: Select all

[email protected] ~ $ uname -a
Linux pi1 3.12.28+ #709 PREEMPT Mon Sep 8 15:28:00 BST 2014 armv6l GNU/Linux

[email protected] ~ $ lsmod
Module                  Size  Used by
can_bcm                11827  0 
can_raw                 6295  1 
can                    23718  2 can_bcm,can_raw
mcp251x                 9411  0 
can_dev                 9915  1 mcp251x
spi_config              9379  0 
spi_bcm2708             8027  0 
snd_bcm2835            19584  0 
snd_soc_bcm2708_i2s     6202  0 
regmap_mmio             2818  1 snd_soc_bcm2708_i2s
snd_soc_core          127841  1 snd_soc_bcm2708_i2s
snd_compress            8259  1 snd_soc_core
regmap_i2c              1661  1 snd_soc_core
snd_pcm_dmaengine       5505  1 snd_soc_core
regmap_spi              1913  1 snd_soc_core
snd_pcm                83845  3 snd_bcm2835,snd_soc_core,snd_pcm_dmaengine
snd_page_alloc          5132  1 snd_pcm
snd_seq                55484  0 
snd_seq_device          6469  1 snd_seq
snd_timer              20998  2 snd_pcm,snd_seq
leds_gpio               2079  0 
led_class               4118  1 leds_gpio
snd                    62252  7 snd_bcm2835,snd_soc_core,snd_timer,snd_pcm,snd_seq,snd_seq_device,snd_compress

[email protected] ~ $ modinfo spi_bcm2708
filename:       /lib/modules/3.12.28+/kernel/drivers/spi/spi-bcm2708.ko
alias:          platform:bcm2708_spi
license:        GPL v2
author:         Chris Boot <[email protected]>, Martin Sperl
description:    SPI controller driver for Broadcom BCM2708
srcversion:     AA32BEBA832149A11535B88
alias:          of:N*T*Cbrcm,bcm2708-spi*
depends:        
vermagic:       3.12.28+cancan-pi1 preempt mod_unload modversions ARMv6 
parm:           mode:Processing mode: 0=polling, 1=interrupt driven, 2=dma (default) (short)
parm:           realtime:Run the driver with realtime priority (bool)
parm:           debug:Turn on debug output (uint)

[email protected] ~ $ ifconfig can0
can0      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:17965 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:10 
          RX bytes:143720 (140.3 KiB)  TX bytes:0 (0.0 B)
dmesg at boot:

Code: Select all

[   13.417646] bcm2708_spi bcm2708_spi.0: DMA channel 4 at address 0xf2007400 with irq 20
[   13.441009] bcm2708_spi bcm2708_spi.0: DMA channel 5 at address 0xf2007500 with irq 21
[   13.469733] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[   13.484920] bcm2708_spi bcm2708_spi.0: SPI Controller running in interrupt-driven mode
[   13.642660] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=22:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
[   13.660182]  spi_config_match_cs: SPI0: check CS=0 to be 0
[   13.667395]  spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[   13.676159] spi_config_register:spi0.0:mcp2515: found already registered device
[   13.685175]  spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[   13.701373] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=22/192
[   13.734027] spi_config_register:spi0.0:platform data:da2709e0: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00  .$... ..........
[   13.750681] spi_config_register:spi0.0:platform data:da2709f0: 00 00 00 00                                      ....
[   13.848897] CAN device driver interface
[   13.875964] mcp251x spi0.0: probed
[   19.483076] FAT-fs (mmcblk0p1): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
[   21.873849] smsc95xx 1-1.1:1.0 eth0: hardware isn't capable of remote wakeup
[   22.411370] mcp251x spi0.0 can0: bit-timing not yet defined
[   22.411404] mcp251x spi0.0: unable to set initial baudrate!
[   22.411885] mcp251x spi0.0 can0: bit-timing not yet defined
[   22.411914] mcp251x spi0.0: unable to set initial baudrate!
[   22.411966] mcp251x spi0.0 can0: bit-timing not yet defined
[   22.411985] mcp251x spi0.0: unable to set initial baudrate!
[   22.412030] mcp251x spi0.0 can0: bit-timing not yet defined
[   22.412049] mcp251x spi0.0: unable to set initial baudrate!
[   22.412093] mcp251x spi0.0 can0: bit-timing not yet defined
[   22.412110] mcp251x spi0.0: unable to set initial baudrate!
[   23.514162] mcp251x spi0.0 can0: bit-timing not yet defined
[   23.514198] mcp251x spi0.0: unable to set initial baudrate!
[   23.526027] smsc95xx 1-1.1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0x45E1
[   24.515408] mcp251x spi0.0 can0: bit-timing not yet defined
[   24.515444] mcp251x spi0.0: unable to set initial baudrate!
[   24.520360] bcm2835-cpufreq: switching to governor ondemand
[   24.520413] bcm2835-cpufreq: switching to governor ondemand
[   25.516646] mcp251x spi0.0 can0: bit-timing not yet defined
[   25.516682] mcp251x spi0.0: unable to set initial baudrate!
[   26.517908] mcp251x spi0.0 can0: bit-timing not yet defined
[   26.517946] mcp251x spi0.0: unable to set initial baudrate!
[   27.519166] mcp251x spi0.0 can0: bit-timing not yet defined
[   27.519206] mcp251x spi0.0: unable to set initial baudrate!
[   28.418835] Adding 102396k swap on /var/swap.  Priority:-1 extents:1 across:102396k SSFS
[   28.520412] mcp251x spi0.0 can0: bit-timing not yet defined
[   28.520452] mcp251x spi0.0: unable to set initial baudrate!
[   29.455998] can: controller area network core (rev 20120528 abi 9)
[   29.456185] NET: Registered protocol family 29
[   29.488010] can: raw protocol (rev 20120528)
[   29.521021] mcp251x spi0.0 can0: bit-timing not yet defined
[   29.521059] mcp251x spi0.0: unable to set initial baudrate!
[   29.521171] can: broadcast manager protocol (rev 20120528 t)
[   29.574934] mcp251x spi0.0: CNF: 0x00 0x91 0x01
I manage to get CAN up and working but when it gets messages in delta shorter than 0.5ms, it hangs and I've got to rmmod/modprobe to get the interface up again.
I guess this is a very well known issue but googling around did not help this time.

J
---
bomba

User avatar
bomba5
Posts: 10
Joined: Thu Jul 09, 2015 1:58 pm
Location: Catania, IT

Re: CAN controller

Mon Jul 13, 2015 4:57 pm

For everybody struggling with SPI latency issues on Raspberri PI module B+ and MCP2515 based CAN interfaces:

on your computer, download the latest Raspbian release from http://downloads.raspberrypi.org/raspbian_latest
and place it on a SD card as described in https://www.raspberrypi.org/documentati ... s/linux.md

Place the SD inside your module and power it on. This will be the first time you boot into your new Raspbian so
raspi-config will show up automagically - if not, type:

Code: Select all

cd /usr/bin 
sudo ./raspi-config
Select "Advanced options"
Image
Select "SPI"
Image
Confirm you want the SPI interface enabled. Confirm you want the SPI kernel module to be loaded by default, then exit.
Update your system

Code: Select all

sudo apt-get update 
sudo apt-get upgrade 
sudo reboot
Update your kernel

Code: Select all

sudo rpi-update
Add the device tree overlays in /boot/config.txt/

Code: Select all

sudo vi /boot/config.txt
by adding the following lines at the very bottom of the file (oscillator freq and interrupt number may vary)

Code: Select all

dtparam=spi=on 
dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=22 
dtoverlay=spi-bcm2835-overlay
dtoverlay=spi-dma-overlay
Reboot your system, after that you would be able to bring up your can interface by typing

Code: Select all

sudo /sbin/ip link set can0 up type can bitrate 500000
Adjust the bitrate to match your needings.

Install can-utils

Code: Select all

git clone https://github.com/linux-can/can-utils.git
cd can-utils
./autogen.sh
./configure
make
sudo make install
Done! Refer to can-utils documentation to test your hardware.
https://en.wikipedia.org/wiki/SocketCAN
* based on http://skpang.co.uk/blog/archives/1165
Last edited by bomba5 on Thu Jul 30, 2015 9:23 am, edited 6 times in total.
---
bomba

cr08
Posts: 6
Joined: Wed Jun 10, 2015 1:29 pm

Re: CAN controller

Mon Jul 13, 2015 5:52 pm

In regards to the above post and curious about the oscillator frequency option:

I actually picked up the CAN Mini board for my project and it is all wired up correctly and all. After playing with it a bunch I have on one occasion been able to get a working loopback configuration and actually get messages sent from one terminal to another.

What I want to know is the existing documentation defaults to a 16mhz oscillator but on the CAN Mini board the 'can' I read is etched as 20mhz. I'm just curious how this would affect things? Leaving at 16mhz seems to be the only thing that worked for me at least using the loopback mode.

I did try hooking it up to my car (Ford) to the MS-CAN lines in the DLC connector, configured the CAN interface for 125kb but got absolute bupkis and even the connection stats showed 0 across the board. I assume even is misconfigured including with the oscillator frequency wrong if something tried to go across the bus it would at least register errored packets?

I need to actually investigate at a lower level and see what my car offers in the way of buses. It is a 2007 which is just a year shy of the 2008 mandate for CAN, but it does have an HS-CAN bus for the powertrain and the radio has it's own isolated 2-node MS-CAN just for optional aux/sat/dvd modules. But it is supposed to (or at least the newer years do) have the MS-CAN on other modules such as the BCM offered via the DLC connector. Sadly I can't find a proper wiring diagram or any written confirmation saying that the 2007 model year does or does not have this.

Is there possibly a way to use a multimeter to measure the pins in the car and see whether or not something is there to begin with?

andrea.cane
Posts: 3
Joined: Tue Jul 28, 2015 11:23 am

Re: CAN controller

Tue Jul 28, 2015 11:46 am

hi guys,
i have a strange problem no with socket can, but the integration with the driver for a touch screen, for clarify the my system and hardware used.
i have followed the rules put in this forum and i can load the driver se the board 2515 and communicate between two board, i have 2 Pi B+ with pican installed.

is the dmesg_before.

now i have bought this 7 inch touchscreen

http://www.wvshare.com/product/7inch-HDMI-LCD-B.htm

to use the touch i need to install the driver shared from a dvd

but when i have installed the driver i can't use the can-socket and everithing as before, i think because in sys/module it disappearance the folder bcm-2835.

could you say how i can fixed this problem.

thanks

arndt
Posts: 3
Joined: Mon Aug 31, 2015 11:01 am

Re: CAN controller

Fri Sep 18, 2015 9:04 am

I first asked this in a thread of its own, and got no answer, and then I found this thread, where all the interesting information seems to be.


I am somewhat new to raspberry pi, and kernel building, and device drivers, but not programming in general, so I will be using the wrong words.

I have an SD card, which was prepared using the instructions on this page: http://elinux.org/RPi_CANBus, and then doing insmod on the modules can.ko, can-bcm.ko, can-dev.ko, can-raw.ko, mcp251x.ko, mcp2515.ko and spi-cm2708.ko, finally doing "ip link set can0". The kernel is 3.6. This setup works (except for the latency problems that apparently a lot of people are having).

Now I want to use kernel 4.2, because a more recent kernel than 3.6 is needed for some camera that we want to use. The instructions on the page I mentioned don't fit completely anymore, but I think I could adapt all steps appropriately. When I run this kernel and do this command:

ip link set can0 up type can bitrate 500000

I get the error message "Invalid argument", and in /var/log/messages, it says

"A link change request failed with some changes committed already. Interface can0 may have been left with an inconsistent configuration, please check."

I have read at some place (maybe this forum) that people do use the CAN bus with kernel 4.2. They were asking whether the alternative 2515 module (described at the end of the instruction page) can be made to run there, and I'd like to know that too, since it has better latency, but to begin with I can't get CAN to work at all. Perhaps 4.1 will be sufficient for me, but I tried that too, with the same result.

Once having a 4.2 that didn't work, I went through the instructions for 3.6 and got back a 3.6 that worked, and then I went to 4.2 again.

What could be wrong?

polishpixel
Posts: 1
Joined: Wed Sep 23, 2015 4:04 am

Re: CAN controller

Wed Sep 23, 2015 4:16 am

Hi Guys,

I am having a problem getting cansniffer to work. Would really appreciate some help. Candump works perfectly and has a lot of data going through it.

But when I try to run cansniffer on the same interface all i get is XXX delta ID data...

Where the XXX is there are numbers that increment from 1 -100, then when they reach 100 they reset to 1. I am running this command: cansniffer can0.

No matter what I do this is the result I get. Thanks so much!

skpang
Posts: 18
Joined: Mon Jul 29, 2013 10:09 pm
Location: Essex, UK
Contact: Website

Re: CAN controller

Tue Sep 29, 2015 2:55 pm

Just tried the new Raspbian Jessie and PiCAN works fine. You don't need to do rpi-update anymore.

Good work.

Sl8rBug
Posts: 12
Joined: Fri Oct 02, 2015 10:18 am
Location: Lara, Victoria, Australia

Re: CAN controller

Fri Oct 02, 2015 10:33 am

Hi skpang,
Could you list the steps you went through to get the PiCAN working with Jessie?

I've just bought a RPi2 and intend to use a CAN module like this one:-
http://hacktronics.co.in/home/1253-mcp2515-can-bus-module-tja1050-receivers-spi-protocol.html
(This site has a circuit diagram of the module and a manual in chinese you can download. I actually bought the module from eBay.)

I'm hanging out for Jessie-Lite which is being asked for by others as a Command Line only version of Raspbian.

Regards,
John

skpang
Posts: 18
Joined: Mon Jul 29, 2013 10:09 pm
Location: Essex, UK
Contact: Website

Re: CAN controller

Fri Oct 02, 2015 10:42 am

The procedure is for use with PiCAN board
http://skpang.co.uk/catalog/pican-canbu ... -1196.html
Don't know if it will work with other boards.

This is the procedure:
http://skpang.co.uk/blog/archives/1165

You don't need the sudo rpi-update anymore.

Sl8rBug
Posts: 12
Joined: Fri Oct 02, 2015 10:18 am
Location: Lara, Victoria, Australia

Re: CAN controller

Fri Oct 02, 2015 12:52 pm

Thanks, I'll give it a go.

Regards,
John

pravinkamble
Posts: 1
Joined: Wed Nov 04, 2015 8:38 pm

Re: CAN controller

Wed Nov 04, 2015 9:04 pm

Hello skpang,

I have installed the latest raspbian wheezy (kernel version 3.18) on Raspberry Pi 2 Model B V1.1.
After updating and upgrading, i seen the new kernel version 4.1.7 when i run 'uname -a' command.

I have followed all the procedure as you explained in the link 'http://skpang.co.uk/blog/archives/1165'
but when i run command 'sudo /sbin/ip link set can0 up type can bitrate 500000' then i got an error i.e.
Cannot find device "can0".

I don't know where i am doing mistake. please help me.

skpang
Posts: 18
Joined: Mon Jul 29, 2013 10:09 pm
Location: Essex, UK
Contact: Website

Re: CAN controller

Mon Nov 16, 2015 2:35 pm

pravinkamble,

Check you have a correct entry in the /boot/config.txt file.

Make sure you have add these lines.

dtoverlay=mcp2515-can0-overlay,oscillator=16000000,interrupt=25
dtoverlay=spi-bcm2835-overlay


skpang

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

Who is online

Users browsing this forum: No registered users and 10 guests