freto
Posts: 1
Joined: Thu Nov 02, 2017 2:28 pm

Raspberry Pi 2 with Pi 2 Click Shield and 2 MCP2515

Thu Nov 02, 2017 2:41 pm

Hello.

I searched here and other place in Web but i can't find a solution to my problem.
I use a Raspberry Pi 2 with a Pi 2 Click Shield from MikroE : https://shop.mikroe.com/pi-2-click-shield
I plugged 2 CAN SPI Click from MikroE too : https://shop.mikroe.com/can-spi-33v-click

I managed to work with first CAN SPI (with spi0.0, sending and receiving frame works fine), but not with the second (spi0.1).

Below are some informations i can provide :

Code: Select all

[email protected]:/home/pi# uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux
The dmesg results :

Code: Select all

[email protected]:/home/pi# dmesg | grep mcp
[   26.338590] mcp251x spi0.0 can0: MCP2515 successfully initialized.
[   26.349407] mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?
[   26.349448] mcp251x spi0.1: Probe failed, err=19
[   26.507801] mcp251x spi0.0 can0: bit-timing not yet defined
[   26.507824] mcp251x spi0.0: unable to set initial baudrate!
The vcdbg results :

Code: Select all

[email protected]:/home/pi# vcdbg log msg
001177.846: brfs: File read: /mfs/sd/config.txt
001178.780: brfs: File read: 1771 bytes
001187.551: HDMI:EDID error reading EDID block 0 attempt 0
001188.814: HDMI:EDID error reading EDID block 0 attempt 1
001190.072: HDMI:EDID error reading EDID block 0 attempt 2
001191.331: HDMI:EDID error reading EDID block 0 attempt 3
001192.589: HDMI:EDID error reading EDID block 0 attempt 4
001193.848: HDMI:EDID error reading EDID block 0 attempt 5
001195.106: HDMI:EDID error reading EDID block 0 attempt 6
001196.364: HDMI:EDID error reading EDID block 0 attempt 7
001197.622: HDMI:EDID error reading EDID block 0 attempt 8
001198.881: HDMI:EDID error reading EDID block 0 attempt 9
001199.902: HDMI:EDID giving up on reading EDID block 0
001213.351: brfs: File read: /mfs/sd/config.txt
001214.155: HDMI:Setting property pixel encoding to Default
001214.173: HDMI:Setting property pixel clock type to PAL
001214.193: HDMI:Setting property content type flag to No data
001214.210: HDMI:Setting property fuzzy format match to enabled
001222.849: gpioman: gpioman_get_pin_num: pin WL_LPO_CLK not defined
001222.875: gpioman: gpioman_get_pin_num: pin BT_ON not defined
001222.896: gpioman: gpioman_get_pin_num: pin WL_ON not defined
001403.438: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
001403.466: hdmi: HDMI:>>>>>>>>>>>>>Rx sensed, reading EDID<<<<<<<<<<<<<
001403.772: hdmi: HDMI:EDID error reading EDID block 0 attempt 0
001405.038: hdmi: HDMI:EDID error reading EDID block 0 attempt 1
001406.301: hdmi: HDMI:EDID error reading EDID block 0 attempt 2
001407.563: hdmi: HDMI:EDID error reading EDID block 0 attempt 3
001408.825: hdmi: HDMI:EDID error reading EDID block 0 attempt 4
001410.087: hdmi: HDMI:EDID error reading EDID block 0 attempt 5
001411.349: hdmi: HDMI:EDID error reading EDID block 0 attempt 6
001412.611: hdmi: HDMI:EDID error reading EDID block 0 attempt 7
001413.873: hdmi: HDMI:EDID error reading EDID block 0 attempt 8
001415.136: hdmi: HDMI:EDID error reading EDID block 0 attempt 9
001416.162: hdmi: HDMI:EDID giving up on reading EDID block 0
001416.194: hdmi: HDMI: No lookup table for resolution group 0
001416.213: hdmi: HDMI: hotplug attached with DVI support
001416.245: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
001416.538: hdmi: HDMI:EDID error reading EDID block 0 attempt 0
001417.802: hdmi: HDMI:EDID error reading EDID block 0 attempt 1
001419.065: hdmi: HDMI:EDID error reading EDID block 0 attempt 2
001420.328: hdmi: HDMI:EDID error reading EDID block 0 attempt 3
001421.591: hdmi: HDMI:EDID error reading EDID block 0 attempt 4
001422.854: hdmi: HDMI:EDID error reading EDID block 0 attempt 5
001424.118: hdmi: HDMI:EDID error reading EDID block 0 attempt 6
001425.381: hdmi: HDMI:EDID error reading EDID block 0 attempt 7
001426.644: hdmi: HDMI:EDID error reading EDID block 0 attempt 8
001427.907: hdmi: HDMI:EDID error reading EDID block 0 attempt 9
001428.934: hdmi: HDMI:EDID giving up on reading EDID block 0
001428.971: hdmi: HDMI: hotplug deassert
001428.985: hdmi: HDMI: HDMI is currently off
001428.999: hdmi: HDMI: changing mode to unplugged
001429.022: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
001429.753: *** Restart logging
001429.779: brfs: File read: 1771 bytes
001431.269: brfs: File read: /mfs/sd/cmdline.txt
001431.347: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
001431.620: brfs: File read: 181 bytes
001706.466: brfs: File read: /mfs/sd/kernel7.img
001706.489: Loading 'kernel7.img' to 0x8000 size 0x45dfb0
001710.115: No kernel trailer - assuming DT-capable
001710.144: brfs: File read: 4579248 bytes
001714.383: brfs: File read: /mfs/sd/bcm2709-rpi-2-b.dtb
001714.406: Loading 'bcm2709-rpi-2-b.dtb' to 0x465fb0 size 0x408b
001828.282: brfs: File read: 16523 bytes
001830.460: brfs: File read: /mfs/sd/config.txt
001830.955: dtparam: spi=on
001838.138: brfs: File read: 1771 bytes
001846.822: brfs: File read: /mfs/sd/overlays/mcp2515-can1.dtbo
001857.485: Loaded overlay 'mcp2515-can1'
001857.505: dtparam: oscillator=16000000
001858.282: dtparam: interrupt=26
001859.644: dtparam: spimaxfrequency=500000
001909.947: brfs: File read: 1833 bytes
001918.581: brfs: File read: /mfs/sd/overlays/mcp2515-can0.dtbo
001929.530: Loaded overlay 'mcp2515-can0'
001929.548: dtparam: oscillator=16000000
001930.334: dtparam: interrupt=6
001931.708: dtparam: spimaxfrequency=500000
001983.187: brfs: File read: 1833 bytes
001996.812: brfs: File read: /mfs/sd/overlays/w1-gpio.dtbo
002003.512: Loaded overlay 'w1-gpio'
002974.616: Device tree loaded to 0x2effb700 (size 0x48d0)
002976.202: gpioman: gpioman_get_pin_num: pin SDCARD_CONTROL_POWER not defined
004284.082: vchiq_core: vchiq_init_state: slot_zero = 0xfa980000, is_master = 1
004288.245: hdmi: HDMI:hdmi_get_state is deprecated, use hdmi_get_display_state instead
And the config.txt file (not entire, just concerned lines):

Code: Select all

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README
dtoverlay=mcp2515-can1,oscillator=16000000,interrupt=26,spimaxfrequency=500000
dtoverlay=mcp2515-can0,oscillator=16000000,interrupt=6,spimaxfrequency=500000

# Enable audio (added by raspberrypi-sys-mods)
#dtparam=audio=on
start_x=0
enable_uart=1
I tried to delete the spimaxfrequency, to disable uart with spi-config, to change also the interrupt pin, without success.
With this error, when i try to "ip link", that's the result :

Code: Select all

[email protected]:/home/pi# ip link set can1 up type can bitrate 500000
Cannot find device "can1"
I tried also the lines : dtoverlay=spi-bcm-2835-overlay, or dtoverlay=spi-bcm-2708 in config.txt but without effects too.

Can someone help me? Or does someone managed to work with a similar configuration?

PS: sorry for my english ;)

TrHawk
Posts: 1
Joined: Thu May 09, 2019 7:00 pm

Re: Raspberry Pi 2 with Pi 2 Click Shield and 2 MCP2515

Thu May 09, 2019 7:54 pm

Hi!

Though this question is already a little bit older, I stumbled across it, as I had nearly the same setup and problem.

I'm using a Raspberry Pi 3B+, a Pi2 Click Shield, and two CAN SPI click 3V3 modules.

On the oscillators package on CAN SPI click modules I can read "10.000", so I'd guess these boards are using 10MHz oscillators,
which I verified e.g. at https://download.mikroe.com/documents/a ... l-v100.pdf. And I figured out CS0 and CS1 and the connected GPIO interrupt lines in https://download.mikroe.com/documents/a ... c-v100.pdf.

So I added to my /boot/config.txt the following snipped:

Code: Select all

dtparam=spi=on
dtoverlay=mcp2515-can0,oscillator=10000000,interrupt=6,spimaxfrequency=500000
dtoverlay=mcp2515-can1,oscillator=10000000,interrupt=26,spimaxfrequency=500000
After rebooting I also got:

Code: Select all

[  575.065139] mcp251x spi0.0 can0: MCP2515 successfully initialized.
[  579.344116] mcp251x spi0.1: Cannot initialize MCP2515. Wrong wiring?
[  579.344134] mcp251x spi0.1: Probe failed, err=19
This can be repeated by reloading the MCP2515 driver

Code: Select all

[email protected]:~ $ sudo rmmod mcp251x
[email protected]:~ $ sudo modprobe mcp251x
I compared the connections of the click modules in the Pi2 Click Shield schematic (from the link above).

I've checked the GPIO settings with

Code: Select all

[email protected]:~ $ gpio readall
 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | OUT  | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | OUT  | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 1 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3B+-+---+------+---------+-----+-----+
Then I used an oscilloscope to check for signal levels and I found the wrong RST# low level on the second mbus slot of the PI2 Click Shield. It's BCM GPIO19 and it's pulled up via 100K to VCC. So it's a little bit strange, that a GPIO input pin is able to pull this signal low. I measured 1V2, which seems to be low enough to keep the MCP2515 in reset.

So I've set GPIO19 to high level to force the MCP2515 in the second mbus slot out of reset:

Code: Select all

[email protected]:~ $ gpio export 19 out
[email protected]:~ $ gpio -g write 19 1
Verified the level with the scope and "gpio readall" and reloaded the MCP2515 driver:

Code: Select all

[ 1241.630447] mcp251x spi0.1 can0: MCP2515 successfully initialized.
[ 1241.641502] mcp251x spi0.0 can1: MCP2515 successfully initialized.
Setup the can interfaces:

Code: Select all

[email protected]:~ $ sudo /sbin/ip link set can0 up type can bitrate 500000
[email protected]:~ $ sudo /sbin/ip link set can1 up type can bitrate 500000
Connected both CAN-H pads with one wire and both CAN-L pads with another, having the termination jumpers on the CAN SPI click boards in place, then I can issue a "candump can1" on one console and on another

Code: Select all

cansend can0 001#1122334455667788
to finally get my first CAN bus up and running on the Raspberry Pi 3B+:

Code: Select all

[email protected]:~ $  candump can1
  can1  001   [8]  11 22 33 44 55 66 77 88
Now I only need to find out, why GPIO19 is pulled low while being in input mode, compared to GPIO5, being the first mbus slot RST pin.

HTH
Hawk

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