3.10.36+
github.com/tz1/pikernomatic has been updated to the latest rpi-update kernel binary.
Attached are the can specific modules built with pikernomatic.
Attached are the can specific modules built with pikernomatic.
- Attachments
-
- canmods-36+.tgz
- can modules 3.10.36+
- (59.14 KiB) Downloaded 440 times
Re: CAN controller
Hi Fabian!
(http://lxr.free-electrons.com/source/Do ... n.txt#L908)
True - mcp2515 is a bit different, but (with the correctly optimized drivers) it is still able to handle a fully loaded BUS with 8byte extended messages...
Martin
Here a quote from: Documentation/networking/can.txt line 908.Webo wrote:So, do there exist solutions to support the hardware filtering? Or does this require an own implementation/modification![]()
(http://lxr.free-electrons.com/source/Do ... n.txt#L908)
Code: Select all
... The high efficient filter sets inside the PF_CAN core allow
to set different multiple filters for each socket separately.
Therefore the use of hardware filters goes to the category 'handmade
tuning on deep embedded systems'. The author is running a MPC603e
@133MHz with four SJA1000 CAN controllers from 2002 under heavy bus
load without any problems ...
Martin
Re: 3.10.36+
Hi, thanks for updating the moduels!
I have two basic questions though, regarding how to use the CAN module:
1. is it enough to load all the attached can-specific modules to get the sparfun PICAN board working?
2. is there a reference to how i can use a simple c program for sending/receiving CAN messages? instead of using cmdline executables (candump, cansend, etc.) ?
Thanks!!
I have two basic questions though, regarding how to use the CAN module:
1. is it enough to load all the attached can-specific modules to get the sparfun PICAN board working?
2. is there a reference to how i can use a simple c program for sending/receiving CAN messages? instead of using cmdline executables (candump, cansend, etc.) ?
Thanks!!
tz1 wrote:github.com/tz1/pikernomatic has been updated to the latest rpi-update kernel binary.
Attached are the can specific modules built with pikernomatic.
Re: CAN controller
ad 2): Sending receiving messages:
http://en.wikipedia.org/wiki/SocketCAN
and also the definite documentation directly from the kernel:
http://lxr.free-electrons.com/source/Do ... ng/can.txt
http://en.wikipedia.org/wiki/SocketCAN
and also the definite documentation directly from the kernel:
http://lxr.free-electrons.com/source/Do ... ng/can.txt
Re: CAN controller
Thanks a lot! I'll try it out!!
regarding the 1st question, any idea?
regarding the 1st question, any idea?
msperl wrote:ad 2): Sending receiving messages:
http://en.wikipedia.org/wiki/SocketCAN
and also the definite documentation directly from the kernel:
http://lxr.free-electrons.com/source/Do ... ng/can.txt
Re: CAN controller
For all those of you who have issues with the MCP2515.
If you have issues with the mcp2515 driver (the interface comes up, but does not work), then please try to load the stock mcp251x driver instead and try to bring that one up.
This original driver does not blindly assume that the mcp2515 is connected - it also reads some info back from the mcp2515 and verifies that the chip has been set up correctly...
It has other issues with stalling because of missed interrupts, but at least it works better on setup and does sanity testing at that time.
The other driver you could use is the mcp2515a driver, that I have written with more focus on optimizations and with least ammount of CPU resources when using the new spi-bcm2835dma driver (but I have not tested it yet against a 3.10 kernel).
You can find it here: https://github.com/msperl/mcp2515a
Both drivers together (plus a patch) allows me to read 3300 CAN messages per second and I only loose 20% of CPU resources - not like 60% like with the stock driver pair... (the spi-bcm2835dma driver currently only compiles against 3.13 and only seems to work reliably with the mcp2515 and mcp2515a drivers - nothing else has been tested)
Also this driver currently produces a seg-fault when using the "default" spi-bcm2708 driver, but as it works with the other versions I would guess it is related to the spi-bcm2708 driver - need to investigate...
Anyway: use the mcp251x driver to do your initial connection testing!
Martin
Still
If you have issues with the mcp2515 driver (the interface comes up, but does not work), then please try to load the stock mcp251x driver instead and try to bring that one up.
This original driver does not blindly assume that the mcp2515 is connected - it also reads some info back from the mcp2515 and verifies that the chip has been set up correctly...
It has other issues with stalling because of missed interrupts, but at least it works better on setup and does sanity testing at that time.
The other driver you could use is the mcp2515a driver, that I have written with more focus on optimizations and with least ammount of CPU resources when using the new spi-bcm2835dma driver (but I have not tested it yet against a 3.10 kernel).
You can find it here: https://github.com/msperl/mcp2515a
Both drivers together (plus a patch) allows me to read 3300 CAN messages per second and I only loose 20% of CPU resources - not like 60% like with the stock driver pair... (the spi-bcm2835dma driver currently only compiles against 3.13 and only seems to work reliably with the mcp2515 and mcp2515a drivers - nothing else has been tested)
Also this driver currently produces a seg-fault when using the "default" spi-bcm2708 driver, but as it works with the other versions I would guess it is related to the spi-bcm2708 driver - need to investigate...
Anyway: use the mcp251x driver to do your initial connection testing!
Martin
Still
Re: CAN controller
Fixed the issue with the spi-bcmdma driver - the "original" module also works now...
Still I found ways to Improve the mcp2515a driver - there is quite some overhead switching from write to read with _any_ spi_bus driver, so to shorten the "delays" I need to switch to concurrent read+write operations and just ignore the other part myself...
In the end this even reduces memory footprint, as then there is no separate spi_transfer structure for read and writes...
For the spi-DMA-busdriver this reduces the time spent on the SPI bus by about 8us.
While for the upstream linux spi-driver using interrupts and Programmable IO this means a reduction of: 46us
as well as a reduction in the number of interrupts for a single interrupt for a CAN message from 12 to 9.
So that is quite remarkable on its own...
So work in progress...
Ciao, Martin
P.s: Note that the new mcp2515a driver still does not work with the spi-bcm2708 bus driver - still need to investigate where the issue is..
Still I found ways to Improve the mcp2515a driver - there is quite some overhead switching from write to read with _any_ spi_bus driver, so to shorten the "delays" I need to switch to concurrent read+write operations and just ignore the other part myself...
In the end this even reduces memory footprint, as then there is no separate spi_transfer structure for read and writes...
For the spi-DMA-busdriver this reduces the time spent on the SPI bus by about 8us.
While for the upstream linux spi-driver using interrupts and Programmable IO this means a reduction of: 46us
as well as a reduction in the number of interrupts for a single interrupt for a CAN message from 12 to 9.
So that is quite remarkable on its own...
So work in progress...
Ciao, Martin
P.s: Note that the new mcp2515a driver still does not work with the spi-bcm2708 bus driver - still need to investigate where the issue is..
Re: CAN controller
Fixed the Problem with the mcp2515a driver crashing when using it with the spi-bcm2708 driver.
reason is that the spi-bcm2708 driver does NOT check for NULL prior to calling the complete callback.
And to reduce possible interrupts the mcp2515a is not making use of complete callbacks under _all_ circumstances and subequently the spi-bcm2708 driver crashes...
Thsi has now been fixed by adding a module argument to disable the use of a dummy complete call - but it has to be added manually as:
This now seems to be the fastest and most complete driver from a performance and feature perspective.
It is also a perfect match for the spi-bcm2835dma driver.
But as mentioned it still has some potential for further optimizations...
Ciao, Martin
reason is that the spi-bcm2708 driver does NOT check for NULL prior to calling the complete callback.
And to reduce possible interrupts the mcp2515a is not making use of complete callbacks under _all_ circumstances and subequently the spi-bcm2708 driver crashes...
Thsi has now been fixed by adding a module argument to disable the use of a dummy complete call - but it has to be added manually as:
Code: Select all
modprobe mcp2515a use_dummy_complete=0
It is also a perfect match for the spi-bcm2835dma driver.
But as mentioned it still has some potential for further optimizations...
Ciao, Martin
Re: CAN controller
Hello,
first of all i want to thank Martin and Bert for their support.
All is working fine now and i'm really happy!
Thanks a lot!
Ciao
Patrick
first of all i want to thank Martin and Bert for their support.
All is working fine now and i'm really happy!
Thanks a lot!
Ciao
Patrick
Re: CAN controller
Lessons learned from supporting this case:
Note that this needs to start without spi drivers loaded!
Afterwards you need to reboot the RPI:
The script accepts one optional argument to define the GPIO pin used for ChipSelect.
You would typically only use 8(CS0) or 7(CS1).
Expected output is (the example is shown for the most common CS0=8 case):
Especially the last 2 lines with CANSTAT and CANCTRL must show the values 0x80 and 0x87...
If they show anything else then the electrical connection is not working correctly.
If you see that then load the drivers for the first tests (this assumes cs=0 (mapping to GPIO8), otherwise change to cs=1 (mapping to GPIO7) in the "modprobe spi-config" line):
the output of dmesg should look like this:
You should find especially the "probed" and "bit-timing not yet defined" lines.
If it does not show those and you find instead:
Especially if you find the "MCP251x didn't enter in conf mode after reset" and "probe failed" lines, then there is a config/electrical error (in this example I have used CS1, where there is no mcp2515 connected)
These are the basics for trouble-shooting initial SPI-setup.
Those scripts/packages shared by others are there to help you with your next steps...
The last and again tricky part comes with matching the CAN-BUS speed, where you need to configure the parameter to spi-config and the correctly to what is happening on the CAN bus - you need to match it exactly - otherwise there is no communication and you even introduce errors on the CAN BUS!
Note that for communication to work properly you need to have a communication partner on the can bus that is not in listen-only mode!
Ciao, Martin
P.s: maybe we should add a "sticky" message that shows up on the first page of this thread, which contains the latest up to date version of the howto debug/deploy... descriptions for newbies (probably requires an administrator to do that...)
- for initial testing use the shell-script below (without any SPI drivers loaded) - if you see the expected response, then the communication with the mcp2515 works fine.
- next step is testing with the mcp251x driver, as this one really verifies that the device is available before starting can0.
- the mcp2515 driver does not do any verifications that the HW really exists and assumes implicitly that the SPI-communication with the mcp2515 works.
- only when the mcp251x driver enables the CAN0 device, then switch to the mcp2515 driver. (or better - at some point the mcp2515a driver)
- do not use the MicroChip mcp2515 test-board unless you got the equipment to debug SPI yourself....
- instead get the 2 chips (mcp2515, mcp2551) plus quarz/oszillator, plus resistors and capacitors and implement the HW like it is described by Bert: http://lnxpps.de/rpie/
- from the available schematic the PiCan board is looking almost identical to what Gert's schematic looks like, so it should be OK, and the test-script script should work as expected and allow you to detect the device - THIS IS NOT TESTED BY ME!!!!
Note that this needs to start without spi drivers loaded!
Afterwards you need to reboot the RPI:
Code: Select all
#! /bin/sh
CS=8
test -z "$1" || CS=$1
SCLK=11
MOSI=10
MISO=9
#config SPI Pins and Directions
CONFIG_PINS() {
(while read gpio dir level; do
test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/export
echo $dir > /sys/class/gpio/gpio$gpio/direction
test -z "$level" || echo $level > /sys/class/gpio/gpio$gpio/value
done) <<EOF
$CS out 1
$MISO in
$MOSI out 0
$SCLK out 0
EOF
}
UNCONFIG_PINS() {
(while read gpio dir level; do
test -f /sys/class/gpio/gpio$gpio/value || echo $gpio > /sys/class/gpio/unexport
done) <<EOF
$CS
$MISO
$MOSI
$SCLK
EOF
}
CS() {
echo "$1" > /sys/class/gpio/gpio$CS/value
}
MOSI() {
echo "$1" > /sys/class/gpio/gpio$MOSI/value
}
SCLK() {
echo "$1" > /sys/class/gpio/gpio$SCLK/value
}
spi_send() {
echo "$1" \
| awk '{X=$1;for(i=128;i>=1;i/=2){B=0;if (X>=i){ B=1;X-=i;}print i,B}}' \
| while read bit v; do
MOSI $v
SCLK 1
echo -n "$bit "
cat /sys/class/gpio/gpio$MISO/value
SCLK 0
done \
| awk 'BEGIN{C=0}{if ($2){C+=$1}}END{printf "%-20s %3i 0x%02x\n","'$2'",C,C;}'
}
CONFIG_PINS
# reset mcp2515
echo "Resetting MCP2515"
CS 0
spi_send 192 RESET
CS 1
# wait some time
sleep 1
# and read the registers
echo "Reading MCP2515 config-registers"
CS 0
spi_send 3 CMD-READ
spi_send 40 REG-CNF3
spi_send 0 CNF3
spi_send 0 CNF2
spi_send 0 CNF1
spi_send 0 INTE
spi_send 0 INTF
spi_send 0 EFLG
spi_send 0 CANSTAT
spi_send 0 CANCTRL
CS 1
UNCONFIG_PINS
You would typically only use 8(CS0) or 7(CS1).
Expected output is (the example is shown for the most common CS0=8 case):
Code: Select all
root@raspberrypi:~# sh test-mcp2515.sh 8
Resetting MCP2515
RESET 192 0xc0
Read MCP2515 registers
CMD-READ 3 0x03
REG-CNF3 40 0x28
CNF3 0 0x00
CNF2 0 0x00
CNF1 0 0x00
INTE 0 0x00
INTF 0 0x00
EFLG 0 0x00
CANSTAT 128 0x80
CANCTRL 135 0x87
If they show anything else then the electrical connection is not working correctly.
If you see that then load the drivers for the first tests (this assumes cs=0 (mapping to GPIO8), otherwise change to cs=1 (mapping to GPIO7) in the "modprobe spi-config" line):
Code: Select all
dmesg -C
modprobe spi-bcm2708
modprobe spi-config devices=bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
modprobe mcp251x
dmesg
Code: Select all
[90600.903092] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[90600.903139] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[90609.232778] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
[90609.237435] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[90609.237481] spi_config_register:spi0.0:platform data:da103da0: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00 .$... ..........
[90609.237501] spi_config_register:spi0.0:platform data:da103db0: 00 00 00 00 ....
[90615.416805] CAN device driver interface
[90615.436830] mcp251x spi0.0: probed
[90615.548927] mcp251x spi0.0 can0: bit-timing not yet defined
[90615.548967] mcp251x spi0.0: unable to set initial baudrate!
If it does not show those and you find instead:
Code: Select all
[90721.827524] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[90721.827573] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[90728.508529] spi_config_register: device description: bus=0:cs=1:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=16000000:pdu32-4=0x2002:force_release
[90728.512329] spi_config_register:spi0.1: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[90728.512377] spi_config_register:spi0.1:platform data:dbbfe4c0: 00 24 f4 00 02 20 00 00 00 00 00 00 00 00 00 00 .$... ..........
[90728.512395] spi_config_register:spi0.1:platform data:dbbfe4d0: 00 00 00 00 ....
[90739.396232] CAN device driver interface
[90740.406161] mcp251x spi0.1: MCP251x didn't enter in conf mode after reset
[90740.406321] mcp251x spi0.1: probe failed
These are the basics for trouble-shooting initial SPI-setup.
Those scripts/packages shared by others are there to help you with your next steps...
The last and again tricky part comes with matching the CAN-BUS speed, where you need to configure the
Code: Select all
pdu32-0=<12000000|16000000|20000000|...>
Code: Select all
/sbin/ip link set can0 up type can bitrate <1000000|500000|250000|125000|100000|...>
Note that for communication to work properly you need to have a communication partner on the can bus that is not in listen-only mode!
Ciao, Martin
P.s: maybe we should add a "sticky" message that shows up on the first page of this thread, which contains the latest up to date version of the howto debug/deploy... descriptions for newbies (probably requires an administrator to do that...)
Re: CAN controller
Hello,
I setup the CAN-Bus after this Instruction: http://lnxpps.de/rpie/raspi-anleitung.txt
In the loopback mode all seems to work perfect, but when I disable the loopback mode and send CAN-Data with another Can Device, that runs also with 125 KB, I just get 1 Error frame:
The setup Commands:
Has anyone a Idee to solve my Problem?
Thanks a lot
I setup the CAN-Bus after this Instruction: http://lnxpps.de/rpie/raspi-anleitung.txt
In the loopback mode all seems to work perfect, but when I disable the loopback mode and send CAN-Data with another Can Device, that runs also with 125 KB, I just get 1 Error frame:
Code: Select all
pi@pi~ $ candump any,0:0,#FFFFFFFF
can0 20000004 [8] 00 10 00 00 00 00 00 00 ERRORFRAME
Code: Select all
sudo modprobe spi-config devices=\bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=22:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
sudo ip link set can0 up type can bitrate 125000
Thanks a lot
Re: CAN controller
Looks as if your clocks do not match (especially: are you sure you got a 16mhz clock connected to the mcp2515?) or you connected with the wrong polarity.
The other thing is: which driver did you use: mcp251x or mcp2515?
If you use the mcp251x, then you probably hit the interrupt issue which is why you only get 1 frame.
But at least you have confirmed that spi communication works properly, so switching drivers should not be an issue. Problem here is that you will not see error-frames...
Martin
The other thing is: which driver did you use: mcp251x or mcp2515?
If you use the mcp251x, then you probably hit the interrupt issue which is why you only get 1 frame.
But at least you have confirmed that spi communication works properly, so switching drivers should not be an issue. Problem here is that you will not see error-frames...
Martin
Re: CAN controller
When i use "candump can0" instead of "candump any,0:0,#FFFFFFFF" I get more than one Frame but I don't get the message that I send.
Send messages from the Pi doesn't work too.
Is there a difference between "candump can0" and "candumpany,0:0,#FFFFFFFF"?
Thanks for your help
Send messages from the Pi doesn't work too.
Is there a difference between "candump can0" and "candumpany,0:0,#FFFFFFFF"?
Thanks for your help
Re: CAN controller
Code: Select all
candump any,0:0,#FFFFFFFF
Code: Select all
candump can0
so you are possibly seeing an error frame...
for all the options of candump run:
Code: Select all
candump
Code: Select all
Usage: candump [options] <CAN interface>+
(use CTRL-C to terminate candump)
Options: -t <type> (timestamp: (a)bsolute/(d)elta/(z)ero/(A)bsolute w date)
-c (increment color mode level)
-i (binary output - may exceed 80 chars/line)
-a (enable additional ASCII output)
-S (swap byte order in printed CAN data[] - marked with '`' )
-s <level> (silent mode - 0: off (default) 1: animation 2: silent)
-b <can> (bridge mode - send received frames to <can>)
-B <can> (bridge mode - like '-b' with disabled loopback)
-u <usecs> (delay bridge forwarding by <usecs> microseconds)
-l (log CAN-frames into file. Sets '-s 2' by default)
-L (use log file format on stdout)
-n <count> (terminate after receiption of <count> CAN frames)
-r <size> (set socket receive buffer to <size>)
-d (monitor dropped CAN frames)
-e (dump CAN error frames in human-readable format)
Up to 16 CAN interfaces with optional filter sets can be specified
on the commandline in the form: <ifname>[,filter]*
Comma separated filters can be specified for each given CAN interface:
<can_id>:<can_mask> (matches when <received_can_id> & mask == can_id & mask)
<can_id>~<can_mask> (matches when <received_can_id> & mask != can_id & mask)
#<error_mask> (set error frame filter, see include/linux/can/error.h)
CAN IDs, masks and data content are given and expected in hexadecimal values.
When can_id and can_mask are both 8 digits, they are assumed to be 29 bit EFF.
Without any given filter all data frames are received ('0:0' default filter).
Use interface name 'any' to receive from all CAN interfaces.
Examples:
candump -c -c -ta can0,123:7FF,400:700,#000000FF can2,400~7F0 can3 can8
candump -l any,0~0,#FFFFFFFF (log only error frames but no(!) data frames)
candump -l any,0:0,#FFFFFFFF (log error frames and also all data frames)
candump vcan2,92345678:DFFFFFFF (match only for extended CAN ID 12345678)
candump vcan2,123:7FF (matches CAN ID 123 - including EFF and RTR frames)
candump vcan2,123:C00007FF (matches CAN ID 123 - only SFF and non-RTR frames)
Re: CAN controller
Hi, I'm trying to get the SKPANG PiCAN http://skpang.co.uk/catalog/pican-canbu ... -1196.htmlboard working on the rpi. After checking through all the posts here, I'm still stuck at some point. The current problem is, can0 state is STOPPED when I show:
RPi has a kernel version: 3.10.36+. I used compiled modules from tz1 directly in the raspbian, without having the kernel recompiled.
Other setup:
1. /etc/modules:
2. Blacklist:
although I don't have mcp251x module anywhere on the rpi.
3. /etc/network/interfaces:
4. ifconfig:
So, when I try in one terminal, and in another terminal, nothing happens....
In dmesg, everytime when I bring up the can0:, it shows: . But nothing else happens...
Anyone has any idea what's going wrong here? I'd really appreciate any help here!!
Code: Select all
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state STOPPED restart-ms 100
bitrate 125000 sample-point 0.875
tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 8000000
Other setup:
1. /etc/modules:
Code: Select all
$ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
i2c-bcm2708
i2c-dev
# MCP2515 configuration with /INT on GPIO25 and 16MHz clock
spi-bcm2708
can
can-dev
can-raw
can-bcm
spi-config devices=\
bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002
:force_release
mcp2515
Code: Select all
$ cat /etc/modprobe.d/raspi-blacklist.conf
# blacklist spi and i2c by default (many users don't need them)
#blacklist spi-bcm2708
blacklist i2c-bcm2708
blacklist mcp251x
3. /etc/network/interfaces:
Code: Select all
auto can0
iface can0 inet manual
pre-up /sbin/ip link set can0 type can bitrate 125000
up /sbin/ifconfig can0 up
down /sbin/ifconfig can0 down
Code: Select all
$ ifconfig
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)
Code: Select all
candump any,0:0,#FFFFFFFF
Code: Select all
cansend can0 7DF#0201050000000000
In dmesg, everytime when I bring up the can0:
Code: Select all
sudo ifconfig can0 up
Code: Select all
mcp2515 spi0.0 can0: writing CNF: 0x03 0xb5 0x01
Anyone has any idea what's going wrong here? I'd really appreciate any help here!!
Re: CAN controller
Everything that you shared indicates that:
a) the communication with the MCP2515 chip is working
b) the interface is up
My guess is that you have NOT added another device on the CAN bus.
Unless this is added your packet will not get delivered anywhere (as there isn't a single recipient to acknowledge it) and that is probably why it does not show up in candump - packet is still pending.
Please also share the output of "lsmod" to see which modules(=drivers) you have actually loaded.
Martin
a) the communication with the MCP2515 chip is working
b) the interface is up
My guess is that you have NOT added another device on the CAN bus.
Unless this is added your packet will not get delivered anywhere (as there isn't a single recipient to acknowledge it) and that is probably why it does not show up in candump - packet is still pending.
Please also share the output of "lsmod" to see which modules(=drivers) you have actually loaded.
Martin
Re: CAN controller
Thanks Martin!
You're right about me not having another device on the CAN bus. I'll have access to a CANCase in a few days. I'll post an update afterwards.
It's really great to know everything else is working correctly.
The lsmod shows:
You're right about me not having another device on the CAN bus. I'll have access to a CANCase in a few days. I'll post an update afterwards.
It's really great to know everything else is working correctly.
The lsmod shows:
Code: Select all
$ lsmod | grep 'mcp\|can\|spi\|i2c'
mcp2515 6494 0
spi_config 9367 0
can_bcm 11643 0
can_raw 6183 0
can_dev 9987 1 mcp2515
can 23714 2 can_bcm,can_raw
i2c_dev 5557 0
i2c_bcm2708 3997 0
regmap_i2c 1645 3 snd_soc_pcm512x,snd_soc_wm8804,snd_soc_core
regmap_spi 1897 3 snd_soc_pcm512x,snd_soc_wm8804,snd_soc_core
spi_bcm2708 4728 0
msperl wrote:Everything that you shared indicates that:
a) the communication with the MCP2515 chip is working
b) the interface is up
My guess is that you have NOT added another device on the CAN bus.
Unless this is added your packet will not get delivered anywhere (as there isn't a single recipient to acknowledge it) and that is probably why it does not show up in candump - packet is still pending.
Please also share the output of "lsmod" to see which modules(=drivers) you have actually loaded.
Martin
Re: CAN controller
if you load the mcp251x driver instead of the mcp2515:
Then you can add: "one-shot on" to your /sbin/ip command - this way the mcp2515 will only try to send the message once possibly also sending an error frame that it was not acknowledged...
With that you should see the message you send even without a peer.
The driver named mcp2515 does not support this, but the mcp251x does - but it is buggy in other ways, so that the recommended driver until now is still the mcp2515.
Code: Select all
rmmod mcp2515
modprobe mcp251x
With that you should see the message you send even without a peer.
The driver named mcp2515 does not support this, but the mcp251x does - but it is buggy in other ways, so that the recommended driver until now is still the mcp2515.
Re: CAN controller
Actually, I don't have this mcp251x driver anywhere on the rpi, since I used compiled mcp2515 drivers from tz1's post for 3.10.36+. Anywhere I can find mcp251x.ko for 3.10.36+, maybe?
Another thing is, I think mcp2515 also doesn't support lookback, triple-timing options, right? It's saying "Operation not supported" if I try to turn this options on.
Another thing is, I think mcp2515 also doesn't support lookback, triple-timing options, right? It's saying "Operation not supported" if I try to turn this options on.
msperl wrote:if you load the mcp251x driver instead of the mcp2515:Then you can add: "one-shot on" to your /sbin/ip command - this way the mcp2515 will only try to send the message once possibly also sending an error frame that it was not acknowledged...Code: Select all
rmmod mcp2515 modprobe mcp251x
With that you should see the message you send even without a peer.
The driver named mcp2515 does not support this, but the mcp251x does - but it is buggy in other ways, so that the recommended driver until now is still the mcp2515.
Re: CAN controller
No idea - I use my self-compiled kernel, so I do not know the package you are using is included.
But, yes - the mcp2515 driver does not support all the features:
* one-shot
* loopback
* listen-only
* triple-sampling
the mcp251x driver supports all of those (but is buggy in other ways...).
But, yes - the mcp2515 driver does not support all the features:
* one-shot
* loopback
* listen-only
* triple-sampling
the mcp251x driver supports all of those (but is buggy in other ways...).
Re: CAN controller
Hi martin, I'm hoping you could further help me with the PICAN board on rpi.
Now I've connected a CANCasexl to the PiCAN, but still, nothing happens. I don't have any CAN traffic anywhere.
As I showed before, the command to show detials of can0 is:
BTW, I've configured my CANcase to have 125K baudrate. After I try to send a can message from cancase to rpi, it shows me error in ACK, as if nothing is connected on the other side.
dmesg shows:
really don't know where the problem is...
Now I've connected a CANCasexl to the PiCAN, but still, nothing happens. I don't have any CAN traffic anywhere.
As I showed before, the command to show detials of can0 is:
Code: Select all
$ ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 1
0
link/can
can state STOPPED restart-ms 0
bitrate 125000 sample-point 0.875
tq 500 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
mcp2515: tseg1 2..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
clock 8000000
dmesg shows:
Code: Select all
$ dmesg | grep 'mcp\|can\|spi\|i2c'
[ 5.126427] bcm2708_spi bcm2708_spi.0: master is unqueued, this is deprecated
[ 5.291836] bcm2708_spi bcm2708_spi.0: SPI Controller at 0x20204000 (irq 80)
[ 13.675599] bcm2708_i2c_init_pinmode(0,0)
[ 13.683758] bcm2708_i2c_init_pinmode(0,1)
[ 13.692170] bcm2708_i2c bcm2708_i2c.0: BSC0 Controller at 0x20205000 (irq 79) (baudrate
100000)
[ 13.703920] bcm2708_i2c_init_pinmode(1,2)
[ 13.709311] bcm2708_i2c_init_pinmode(1,3)
[ 13.720134] bcm2708_i2c bcm2708_i2c.1: BSC1 Controller at 0x20804000 (irq 79) (baudrate
100000)
[ 13.880667] i2c /dev entries driver
[ 14.090734] can: controller area network core (rev 20120528 abi 9)
[ 14.266949] can: raw protocol (rev 20120528)
[ 14.343973] can: broadcast manager protocol (rev 20120528 t)
[ 14.445220] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=1
0000000:gpioirq=25:pd=20:pds32-0=16000000:pdu32-4=0x2002:force_release
[ 14.462336] spi_config_match_cs: SPI0: check CS=0 to be 0
[ 14.469274] spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[ 14.477908] spi_config_register:spi0.0:mcp2515: found already registered device
[ 14.486750] spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered
device taints kernel
[ 14.502484] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=1
0000000 mode=0 and gpio/irq=25/195
[ 14.534402] spi_config_register:spi0.0:platform data:d6bd9020: 00 24 f4 00 02 20 00 00 0
0 00 00 00 00 00 00 00 .$... ..........
[ 14.550812] spi_config_register:spi0.0:platform data:d6bd9030: 00 00 00 00
....
[ 14.845864] mcp2515 spi0.0 can0: device registered (cs=0, irq=195)
[ 22.337042] mcp2515 spi0.0 can0: writing CNF: 0x03 0xb5 0x01
msperl wrote:No idea - I use my self-compiled kernel, so I do not know the package you are using is included.
But, yes - the mcp2515 driver does not support all the features:
* one-shot
* loopback
* listen-only
* triple-sampling
the mcp251x driver supports all of those (but is buggy in other ways...).
Re: CAN controller
Cable polarity?
Re: CAN controller
the cable works fine, when I connect channel 1 to ch. 2 on cancase itself...
msperl wrote:Cable polarity?
Re: CAN controller
So... I have recompiled kernel, but
is still the same....
I wanted to test the mcp2515x module for loopback, but I forgot to enable mcp2515x module before recompile. Do you know how to install this module alone really quick? Thanks a lot!
Code: Select all
can state STOPPED
I wanted to test the mcp2515x module for loopback, but I forgot to enable mcp2515x module before recompile. Do you know how to install this module alone really quick? Thanks a lot!
msperl wrote:Cable polarity?
Re: CAN controller
okay, I managed to get the mcp251x module compiled.
Now, the situation is:
1. when I load mcp251x, and set loopback on, the can0 works fine. send and dump are both okay.
2. when I set loopback off, the can state is:
and if I try to send a can message, it becomes ERROR-PASSIVE....
3. when I "rmmod" mcp251x, and modprobe mcp2515 again, the can state is STOPPED again...
Does anyone have any clue to this...
Now, the situation is:
1. when I load mcp251x, and set loopback on, the can0 works fine. send and dump are both okay.
2. when I set loopback off, the can state is:
Code: Select all
can state ERROR-ACTIVE restart-ms 100
Code: Select all
ip -s -d link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT qlen 10
link/can
can state ERROR-PASSIVE restart-ms 100
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 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
Does anyone have any clue to this...
mikexu wrote:So... I have recompiled kernel, butis still the same....Code: Select all
can state STOPPED
I wanted to test the mcp2515x module for loopback, but I forgot to enable mcp2515x module before recompile. Do you know how to install this module alone really quick? Thanks a lot!
msperl wrote:Cable polarity?