MCP2515 over Rpi SPI

Hello everyone,

I don’t know if anyone have any experience with it, but I just can’t get the mcp2515 to work with the Mangoh Red over the Rpi SPI port. I tried to assign multiples IRQ, but it won’t work at all.
The purpose of doing this is to have 2 CAN buses connected over SPI, instead of using the CAN IoT board that only has 1 channel.

echo -n 0,2,1,0,0,0,1,0,0,0,0,mcp2515 > /sys/devices/7c00000.hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config

echo -n 0,2,0,0,0,0,1,0,0,0,0,mcp2515 > /sys/devices/7c00000.hsic_host/usb1/1-1/1-1.1/1-1.1:1.0/channel_config

When I check can0, it’s not receiving any message.

Please, let me know if you have any suggestion.
Thank you!

I think your echo commands are incorrect. I had these notes written down for myself:

channel_id (chip select), chip-select enable, irq pin, clock phase, clock polarity, chip-select pin mode (0=open_drain, 1=push_pull), clock frequency (0=12M, 1=6M, 2=3M, ... 7=93.8K), delay mask,
                       2,                  1,      -1,           0,              0,                                                1,                                                0,          8,
                       
inter-byte-delay, pre-assert delay, post-assert delay, modalias
               0,                0,                 0,   spidev

The first field is chip select. So you will want values of 1 and 2 for your two different chips assuming that you’re using the chip select pins available on the RPi connector.

Hi @dfrey, I appreciate your input.

Can you explain what is a chip selector? What pins are you referring to? Can you point me to something on the documentation that talks about this chip selection?

I really don’t understand the Channel / Chip Select part of this for the CP2130.

Thank you,
Caio

In SPI, there is a single pair of data lines (MOSI=master-out-slave-in, MISO=master-in-slave-out). To enable a single master (in our case the CP2130) to talk to multiple slaves, the slaves must know when the master is talking to them. In SPI, this is achieved by the master driving a “chip select” to a predetermined logic level (typically low). Pins 24 and 26 of the Raspberry Pi connector on the mangOH Red correspond to chip select 1 and chip select 2 of the CP2130.

Thank you for the information.

I finally got time to work on this again and this was my progress.
When I try to initialize the can0 interface (ifconfig can0 up) I’m getting the following error logged:

[ 434.037242] spi32766.2 supply vdd not found, using dummy regulator
[ 434.037336] spi32766.2 supply xceiver not found, using dummy regulator
[ 467.034220] gpio_sync_ri: RI owner is Modem
[ 467.034245] gpiod_export: sierra–find GPIO,chipdev = -828217840,chipngpio = 80,chipbase = 0
[ 467.036069] sps:BAM 0x07884000 (va:0xd09c0000) enabled: ver:0x18, number of pipes:24
[ 467.036578] spi1.0 supply vdd not found, using dummy regulator
[ 467.036660] spi1.0 supply xceiver not found, using dummy regulator
[ 467.047547] can_spi_init: mcp2515 (gpio:9 irq:61).
[ 504.152050] mcp251x spi32766.2: failed to acquire irq -930657552
[ 522.002345] mcp251x spi32766.2: failed to acquire irq -930657552

I’m trying to use the module that was already developed for the mangOH board. It already implements the platform_data configuration. I set the interrupt pin to 9, GPIO 22.
The interrupt is not connected to the cp2130, it’s connect directly to one of the processors GPIOs, that’s why I’m using -1 for the IRQ.
I’m using CS2 for this mcp2515 chip. I’m trying to understand what’s the “cs_mode” configuration. I see it as an enable, so I set it to 1, but I see that it accepts the value 2 as well.

echo -n 2,1,-1,0,0,0,1,0,0,0,0,mcp2515 > $(find /sys -name ‘channel_config’)

Thank you,
Caio Porto

Hello @dfrey,

I’ve been working intensively on this and still couldn’t get to a solution.
I could adapt the can_iot.c to work with the CP2130 based on the WiFi SPI communication.
I got everything to load perfectly, but I’m still not receiving any CAN message. Tomorrow I’m going to connect a logic analyzer to see what the CP2130 is doing wrong, but I don’t have much knowledge of SPI to be able to troubleshoot at that level.

Here is the adapted CAN module:
can1_spi.c (3.5 KB)

I also wrote a script that loads the modules and bring the CAN interface up. You will notice that I’m creating and loading the pdata as suggested by the driver developer using the create_pdata.c located in the CP2130 module folder, but still not working.

start_can.sh (425 Bytes)

This is the output from dmesg

[ 90.686833] spi_master spi32766: can_spi_init(): find SPI device(‘spi32766.1’)
[ 90.686861] spi_master spi32766: can_spi_init(): dev(‘mcp2515’) mode(0) max speed(12000000) CS(1) bits/word(8)
[ 90.686898] gpio_sync_ri: RI owner is Modem
[ 90.686912] gpiod_export: sierra–find GPIO,chipdev = -828217840,chipngpio = 80,chipbase = 0
[ 90.687244] spi spi32766.1: can_spi_init(): mcp2515 (gpio:9 irq:61).
[ 90.687257] spi spi32766.1: can_spi_init(): ‘mcp2515’ initialized
[ 90.736726] spi32766.1 supply vdd not found, using dummy regulator
[ 90.736827] spi32766.1 supply xceiver not found, using dummy regulator
[ 96.663519] mcp251x spi32766.1: modalias:mcp2515 , irq:61 , Max Speed:6000000 , chip:1

Output from lsmod

root@swi-mdm9x28-wp:~# lsmod
Tainted: G
mcp251x 9728 0 - Live 0xbf024000 (O)
can1_spi 1190 0 - Live 0xbf020000 (O)
mt7697serial 8094 0 - Live 0xbf01a000 (O)
mt7697q 19703 0 - Live 0xbf010000 (O)
cp2130 20454 2 can1_spi,mt7697q, Live 0xbf000000 (O)

channel_config content:

root@swi-mdm9x28-wp:~# cat $(find /sys -name ‘channel_config’)
channel cs_mode irq_pin clock_phase polarity cs_pin_mode clock_freq delay_mask inter_byte_delay pre_delay post_delay mod_alias
0 2 -1 0 0 1 12 MHz 0 0 0 0 ‘mt7697’
1 2 -1 0 0 0 6 MHz 0 0 0 0 ‘mcp2515’
2 0 0 0 0 1 6 MHz 0 0 0 0 ‘(null)’
3 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
4 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
5 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
6 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
7 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
8 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
9 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’
10 0 0 0 0 0 6 MHz 0 0 0 0 ‘(null)’

Please, advise what should I test next. I have tested this MCP2515 with a Raspberry Pi and it works perfectly. The interface with CP2130 makes everything very hard.

I really need to get 2 CAN buses working on the Mangoh platform. I would appreciate if you could also point someone to help me developing this driver, if you are not available. I’m open to hire a contractor to assist on this development.

Thank you very much,
Caio Porto

Hi,

What is the link state of your can0 interface?
ip link show can0

Could you see activity on WP76 interrupt pin (msmgpio 9)?
cat /proc/interrupts

Using an oscilloscope, could you see activity on MCP2515’s CS pin when using can0 interface (e.g. with ip command)?

@Jay, thank you for the response.

I just connected the board to an oscilloscope. I tested the pins using the spidev first to make sure everything was working fine.

Then I went back to try with the mcp2515. I could see an initial count of 2 on the interrupt then I did some tests with the interrupt by manually switching from 0 to 1 to make sure the pins are correct and it is counting.

61: 26 msmgpio 9 mcp251x

I connected the oscilloscope to the Interrupt, SCK, MOSI and MISO. But cannot see any activity.
My guess is that something is wrong on my module code.

output for ip link show can0:

10: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
link/can

Any suggestion where should I look at? Any command or screen that I can share that will help on this?

Thank you very much!