Re: CAN controller
Posted: Mon Mar 23, 2015 7:37 am
I get 255/0xff running it without any arguments, and 0/0x00 with the 7 arg. This is the same with or without the CAN board and GPIO7+GPIO9 shorted.
A small, affordable computer with free resources to help people learn, make things, and have fun
https://forums.raspberrypi.com/
I just tried this on a brand new pi2 & a clean build, and the result is exactly the same.msperl wrote:I have just checked - for me MISO/MOSI are typically low, so there must be something pulling it high on your end to result in 0xff to get read - especially if that ONLY happens with CS0 (=default) but you are reading 0x00 for CS1 (=argument 7)...
Yeey. New build works. Same schematic. I must have fried something the first time.msperl wrote:Also it is important that the clock of the mcp2515 is running correctly!
Without a connected clock/crystal the mcp2515 will not respond on SPI and return 0x00 (or 0xff if you have added a pullup to MISO)...
So you may want to check that as well!
Martin
Code: Select all
Mar 28 04:34:57 raspberrypi ifplugd(can0)[1614]: Link beat lost.
Mar 28 04:35:07 raspberrypi ifplugd(can0)[1614]: Executing '/etc/ifplugd/ifplugd.action can0 down'.
Mar 28 04:35:07 raspberrypi avahi-daemon[2279]: Withdrawing workstation service for can0.
Mar 28 04:35:07 raspberrypi ifplugd(can0)[1614]: Killing child.
Mar 28 04:35:07 raspberrypi ifplugd(can0)[1614]: Program execution failed, return value is 0.
Code: Select all
root@raspberrypi:~# ip -d link show can0
3: can0: <NO-CARRIER,NOARP,UP,ECHO> mtu 16 qdisc pfifo_fast state DOWN mode DEFAULT qlen 10
link/can
can state BUS-OFF restart-ms 0
bitrate 500000 sample-point 0.875
tq 125 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
Code: Select all
mcp251x spi0.0: unable to set initial baudrate!
mcp251x spi0.0: can0: bit-timing not yet defined
Code: Select all
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
Code: Select all
/sbin/ip link set can0 up type can bitrate 500000
Code: Select all
[ 11.449421] spi_config_register: device description: bus=0:cs=0:modalias=mcp2515:speed=10000000:gpioirq=25:pd=20:pdu32-0=12000000:pdu32-4=0x2002:force_release
[ 11.466501] spi_config_match_cs: SPI0: check CS=0 to be 0
[ 11.473364] spi_config_match_cs: SPI0.0: Found a device with modinfo spidev
[ 11.481881] spi_config_register:spi0.0:mcp2515: found already registered device
[ 11.490703] spi_config_register:spi0.0:mcp2515: forcefully-releasing already registered device taints kernel
[ 11.506503] spi_config_register:spi0.0: registering modalias=mcp2515 with max_speed_hz=10000000 mode=0 and gpio/irq=25/195
[ 11.536253] spi_config_register:spi0.0:platform data:da2e3900: 00 1b b7 00 02 20 00 00 00 00 00 00 00 00 00 00 ..... ..........
[ 11.567949] spi_config_register:spi0.0:platform data:da2e3910: 00 00 00 00 ....
[ 11.596663] CAN device driver interface
[ 11.707507] mcp251x spi0.0: probed
[ 20.234327] mcp251x spi0.0 can0: bit-timing not yet defined
[ 20.234367] mcp251x spi0.0: unable to set initial baudrate!
[ 20.234773] mcp251x spi0.0 can0: bit-timing not yet defined
[ 20.234800] mcp251x spi0.0: unable to set initial baudrate!
[ 20.234852] mcp251x spi0.0 can0: bit-timing not yet defined
[ 20.234869] mcp251x spi0.0: unable to set initial baudrate!
same as the answer before - you need to configure the can-bus speed via:MrBool wrote:It looks like hardware is fine. Do I need some other device on bus?
Code: Select all
/sbin/ip link set can0 up type can bitrate 500000
Code: Select all
dtoverlay=spi-bcm2835-overlay
dtoverlay=mcp2515-can0-overlay
Code: Select all
/sbin/ip link set can0 up type can bitrate 500000
Code: Select all
git clone https://git.gitorious.org/linux-can/can-utils.git
make -C can-utils
sudo make -C can-utils install PREFIX=/usr/local
rm -rf can-utils
Code: Select all
mcp251x spi0.0: CNF: 0x03 0xb5 0x01
Code: Select all
mcp251x spi0.0: CNF: 0x01 0xb5 0x01
Code: Select all
can-calc-bit-timing -c 16000000 mcp251x
Code: Select all
Bit timing parameters for mcp251x with 16.000000 MHz ref clock
nominal real Bitrt nom real SampP
Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error CNF1 CNF2 CNF3
1000000 62 5 6 4 1 1 1000000 0.0% 75.0% 75.0% 0.0% 0x00 0xac 0x03
800000 62 7 8 4 1 1 800000 0.0% 80.0% 80.0% 0.0% 0x00 0xbe 0x03
500000 125 6 7 2 1 2 500000 0.0% 87.5% 87.5% 0.0% 0x01 0xb5 0x01
250000 250 6 7 2 1 4 250000 0.0% 87.5% 87.5% 0.0% 0x03 0xb5 0x01
125000 500 6 7 2 1 8 125000 0.0% 87.5% 87.5% 0.0% 0x07 0xb5 0x01
100000 625 6 7 2 1 10 100000 0.0% 87.5% 87.5% 0.0% 0x09 0xb5 0x01
50000 1250 6 7 2 1 20 50000 0.0% 87.5% 87.5% 0.0% 0x13 0xb5 0x01
20000 3125 6 7 2 1 50 20000 0.0% 87.5% 87.5% 0.0% 0x31 0xb5 0x01
10000 4000 8 8 8 1 64 10000 0.0% 87.5% 68.0% 22.3% 0x3f 0xbf 0x07
Code: Select all
# 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: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
# cat /proc/net/can/stats
6 transmitted frames (TXF)
0 received frames (RXF)
0 matched frames (RXMF)
0 % total match ratio (RXMR)
0 frames/s total tx rate (TXR)
0 frames/s total rx rate (RXR)
0 % current match ratio (CRXMR)
0 frames/s current tx rate (CTXR)
0 frames/s current rx rate (CRXR)
0 % max match ratio (MRXMR)
1 frames/s max tx rate (MTXR)
0 frames/s max rx rate (MRXR)
0 current receive list entries (CRCV)
0 maximum receive list entries (MRCV)
Code: Select all
# dmesg | egrep "can|spi|mcp"
[ 0.187938] bus: 'spi': registered
[ 0.187952] device class 'spi_master': registering
[ 0.189276] device: '3f204000.spi': device_add
[ 0.189307] bus: 'platform': add device 3f204000.spi
[ 0.189852] device: 'clocks:can0_osc': device_add
[ 0.189883] bus: 'platform': add device clocks:can0_osc
[ 1.679987] device class 'spidev': registering
[ 1.680031] bus: 'spi': add driver spidev
[ 1.680124] bus: 'platform': add driver spi-bcm2835
[ 1.680180] bus: 'platform': driver_probe_device: matched device 3f204000.spi with driver spi-bcm2835
[ 1.680194] bus: 'platform': really_probe: probing driver spi-bcm2835 with device 3f204000.spi
[ 1.680467] device: 'spi0': device_add
[ 1.680592] spi-bcm2835 3f204000.spi: registered master spi0
[ 1.681437] spi spi0.0: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 1.681458] device: 'spi0.0': device_add
[ 1.681498] bus: 'spi': add device spi0.0
[ 1.681594] spi-bcm2835 3f204000.spi: registered child spi0.0
[ 1.681918] spi spi0.1: setup mode 0, 8 bits/w, 500000 Hz max --> 0
[ 1.681935] device: 'spi0.1': device_add
[ 1.681972] bus: 'spi': add device spi0.1
[ 1.682063] bus: 'spi': driver_probe_device: matched device spi0.1 with driver spidev
[ 1.682078] bus: 'spi': really_probe: probing driver spidev with device spi0.1
[ 1.682106] spidev spi0.1: no default pinctrl state
[ 1.682162] device: 'spidev0.1': device_add
[ 1.682384] driver: 'spidev': driver_bound: bound to device 'spi0.1'
[ 1.682403] bus: 'spi': really_probe: bound device spi0.1 to driver spidev
[ 1.682424] spi-bcm2835 3f204000.spi: registered child spi0.1
[ 1.682439] driver: 'spi-bcm2835': driver_bound: bound to device '3f204000.spi'
[ 1.682454] bus: 'platform': really_probe: bound device 3f204000.spi to driver spi-bcm2835
[ 1.682583] bus: 'platform': add driver bcm2708_spi
[ 1.682692] bus: 'platform': remove driver bcm2708_spi
[ 1.682729] driver: 'bcm2708_spi': driver_release
[ 1.682779] vcan: Virtual CAN interface driver
[ 1.694500] bus: 'spi': add driver mcp251x
[ 1.694544] bus: 'spi': driver_probe_device: matched device spi0.0 with driver mcp251x
[ 1.694558] bus: 'spi': really_probe: probing driver mcp251x with device spi0.0
[ 1.694703] mcp251x spi0.0: setup mode 0, 8 bits/w, 10000000 Hz max --> 0
[ 1.704928] mcp251x spi0.0: CANCTRL 0x87
[ 1.705031] device: 'can0': device_add
[ 1.705862] driver: 'mcp251x': driver_bound: bound to device 'spi0.0'
[ 1.705881] bus: 'spi': really_probe: bound device spi0.0 to driver mcp251x
[ 2.479885] can: controller area network core (rev 20120528 abi 9)
[ 2.494504] can: raw protocol (rev 20120528)
[ 2.525054] can: broadcast manager protocol (rev 20120528 t)
[ 2.525090] can: netlink gateway (rev 20130117) max_hops=1
[ 103.234965] mcp251x spi0.0: CNF: 0x01 0xb5 0x01
Code: Select all
# cat /proc/interrupts
CPU0 CPU1 CPU2 CPU3
16: 0 0 0 0 ARMCTRL 16 bcm2708_fb dma
32: 397170 0 0 0 ARMCTRL 32 dwc_otg, dwc_otg_pcd, dwc_otg_hcd:usb1
49: 0 0 0 0 ARMCTRL 49 3f200000.gpio:bank0
50: 0 0 0 0 ARMCTRL 50 3f200000.gpio:bank1
65: 11 0 0 0 ARMCTRL 65 ARM Mailbox IRQ
66: 2 0 0 0 ARMCTRL 66 VCHIQ doorbell
75: 1 0 0 0 ARMCTRL 75
80: 38 0 0 0 ARMCTRL 80 3f204000.spi
84: 1024553 0 0 0 ARMCTRL 84 mmc0
99: 9020 9607 4135 379 ARMCTRL 99 arch_timer
473: 0 0 0 0 pinctrl-bcm2835 25 mcp251x
FIQ: usb_fiq
IPI0: 0 0 0 0 CPU wakeup interrupts
IPI1: 0 0 0 0 Timer broadcast interrupts
IPI2: 3046 1848 2870 461 Rescheduling interrupts
IPI3: 2 2 4 3 Function call interrupts
IPI4: 1 1 0 0 Single function call interrupts
IPI5: 0 0 0 0 CPU stop interrupts
IPI6: 0 0 0 0 IRQ work interrupts
IPI7: 0 0 0 0 completion interrupts
Err: 0
Code: Select all
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
My long message got lost due to timeouts.nikkotorcita wrote:Hi msperl!
I've been following your development of an improved SPI driver with DMA for the Pi as well as your mcp2515a driver and it's been very helpful! I'm developing a sensor system that has at least 8 CAN nodes that need to run at full 1mbit/s speed. There is a case where I need to broadcast >5M of data to all of the nodes but I'm encountering a problem where the transmission stalls (I'm using the 3.11.2+ kernel btw) and I'm assuming this is due to the interrupt issue you mentioned in the previous posts. So my questions are:
1. What's the difference between your latest 2515a from https://github.com/msperl/mcp2515a and the mcp251x in the foundation kernel?
2. Which one would you recommend for use in my case? And if ever it's your mcp2515a, which kernel branch should I apply your spi-optimize.patch to?
Thanks so much for all the hardware on RPi's SPI and the CAN driver!
Cheers