satarassh
Posts: 3
Joined: Mon Mar 03, 2014 12:57 am

Re: CAN controller

Tue Sep 02, 2014 8:04 pm

Hi :)

After long work and a lot of pain i managed to set up can communication on Raspberry Pi. Since i experienced lack of simple help here in this discussion i want to share my knowledge with you. Here is what i did:

- I bought a module http://skpang.co.uk/catalog/pican-canbu ... -1196.html
- I mounted a jumper on this module in position JP3.
- Installed latest raspbian (2014-06-20-wheezy-raspbian) on 4GB sd card

Write following commands in terminal:
sudo rpi-update bfd37013c701f10c6df585346ee1d3d3bdf88b3b
#reboot

cd /tmp; wget http://lnxpps.de/rpie/rpi-can-3.12.22+.tar.bz2
cd /; sudo tar jxvf /tmp/rpi-can-3.12.22+.tar.bz2
sudo depmod -a
sudo reboot

sudo modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
sudo modprobe mcp251x
sudo ip link set can0 up type can bitrate 250000
sudo ip -s -d link show can0

... and this is it! CanBus communication now works like a charm

To test it open two terminals on Raspberry Pi:
- in first one run command: candump can0
- in second one run command: cansend can0 100#12345678

in first terminal should appear a message: can0 000 [4] 12 34 56 78

Have a great time using Raspberry Pi with Can Communication and let me know if it worked for you ;)

Endres
Posts: 2
Joined: Wed Sep 03, 2014 6:23 pm

Re: CAN controller

Wed Sep 03, 2014 7:25 pm

Hi,

I've got my own CAN board up and running using my self compiled kernel 3.12.26+ using mcp251x and spi-config modules.
Sending and receiving packets works like a charm.
However sometimes I got weird error frames while sending. In this case a restart of the mcp251x module and the interface does not suffice to get the chip working again. After that, I am only getting more of such messages when restarting my interface. The only solution would be to hard reset at least the MCP2515, then I could reconfigure and reuse the interface. Is this a known problem? Unfortunately I was not able to reproduce this, so maybe this was only a configuration fault (for example to load the modules in the wrong order or configured the spi wrong or something).

But my biggest thing I worry about is that I don't know which is the best configuration currently. I did read something about mcp2515a and spi-DMA modules, but don't really know if they work better or if there are any bugs in there. I am aware that raspberry pi and CAN is not such good idea, but I really don't know if there isn't a good working kernel / module combination for now which works reliable, as there might have been active development since then when all said it is better to go with a beaglebone black.

So do you actually have an idea which setup is currently working best for using the MCP2515 on the pi? I must say, my current setup seems to work, but the question is how long this will last.

UpAndAway
Posts: 1
Joined: Sat Sep 06, 2014 4:30 pm

Re: CAN controller

Sat Sep 06, 2014 4:42 pm

My first test with the Gnublin CAN interface leaded me to similiar problems. Actually i have a logic analyser scope connected to the interface lines so i would be able to search for the last data packets transferred via SPI before the data transfer stops.
But i am aware of digging into depth concerning the kernel part of the communication because i am not familar with linux and kernel programming, so i would like to ask if there is somebody out there who could help stepping through the software part of the driver ?

I am not sure if the RPi is the best choice for my project so i am looking for a more stable system/configuration. (BeagleBone?)

Any hints where to go from here? There is a lot of work that i have to do for my project even on a system running fine, but i have no estimation how far i have to go to get to this point.

Any suggestions welcome - Udo

Endres
Posts: 2
Joined: Wed Sep 03, 2014 6:23 pm

Re: CAN controller

Mon Sep 08, 2014 4:45 pm

It seems that these error frames do only happen if the connected hardware (another mcp2515) is not configured properly. If it is then configured, the normal operation would continue. I will make further observations, but for now I think CAN on the raspberry pi is not that bad.

moritzmhmk
Posts: 7
Joined: Mon Feb 17, 2014 7:37 pm

Re: CAN controller

Sat Sep 13, 2014 12:52 pm

Hi

did someone already compile the modules for 3.12.28+ and could upload them ;)

Moritz

bertr2d2
Posts: 97
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Sat Sep 13, 2014 11:13 pm

Hi Moritz,
moritzmhmk wrote:Hi

did someone already compile the modules for 3.12.28+ and could upload them ;)

Moritz
new modules can be found here: http://lnxpps.de/rpie/rpi-can-3.12.28+.tar.bz2. Please give feedback.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Andreas Munoz
Posts: 5
Joined: Tue Aug 19, 2014 6:57 am

Re: CAN controller

Mon Sep 15, 2014 11:35 am

Hi,

I just have tried the new modules for 3.12.28+, but I have the same problem I had with the old ones. I have a problem with spi-config, because in the initialization it gaves me an error "mcp251x spi0.0: probe failed". The problem is that when the module reset the mcp2515, after that it tries to read CANSTAT and CANCTRL, and the CANCRTL is nor readeble until the mode operation is changed from the reset value, 111, to the configuration mode, 100. But the modules read both registers without changing the mode operation value. Does anyone has the same problem or know how to solve this? Maybe is a problem with the mcp2515?

Thanks. Regards.

Andreas

bertr2d2
Posts: 97
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Mon Sep 15, 2014 1:42 pm

Hi Andreas
Andreas Munoz wrote:Hi,

I just have tried the new modules for 3.12.28+, but I have the same problem I had with the old ones. I have a problem with spi-config, because in the initialization it gaves me an error "mcp251x spi0.0: probe failed". The problem is that when the module reset the mcp2515, after that it tries to read CANSTAT and CANCTRL, and the CANCRTL is nor readeble until the mode operation is changed from the reset value, 111, to the configuration mode, 100. But the modules read both registers without changing the mode operation value. Does anyone has the same problem or know how to solve this? Maybe is a problem with the mcp2515?

Thanks. Regards.

Andreas
"mcp251x spi0.0: probe failed" is normally the indication for bad wiring. The kernel module resets the mcp215x.
Please provide the output from:

Code: Select all

lsmod | egrep -i "spi|can|mcp2" ; dmesg | egrep "spi|can|mcp2" ; cat /proc/interrupts
BTW: Which mcp2515 board do you use ? Is the the MCP2515 reset pin pulled up ?

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Andreas Munoz
Posts: 5
Joined: Tue Aug 19, 2014 6:57 am

Re: CAN controller

Tue Sep 16, 2014 1:29 pm

Hi Gerd,

I just changed the mcp2515 chip and the problem disappeared. Thanks for the interest Gerd. Now I'm trying to send a CAN message, but when I use "cansend", I can't see any change in the SPI outputs and of course none in the CAN outputs.
I used the schematic of the http://skpang.co.uk/catalog/pican-canbu ... -1196.html

I obtain these messages (just say I have a clock of 20 MHz).
[ 17.822227] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000:gpioirq=25:pd=20:pds32-0=20000000:pdu32-4=0x2002:force_release
[ 17.846650] spi_config_match_cs: SPI0: check CS=0 to be 0
[ 17.857859] spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[ 17.870469] spi_config_register:spi0.0:mcp2515: found already registered device
[ 17.883323] spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[ 17.901984] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000 mode=0 and gpio/irq=25/195
[ 17.937470] spi_config_register:spi0.0:platform data:d9d49780: 00 2d 31 01 02 20 00 00 00 00 00 00 00 00 00 00 .-1.. ..........
[ 17.956451] spi_config_register:spi0.0:platform data:d9d49790: 00 00 00 00 ....
[ 18.123927] NET: Registered protocol family 10
[ 18.256372] mcp251x spi0.0: probed

[ 171.068712] mcp251x spi0.0: CNF: 0x01 0xbf 0x02

After that I recorded no more messages.

The modules are:
mcp251x 9411 0
spi_config 9379 0
can_bcm 11827 0
can_raw 6295 1
can_dev 9915 1 mcp251x
can 23718 2 can_bcm,can_raw
regmap_spi 1913 1 snd_soc_core
spi_bcm2708 4808 0

And the interruptions:

CPU0
3: 65672 ARMCTRL BCM2708 Timer Tick
16: 0 ARMCTRL bcm2708_fb dma
32: 617319 ARMCTRL dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
52: 1 ARMCTRL BCM2708 GPIO catchall handler
65: 13 ARMCTRL ARM Mailbox IRQ
66: 1 ARMCTRL VCHIQ doorbell
75: 1 ARMCTRL
77: 22245 ARMCTRL bcm2708_sdhci (dma)
80: 40 ARMCTRL bcm2708_spi.0
83: 20 ARMCTRL uart-pl011
84: 33151 ARMCTRL mmc0
195: 1 GPIO mcp251x
FIQ: usb_fiq
Err: 0

The interface can0 is up:
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:0 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:0 (0.0 B) TX bytes:0 (0.0 B)


And I type: cansend can0 123#deadbeef, but no result or even an error appears.

Maybe someone had the same problem and could help me. Thanks for your time.


Regards

Andreas

bertr2d2
Posts: 97
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Tue Sep 16, 2014 1:44 pm

Hi Andreas,

how did you setup the CAN Interface ("ip link set can0 ...") ? Do you use the loopback mode or do you have
a second CAN node on the CAN bus ? What does "ip -s -d link show can0" say ?

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Andreas Munoz
Posts: 5
Joined: Tue Aug 19, 2014 6:57 am

Re: CAN controller

Tue Sep 16, 2014 3:24 pm

To configure the interface I write: sudo ip link set can0 type can bitrate 250000 loopback on

And the interface shows:
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can <LOOPBACK> state ERROR-ACTIVE restart-ms 0
bitrate 250000 sample-point 0.850
tq 200 prop-seg 8 phase-seg1 8 phase-seg2 3 sjw 1
mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 10000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
0 0 0 0 0 0
RX: bytes packets errors dropped overrun mcast
0 0 0 0 0 0
TX: bytes packets errors dropped carrier collsns
0 0 0 0 0 0

I see some messages over SPI the first time I use cansend, but the next time I see nothing, like if the chip was blocked and I have to reset it. Those messages send the data over SPI and then read the CANINTF register. Maybe it is a hardware problem?

Thanks. Regards.

Andreas

bertr2d2
Posts: 97
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Tue Sep 16, 2014 3:53 pm

Hi Andreas,
Andreas Munoz wrote:Hi Gerd,

Code: Select all

[   17.822227] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000:gpioirq=25:pd=20:pds32-0=20000000:pdu32-4=0x2002:force_release
[   17.846650]  spi_config_match_cs: SPI0: check CS=0 to be 0
[   17.857859]  spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[   17.870469] spi_config_register:spi0.0:mcp2515: found already registered device
[   17.883323]  spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[   17.901984] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000 mode=0 and gpio/irq=25/195
One thing which I didn't saw on the first look: Your SPI speed is 10k, which is a little bit slow.
Please change this and send the output from "ip -s -d link show can0; cat /proc/interrupts" before and after you send a CAN packet in loopback mode.

Regards Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

Andreas Munoz
Posts: 5
Joined: Tue Aug 19, 2014 6:57 am

Re: CAN controller

Wed Sep 17, 2014 3:11 pm

I see these result before and after cansend.

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:0 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:0 (0.0 B) TX bytes:0 (0.0 B)

I've change the spi speed, but I'm having some troubles know because sometime the loading of the module mcp251x it's ok and sometimes no and I can't figure out why. Maybe the log shows "probed" and I do: modprobe mcp251x -r; modprobe mcp251x" and the result is "not probed" without any change. The same happens setting the bitrate, sometimes the CNF registers are written ok, sometimes not. It's really strange and I don't see the logic to this failure.

witte
Posts: 1
Joined: Tue Sep 23, 2014 8:36 pm

Re: CAN controller

Tue Sep 23, 2014 9:00 pm

Hi,
could you better explain following confusion:
"run candump in one terminal and cansend in another one"

Do you mean that with one RPI board and one MCP2515 we can do this, without connecting it to other CAN devices or a CAN bus? And we will see the packages arriving?
Or do we need to use the loopback commands in order to test without a real CAN bus?

Furthermore, if it is not possible to cansend and candump with one device without hooking up any real bus/devices, could we maybe force it to work by short circuiting RX and TX like we would do with serial buses (so far I couldn't get this to work with CAN)?

optimax
Posts: 2
Joined: Sat Sep 27, 2014 9:52 am

Re: CAN controller

Sat Sep 27, 2014 10:20 am

Hi,

I have successfully set up CAN communication between 2 Pi boards using CANberry v1.1 modules from industrialberry.
I use raspbian 3.12.28. I did the setup with the compiled driver modules from http://lnxpps.de/rpie/rpi-can-3.12.28+.tar.bz2.
I have the bus speed set at 250000.
Everything works fine in both directions with candump and cansend.
However, after a few tens of minutes, the communication hangs, for seemingly unknown reasons.

1) I have read that the mcp251x driver typically has this hanging issue on the raspberry pi. Has anyone experienced the same issue with raspbian 3.12.28 ? Is this hanging issue still around in general ?

2) I tried to use the mcp2515a driver that comes in http://lnxpps.de/rpie/rpi-can-3.12.28+.tar.bz2, as it has been reported to not have this hanging issue. While the CAN communication is properly established, the data sent and received is messed up. I have one Pi with the mcp251x driver, and one Pi with mcp2515a driver (all other configs the same, I only "modprobe 2515a" instead of "modprobe 251x").
mcp251x: cansend can0 01e1ffff#ff5544
mcp2515a (candump): can0 0FFFF878 [3] FF 55 44 (note the CAN-ID is messed up, data is correct)
and in the opposite direction
mcp2515a: cansend can0 01e1ffff#ff554467
mcp251x (candump): can0 01E1FFFF [4] FF 55 44 BF (note the data is messed up, the CAN-ID is correct)
Looking at "ip -s -d link show can0" on both Pis, the only difference I see is:
mcp251x: mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
mcp2515a: mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
So one has "seg1 3..16", the other has "tseg1 2..16".
Can onyone help me on this ? Or is the mcp2515a driver not a good idea ?

Thanks very much for any help you could provide.

jzhvymetal
Posts: 1
Joined: Tue Sep 30, 2014 6:33 am

Re: CAN controller

Tue Sep 30, 2014 6:45 am

Below are working steps to get a reliable CanBus working on the PI by cross compiling with Ubuntu. I use it with CoDeSys run-time which has a full CanOpen Master/Slave, J1939 Manager, and DeviceNet Scanner.

http://store.codesys.com/codesys-contro ... pi-sl.html

###Working directory for compiling and files
export WORKING_DIR=${HOME}/rpi2
###Number of processors to use during compiling (N+1)
export NUM_PROCESSORS=5
###PI IP ADDRESS
export PI_IP=192.168.10.104
###PI USERNAME
export PI_USER=root

###Get Required APPS to compile
sudo apt-get install gcc-arm-linux-gnueabi make ncurses-dev git dh-autoreconf

###Required of 64bit OS
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0

###Make direcotry for source files and compiler
cd ${HOME}
sudo mkdir -p $WORKING_DIR
cd $WORKING_DIR
sudo chmod og+w .

###Get the Get the kernel source
git clone https://github.com/raspberrypi/linux.git

###Get the Get cross compiler tools
git clone --depth 1 git://github.com/raspberrypi/tools.git

export KERNEL_SRC=$WORKING_DIR/linux


###Get config.gz from RPI copy to kernel source
scp root@192.168.10.104:/proc/config.gz config.gz
zcat config.gz > .config
mv .config $KERNEL_SRC

###Change to Kernel source DIR
cd $KERNEL_SRC

###Set KERNEL VERSION FOR REST OF Command
export KERNEL_VER=$(make kernelversion)

###Compile new Config
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- oldconfig -j${NUM_PROCESSORS}

####Make any new changes in kernel settings
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- menuconfig -j${NUM_PROCESSORS}
#Activate the following lines:
#
#[*] Networking support --->
#....<M> CAN bus subsystem support --->
#........<M> Raw CAN Protocol (raw access with CAN-ID filtering)
#........<M> Broadcast Manager CAN Protocol (with content filtering)
#............CAN Device Drivers --->
#................<M> Platform CAN drivers with Netlink support
#................[*] CAN bit-timing calculation
#................<M> Microchip MCP251x SPI CAN controllers
#................[*] CAN devices debugging messages
#
#....Device Drivers --->
#........[*] SPI support --->
#............<M> BCM2798 SPI controller driver (SPI0)
#............<M> User mode SPI driver support
#.......-*- GPIO Support --->
#............[*] /sys/class/gpio/... (sysfs interface)

####build the kernel
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j${NUM_PROCESSORS}
cd ${WORKING_DIR}/tools/mkimage
./imagetool-uncompressed.py ../../linux/arch/arm/boot/zImage
mkdir -p ${WORKING_DIR}/build/boot
mv kernel.img ${WORKING_DIR}/build/boot

####generate a directory containing kernel modules
cd $KERNEL_SRC
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- modules_install INSTALL_MOD_PATH=${WORKING_DIR}/build/ -j5

####Make spi-bcm2708
cd ${WORKING_DIR}
git clone https://github.com/notro/spi-bcm2708
cd ${WORKING_DIR}/spi-bcm2708
sudo sed -i 's#KDIR := /lib/modules/$(shell uname -r)/build#KDIR := ${KERNEL_SRC}#' Makefile
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
cp spi-bcm2708.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/kernel/drivers/spi


####Make spi-config
cd ${WORKING_DIR}
git clone https://github.com/msperl/spi-config
cd ${WORKING_DIR}/spi-config
sudo sed -i 's#KDIR := /lib/modules/$(shell uname -r)/build#KDIR := ${KERNEL_SRC}#' Makefile
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
cp spi-config.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/extra

####Make mcp2515
cd ${WORKING_DIR}
cd MCP2515
git clone https://github.com/jzhvymetal/MCP2515
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- XTRA="KBUILD_EXTRA_SYMBOLS=$KERNEL_SRC/drivers/net/can/Module.symvers" M=${WORKING_DIR}/MCP2515
cp mcp2515.ko ${WORKING_DIR}/build/lib/modules/${KERNEL_VER}+/kernel/drivers/net/can

###Make Can user tools
cd ${WORKING_DIR}
####////CAN NOT GET CANUTILS TO CROSSCOMPILE
#git clone git://gitorious.org/linux-can/can-utils.git
#cd can-utils
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi-
#make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- install DESTDIR=${WORKING_DIR}/build/usr PREFIX= -j5
###///NEEDS UPDATING ONCE CANUTILS CAN BE CROSS COMPILED
git clone https://github.com/jzhvymetal/canutil_pi
cd canutil_pi
mkdir -p ${WORKING_DIR}/build/usr/bin
cp * ${WORKING_DIR}/build/usr/bin

##Compress Updates and upload to PI
cd ${WORKING_DIR}/build
sudo tar czf updates.tgz *
scp updates.tgz ${PI_USER}@${PI_IP}:/tmp

#####Connect to your Raspberry PI over SSH
ssh ${PI_USER}@${PI_IP}

####Apply updates
cd /; sudo tar xvf /tmp/updates.tgz # you normally should'nt do that
sudo depmod -a

####Enable CAN in CoDeSys
nano /etc/CODESYSControl.cfg
####Add lines Below
[ComponentManager]
Component.1=CmpOpenSSL
Component.2=CmpCAACanL2
Component.3=CmpCAASdoServer
Component.4=CmpCAASdoClient
Component.5=CmpSocketCanDrv
####Exit and save ctrl+x

###reboot for new kernel to take effect
reboot

###Start Can On PI
sudo insmod /lib/modules/3.12.28+//kernel/drivers/spi/spi-bcm2708.ko realtime
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can.ko
sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/can-dev.ko
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-raw.ko
sudo insmod /lib/modules/3.12.28+/kernel/net/can/can-bcm.ko
sudo insmod /lib/modules/3.12.28+/extra/spi-config.ko devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=17:pd=20:pds32-0=10000000:pdu32-4=0x2002:force_release
sudo insmod /lib/modules/3.12.28+/kernel/drivers/net/can/mcp2515.ko
ip link set can0 up type can bitrate 250000 restart-ms 100 triple-sampling on

service codesyscontrol start

Janssuuh
Posts: 6
Joined: Fri Aug 29, 2014 2:57 pm

Re: CAN controller

Fri Oct 17, 2014 9:00 am

Hi,

With a lot of help of all you guys I got a Raspbian 3.12.20+ to start candumping and catching can messages from my Audi Infotainment bus.

My goal is to catch the can messages sent by key pressing the nav-system, of which I now achieved.
I installed xdotool to create a fake key-press which I trigger after simulair can message is received.

As you may expect I would like to use all this to remotely operate XBMC. I installed the github version of RB-tomaz (XBMC on Raspbian). Unfortunately this version (or this way of installing XBMC on top of Raspbian) does not seem to support the JSON technique, which keeps me from converting Raspbian candump script to triggering XBMC actions :(

I tried to install fresh XBMC (got the JSON to work after installing 'curl'), but that keeps my from installing the CAN controller. XBMC is version 3.12.21

Could anyone tell me what needs to be done (if even possible!) to make usable CAN modules for this XBMC version?
(I've read about crosscompiling; besides that panics me a bit, it seems to be used with Ubuntu?!)

Thanks in advance..

Janssuuh
Posts: 6
Joined: Fri Aug 29, 2014 2:57 pm

Re: CAN controller

Fri Oct 17, 2014 11:41 am

Update:

I uninstalled previous XBMC and installed new XBMC from http://michael.gorven.za.net/raspberrypi/xbmc
After trying to run my test shell script:

Code: Select all

PI="http://127.0.0.1/jsonrpc"

curl -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "Input.Home", "params": { }, "id": 1 }' $PI/code]

I still get error 'host not found'(while I'm in SSH).
I tried 'wpa_cli' which replies 'Could not connect to wpa_supplicant'.

Does Raspian uses different settings than XBMC on this, do I need to install additional hostingscripts?

floda
Posts: 1
Joined: Tue Oct 21, 2014 4:04 pm

Different output of MCP251x and MCP2515a

Tue Oct 21, 2014 4:11 pm

i ve noticed a difference when running the MCP251x vs MCP2515 driver. With MCP251x and candump i see normal CAN IDs. With MCP2515 i see EXTENDED ones.

When putting libcanopen on top it seems it gets confused somehow.

libcanopen output with MCP251x Driver looks ok. It is able to detect SDO, etc.

0.000000s STANDARD [0x33E] FC=0x6 ID=0x3E [8] 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF => PDO2 RX Node=0x3e 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
0.000000s STANDARD [0x3BE] FC=0x7 ID=0x3E [8] 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF => PDO3 TX Node=0x3e 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
0.000000s STANDARD [0x23E] FC=0x4 ID=0x3E [8] 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF => PDO1 RX Node=0x3e 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
0.000000s STANDARD [0x1BE] FC=0x3 ID=0x3E [2] 0xFF 0xFF => PDO1 TX Node=0x3e 0xff 0xff
0.011459s STANDARD [0x5F2] FC=0xB ID=0x72 [8] 0x01 0x29 0x3B 0x00 0x0F 0x20 0x00 0xB3 => SDO TX Node=0x72 Command=0x01 [Upload Domain Segment] [LAST] [T 0] [SI: 0]
0.011578s STANDARD [0x672] FC=0xC ID=0x72 [8] 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 => SDO RX Node=0x72 Command=0x60 [Upload Domain Segment] [T 0]
5.006040s STANDARD [0x702] FC=0xE ID=0x02 [1] 0x05 => NMT [Node Guarding] Node=0x02 State='Operational'
7.510194s STANDARD [0x701] FC=0xE ID=0x01 [1] 0x05 => NMT [Node Guarding] Node=0x01 State='Operational'
7.556107s STANDARD [0x73E] FC=0xE ID=0x3E [1] 0x05 => NMT [Node Guarding] Node=0x3E State='Operational'
7.488952s STANDARD [0x732] FC=0xE ID=0x32 [1] 0x05 => NMT [Node Guarding] Node=0x32 State='Operational'


libcanopen output with MCP2515A Driver of same traffic leads to very different output.

15.036839s EXTENDED Node ID=0x67D9701 [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown
15.113824s EXTENDED Node ID=0x5BFF73E [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown
0.016199s EXTENDED Node ID=0x67D95F2 [8] 0x01 0x26 0x3B 0x00 0x0F 0x20 0x00 0xB3 => NMT [Module Control] Node=0x26 Command='Start remote node'
0.016958s EXTENDED Node ID=0x5BFF672 [8] 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 => NMT [Module Control] Node=0x00 Command=Unknown
0.009779s EXTENDED Node ID=0x5BFF481 [8] 0x01 0xF2 0x4F 0x16 0x61 0x00 0xCC 0x05 => NMT [Module Control] Node=0xF2 Command='Start remote node'
0.010252s EXTENDED Node ID=0x67D9481 [8] 0x01 0xF2 0x4F 0x15 0x88 0xD0 0xC6 0x04 => NMT [Module Control] Node=0xF2 Command='Start remote node'
0.545353s EXTENDED Node ID=0x5BFF4BE [8] 0x82 0xF3 0x4F 0x01 0x01 0x00 0x00 0x00 => NMT [Module Control] Node=0xF3 Command='Reset communication'
0.711646s EXTENDED Node ID=0x67D94BE [8] 0x82 0xF3 0x4F 0x01 0x01 0x00 0x00 0x00 => NMT [Module Control] Node=0xF3 Command='Reset communication'
0.017349s EXTENDED Node ID=0x5BFF5F2 [8] 0x01 0x27 0x3B 0x00 0x0F 0x20 0x00 0xB3 => NMT [Module Control] Node=0x27 Command='Start remote node'
0.018860s EXTENDED Node ID=0x67D9672 [8] 0x60 0x00 0x00 0x00 0x00 0x00 0x00 0x00 => NMT [Module Control] Node=0x00 Command=Unknown
15.680642s EXTENDED Node ID=0x5BFF732 [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown
16.137000s EXTENDED Node ID=0x67D9702 [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown
10.202245s EXTENDED Node ID=0x5BFF701 [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown
10.252724s EXTENDED Node ID=0x67D973E [1] 0x05 => NMT [Module Control] Node=0x00 Command=Unknown


I would like to stick with the MCP2515A as it runs much more stable in my case. The other one stalls regularly.

Any idea how to resolve this.

anderian
Posts: 1
Joined: Fri Oct 24, 2014 1:26 pm

Re: CAN controller

Fri Oct 24, 2014 1:34 pm

In our project we use the PRI with MCP2515 to control CAN devices.
RPi version B works great, unfortunately after changing to B + not work it does not get the interrupt controller.

Electronics is correct, the assumption of RPI B all works.

Met with such a situation?

pauldcox
Posts: 2
Joined: Sat Nov 08, 2014 9:31 am

Re: CAN controller

Sat Nov 08, 2014 10:47 am

I was able to send and receive a few CAN messages with a RasPi Model B using the instructions provided here. I am using a Seed Studio CAN-BUS shield (MCP2515 at 16Mhz + MCP2551) with a TXB0108 level-shifter (adafruit) all wired manually. I reduced the 10Mbit rate to 1M since my wires are long and probably can't support such a high rate. I do confirm that the modprobe MCP251x leads to a probe fail if I have my USB wifi dongle in so if anyone know what to look at to help debug this, please let me know.

I followed the steps above that start with rpi-update bfd37... that use the 3.12.22+ kernel and some precompiled modules.

My wiring is as follows:

Code: Select all

RPI   <-->TXB0108<-->CAN_Shield
---       -------    ----------
SLCK  <-->A1  B1<--> SCK
MISO  <-->A2  B2<--> MISO
MOSI  <-->A3  B3<--> MOSI
CE0   <-->A4  B4<--> CS
GPIO25<-->A5  B5<--> INT
3.3V  <--> VCCA 
5V    <--> VCCB <--> 5V   
GND   <--> GND  <-->GND
(plus resistor soldered between 3.3v and TXB0108 OE pin)
Some outputs from the Raspberry for debug:

Code: Select all

dmesg output:

[  105.385013] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=1000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
[  105.385091]  spi_config_match_cs: SPI0: check CS=0 to be 0
[  105.385107]  spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[  105.385119] spi_config_register:spi0.0:mcp2515: found already registered device
[  105.385130]  spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[  105.387964] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=1000000 mode=0 and gpio/irq=25/195
[  105.388005] spi_config_register:spi0.0:platform data:d3755680: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00  .$... ..........
[  105.388025] spi_config_register:spi0.0:platform data:d3755690: 00 00 00 00                                      ....
[  116.965836] CAN device driver interface
[  116.984205] mcp251x spi0.0: probe failed
[  173.099117] mcp251x spi0.0: probe failed
(at this point I remove my usb wifi adapter - a TP-Link TL-WN821N)
[  215.183437] usb 1-1.2: USB disconnect, device number 4
[  215.187380] rtw_cmd_thread: DriverStopped(1) SurpriseRemoved(1) break at line 482
[  220.649256] mcp251x spi0.0: probed
[  220.785415] mcp251x spi0.0 can0: bit-timing not yet defined
[  220.785454] mcp251x spi0.0: unable to set initial baudrate!
(above two lines repeat a few dozen times)
[  276.734257] can: controller area network core (rev 20120528 abi 9)
[  276.734448] NET: Registered protocol family 29
[  276.755405] can: raw protocol (rev 20120528)

pi@rpimw1:~$ cat /proc/interrupts
           CPU0
  3:      88896   ARMCTRL  BCM2708 Timer Tick
 16:          0   ARMCTRL  bcm2708_fb dma
 20:          0   ARMCTRL  bcm2708_spi.0
 32:    1182230   ARMCTRL  dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
 52:         90   ARMCTRL  BCM2708 GPIO catchall handler
 65:         31   ARMCTRL  ARM Mailbox IRQ
 66:       1564   ARMCTRL  VCHIQ doorbell
 75:          1   ARMCTRL
 77:      17341   ARMCTRL  bcm2708_sdhci (dma)
 79:          4   ARMCTRL  bcm2708_i2c.0, bcm2708_i2c.1
 80:        154   ARMCTRL  bcm2708_spi.0
 83:       5724   ARMCTRL  uart-pl011
 84:      27594   ARMCTRL  mmc0
195:         90      GPIO  mcp251x
FIQ:              usb_fiq
Err:          0

pi@rpimw1:~$ ip -s -d link show can0
4: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
    link/can
    can state ERROR-ACTIVE restart-ms 0
    bitrate 250000 sample-point 0.875
    tq 250 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          0          0          0
    RX: bytes  packets  errors  dropped overrun mcast
    58         11       0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    16         4        0       0       0       0
Not sure why ip link shows 8Mhz clock when I thought I specified 16Mhz to spi-config

Picture of session and hardware available here:
https://drive.google.com/file/d/0B7-Kdr ... sp=sharing
https://drive.google.com/file/d/0B7-Kdr ... sp=sharing
https://drive.google.com/file/d/0B7-Kdr ... sp=sharing

bertr2d2
Posts: 97
Joined: Wed Aug 08, 2012 10:12 pm

Re: CAN controller

Sat Nov 08, 2014 2:22 pm

pauldcox wrote: <snip>
Not sure why ip link shows 8Mhz clock when I thought I specified 16Mhz to spi-config
8MHz is ok because the TQ calculation is based on FOSC/2.

Regards

Gerd
Easy to build CAN-Bus interface:
http://lnxpps.de/rpie

nos86
Posts: 1
Joined: Sat Nov 08, 2014 5:02 pm

Re: CAN controller

Sat Nov 08, 2014 5:13 pm

Hello all,

I worked for a lot of time adding the CAN communication to my RPi.
Fortunately, I got this thread that solved my glitch.. So, first of all, many thanks for the work you did.

Yesterday, I updated my RPi to latest Kernel (from 3.12.22+) in order to fix some known issues of previous version and CAN driver has stopped to work (as expected)
Now, I'd like to understand if (and eventually when) someone is working on the patch for kernel 3.12.31+.

For the moment, as a recovery action, I'll downgrade my RPi to version 3.12.28+

Again, thank you so much for the work you are doing and for the support.
Have a nice week end,
Salvo

Tim1313
Posts: 1
Joined: Fri Sep 19, 2014 1:48 pm

Re: CAN controller

Tue Nov 11, 2014 5:48 pm

Hello there!

I'm developing a multibus system and facing some problems a the moment. I've got two mcp2515 controllers connected to the RasPi. The bus should be fault tolarant, so I'm using two TJA1055 transceiver. When i'm sending on only one bus ( ifconfig can0 up, ifconfig can1 down), there is no problem at all, sending and receiving is just fine.
But when both buses are "online" i get sooner or later a problem. with cansend i get a "no buffer space available" error, so i was thinking the problem lies there ( at the intern buffer), but i think i was wrong. When the SPI speed is reduced it is more stable, the system is able to send more frames until it crashes. ( but it does crash sooner or later )
With a scope i noticed when exactly the error occurs and what happened. When im using both buses parallel it sometimes happens that after sending a message on both buses, both controllers are setting their INTERRUPT pin on active-low at exactly the same time. Then only one pin is set high again, the other one keeps being low forever (completely arbitrary which one). So no traffic over the SPI is possible any more, resulting in the "no buffer space" error message.
This problem should be handled by the driver i suppose, or what are you thinking?
Of course i do have seperate pins for the two INTERUPT pins, as for the chip select.
Here are the modules i use:

Code: Select all

 
#!/bin/sh
#Can
 insmod /lib/modules/3.12.22+/kernel/drivers/spi/spi-bcm2708.ko
 insmod /lib/modules/3.12.22+/kernel/net/can/can.ko
 insmod /lib/modules/3.12.22+/kernel/drivers/net/can/can-dev.ko
 insmod /lib/modules/3.12.22+/kernel/net/can/can-raw.ko
 insmod /lib/modules/3.12.22+/kernel/net/can/can-bcm.ko
 insmod /lib/modules/3.12.22+/kernel/drivers/spi/spi-config.ko devices=\
bus=0:cs=0:modalias=mcp2515:speed=375000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0X200$
bus=0:cs=1:modalias=mcp2515:speed=375000:gpioirq=24:pd=20:pds32-0=16000000:pdu32-4=0X200$
 insmod /lib/modules/3.12.22+/kernel/drivers/net/can/mcp251x.ko
ip link set can0 type can restart-ms 10
ip link set can0 up type can bitrate 125000 loopback off


ip link set can1 type can restart-ms 10
ip link set can1 up type can bitrate 125000 loopback off

ifconfig can0 txqueuelen 0
ifconfig can1 txqueuelen 0
 
The txqueuelen i set to 0 because i really want to switch the bus after each sent frame. When they are stored in an internal buffer on raspi i have no control in which order they really are sent.
Hope you have some ideas!

sbrajagopal26
Posts: 2
Joined: Wed Dec 10, 2014 12:34 pm

CAN controller

Fri Dec 12, 2014 4:38 pm

Hello all,

I am developing a prototype for adaptive cruise control using two raspberry pi's. I have tested SPI on pi and it works (checked it through loopback). Now i want to write this data to the cotroller. So, after referring to resources i found Socketcan should be used in order to interface can controller with the pi. So i request some one to explain how the communication happens like
1. After writing to spi how the can controller can take that data?
2. If socketcan be used to take data from spi , i need to know how?

Thanks
Raj

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