# MCP2515 over Rpi SPI

**URL:** https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897
**Category:** mangOH Red
**Created:** [September 7, 2019, 3:46am UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897 "2019-09-07T03:46:46Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![caioporto](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/caioporto/32/1099_2.png) [@caioporto](https://mangoh.discourse.group/u/caioporto)
#### Post date: [September 7, 2019, 3:46am UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/1 "2019-09-07T03:46:46Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)
#### Post date: [September 18, 2019, 5:38pm UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/2 "2019-09-18T17:38:57Z")

</div>

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

```nohighlight
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.

---

<div class="post-metadata">

### Author: ![caioporto](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/caioporto/32/1099_2.png) [@caioporto](https://mangoh.discourse.group/u/caioporto)
#### Post date: [September 18, 2019, 10:06pm UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/3 "2019-09-18T22:06:08Z")

</div>

> [@dfrey](#):
>
> The first field is chip select.

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

---

<div class="post-metadata">

### Author: ![dfrey](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/dfrey/32/303_2.png) [@dfrey](https://mangoh.discourse.group/u/dfrey)
#### Post date: [September 18, 2019, 10:11pm UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/4 "2019-09-18T22:11:26Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![caioporto](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/caioporto/32/1099_2.png) [@caioporto](https://mangoh.discourse.group/u/caioporto)
#### Post date: [October 1, 2019, 12:09am UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/5 "2019-10-01T00:09:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![caioporto](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/caioporto/32/1099_2.png) [@caioporto](https://mangoh.discourse.group/u/caioporto)
#### Post date: [November 13, 2019, 4:04am UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/6 "2019-11-13T04:04:09Z")

</div>

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](https://mangoh.discourse.group/uploads/short-url/pgXn7iTJdN60MpZAIQrJ1vJZGGy.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](https://mangoh.discourse.group/uploads/short-url/wv9MYQ8isEkYpSJkmnwjWNK3Hcm.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

---

<div class="post-metadata">

### Author: ![Jay](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/jay/32/46_2.png) [@Jay](https://mangoh.discourse.group/u/Jay)
#### Post date: [November 19, 2019, 4:51pm UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/7 "2019-11-19T16:51:37Z")

</div>

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)?

---

<div class="post-metadata">

### Author: ![caioporto](https://sea2.discourse-cdn.com/flex016/user_avatar/mangoh.discourse.group/caioporto/32/1099_2.png) [@caioporto](https://mangoh.discourse.group/u/caioporto)
#### Post date: [November 27, 2019, 12:36am UTC](https://mangoh.discourse.group/t/mcp2515-over-rpi-spi/2897/8 "2019-11-27T00:36:05Z")

</div>

@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!
