dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 8:48 am

I've just transferred my project from my Pi2 to the Zero, it is connected the same way and used the same SD card. My SPI device won't work and running the spi test https://raw.githubusercontent.com/raspb ... dev_test.c Returns all zeros. Does anybody know what is going on?
I tried:

Code: Select all

root@DietPi:~# gpio load spi
and got this:

Code: Select all

gpio: Unable to load/unload modules as this Pi has the device tree enabled.
  You need to run the raspi-config program (as root) and select the
  modules (SPI or I2C) that you wish to load/unload there and reboot.
  There is more information here:
      https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314
I used

Code: Select all

 raspi-config
to disable device tree and enable SPI but I still get the same error after rebooting.

Further output that may help solve the issue:

Code: Select all

root@DietPi:~# lsmod
Module                  Size  Used by
ctr                     4001  1 
ccm                     8278  1 
i2c_dev                 6730  0 
snd_bcm2835            22317  0 
snd_pcm                92581  1 snd_bcm2835
snd_timer              23454  1 snd_pcm
snd                    68161  3 snd_bcm2835,snd_timer,snd_pcm
arc4                    1972  2 
rt2800usb              18832  0 
rt2800lib              81962  1 rt2800usb
rt2x00usb              11918  1 rt2800usb
rt2x00lib              47910  3 rt2x00usb,rt2800lib,rt2800usb
mac80211              622304  3 rt2x00lib,rt2x00usb,rt2800lib
cfg80211              499834  2 mac80211,rt2x00lib
crc_ccitt               1620  1 rt2800lib
rfkill                 22491  2 cfg80211
i2c_bcm2708             6252  0 
bcm2835_gpiomem         3703  0 
uio_pdrv_genirq         3690  0 
uio                    10002  1 uio_pdrv_genirq

Code: Select all

root@DietPi:/dev# ls
autofs		 kmsg		   network_latency     ram6	tty11  tty28  tty44  tty60	vcs2
block		 loop0		   network_throughput  ram7	tty12  tty29  tty45  tty61	vcs3
btrfs-control	 loop1		   null		       ram8	tty13  tty3   tty46  tty62	vcs4
bus		 loop2		   ppp		       ram9	tty14  tty30  tty47  tty63	vcs5
cachefiles	 loop3		   ptmx		       random	tty15  tty31  tty48  tty7	vcs6
char		 loop4		   pts		       raw	tty16  tty32  tty49  tty8	vcsa
console		 loop5		   ram0		       rfkill	tty17  tty33  tty5   tty9	vcsa1
cpu_dma_latency  loop6		   ram1		       root	tty18  tty34  tty50  ttyAMA0	vcsa2
cuse		 loop7		   ram10	       shm	tty19  tty35  tty51  ttyprintk	vcsa3
disk		 loop-control	   ram11	       snd	tty2   tty36  tty52  uhid	vcsa4
fb0		 MAKEDEV	   ram12	       sndstat	tty20  tty37  tty53  uinput	vcsa5
fd		 mapper		   ram13	       stderr	tty21  tty38  tty54  urandom	vcsa6
full		 mem		   ram14	       stdin	tty22  tty39  tty55  vc-cma	vhci
fuse		 memory_bandwidth  ram15	       stdout	tty23  tty4   tty56  vchiq	zero
gpiomem		 mmcblk0	   ram2		       tty	tty24  tty40  tty57  vcio
hwrng		 mmcblk0p1	   ram3		       tty0	tty25  tty41  tty58  vc-mem
i2c-1		 mmcblk0p2	   ram4		       tty1	tty26  tty42  tty59  vcs
input		 net		   ram5		       tty10	tty27  tty43  tty6   vcs1

Code: Select all

root@DietPi:~# cat /etc/modprobe.d/raspi-blacklist.conf
root@DietPi:~# 
raspi-blacklist.conf doesn't exist

Any help would be greatly appreciated!
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 10:18 am

Add the following line to /boot/config.txt

dtparam=spi=on

Reboot.

Then ls /dev/sp* and lsmod.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 10:21 am

joan wrote:Add the following line to /boot/config.txt

dtparam=spi=on

Reboot.

Then ls /dev/sp* and lsmod.

Code: Select all

root@DietPi:~# ls /dev/sp*
/dev/spidev0.0	/dev/spidev0.1
root@DietPi:~#  lsmod
Module                  Size  Used by
ctr                     4001  1 
ccm                     8278  1 
i2c_dev                 6730  0 
snd_bcm2835            22317  0 
snd_pcm                92581  1 snd_bcm2835
snd_timer              23454  1 snd_pcm
snd                    68161  3 snd_bcm2835,snd_timer,snd_pcm
arc4                    1972  2 
rt2800usb              18832  0 
rt2800lib              81962  1 rt2800usb
rt2x00usb              11918  1 rt2800usb
rt2x00lib              47910  3 rt2x00usb,rt2800lib,rt2800usb
mac80211              622304  3 rt2x00lib,rt2x00usb,rt2800lib
cfg80211              499834  2 mac80211,rt2x00lib
crc_ccitt               1620  1 rt2800lib
rfkill                 22491  2 cfg80211
i2c_bcm2708             6252  0 
bcm2835_gpiomem         3703  0 
spi_bcm2835             7948  0 
uio_pdrv_genirq         3690  0 
uio                    10002  1 uio_pdrv_genirq
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 10:25 am

So it is working.

You are using the improved SPI module (spi_bcm2835) but that makes no difference from userland.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 10:29 am

The SPI test from https://www.raspberrypi.org/documentati ... leshooting still returns all Zeros and the SPI device gives me an error when I try to use it. Still not working.
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 10:43 am

dmaho wrote:The SPI test from https://www.raspberrypi.org/documentati ... leshooting still returns all Zeros and the SPI device gives me an error when I try to use it. Still not working.
What error? Cut&paste please.

User avatar
DougieLawson
Posts: 42155
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 11:21 am

dmaho wrote:The SPI test from https://www.raspberrypi.org/documentati ... leshooting still returns all Zeros and the SPI device gives me an error when I try to use it. Still not working.
Have you got MISO, MOSI switched to your SPI device? Are you using the right CE/CS pin?

I've got SPI on my Zero driving a MAX2719 with an eight digit/seven segment display.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14480
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Wed Dec 30, 2015 11:54 am

To answer your original question, no SPI is exactly the same, as the SOC`s used are the same!

in theory there could have been a layout error in the PCB, but the chance for that to happen is nil, and as dougie is reporting it is working, so the layout is OK.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 12:28 am

joan wrote:
dmaho wrote:The SPI test from https://www.raspberrypi.org/documentati ... leshooting still returns all Zeros and the SPI device gives me an error when I try to use it. Still not working.
What error? Cut&paste please.
This is the error:

Code: Select all

root@DietPi:~/pySX127x# ls
LICENSE  lora_util.py  README.md  rx_cont.py  SX127x  test_lora.py  tx_beacon.py  VERSION
root@DietPi:~/pySX127x# ./test_lora.py 
Traceback (most recent call last):
  File "./test_lora.py", line 130, in <module>
    lora = LoRa(verbose=False)
  File "/root/pySX127x/SX127x/LoRa.py", line 92, in __init__
    self.rx_chain_calibration(968.)
  File "/root/pySX127x/SX127x/LoRa.py", line 835, in rx_chain_calibration
    self.set_freq(freq_bkup)
  File "/root/pySX127x/SX127x/LoRa.py", line 271, in set_freq
    assert self.mode == MODE.SLEEP or self.mode == MODE.STDBY or self.mode == MODE.FSK_STDBY
AssertionError
root@DietPi:~/pySX127x# 
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 12:37 am

DougieLawson wrote:
dmaho wrote:The SPI test from https://www.raspberrypi.org/documentati ... leshooting still returns all Zeros and the SPI device gives me an error when I try to use it. Still not working.
Have you got MISO, MOSI switched to your SPI device? Are you using the right CE/CS pin?

I've got SPI on my Zero driving a MAX2719 with an eight digit/seven segment display.
Glad to hear that it's working for someone, I tried switching the MISO and MOSI and tried using different CE pin but still no luck.
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
DougieLawson
Posts: 42155
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 1:30 am

What's the SPI device you're trying to use?
Have you enabled SPI in sudo raspi-config and rebooted?

Do the two SPI devices show up?

Code: Select all

root@falcon ~ # ls -la /dev/spi*
crw-rw---- 1 root spi 153, 0 Dec 29 11:34 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Dec 29 11:34 /dev/spidev0.1
root@falcon ~ #
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 2:30 am

DougieLawson wrote:What's the SPI device you're trying to use?
Have you enabled SPI in sudo raspi-config and rebooted?

Do the two SPI devices show up?

Code: Select all

root@falcon ~ # ls -la /dev/spi*
crw-rw---- 1 root spi 153, 0 Dec 29 11:34 /dev/spidev0.0
crw-rw---- 1 root spi 153, 1 Dec 29 11:34 /dev/spidev0.1
root@falcon ~ #
Yeah its enabled:

Code: Select all

root@DietPi:~/pySX127x# ls -la /dev/spi*
crw------- 1 root root 153, 0 Jan  1  1970 /dev/spidev0.0
crw------- 1 root root 153, 1 Jan  1  1970 /dev/spidev0.1
root@DietPi:~/pySX127x# 
I also swapped out the module for a brand new one and put the old module in my Pi2, both modules work in the Pi2 but still not working with the Zero.
I thought maybe the Zero can't supply enough power so I used an external power for the module and still not working.
This is so strange, I've tried almost everything now!
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 2:35 am

Hey wait yours says:
crw-rw---- 1 root spi 153, 0 Dec 29 11:34 /dev/spidev0.0
And mine is:
crw------- 1 root root 153, 0 Jan 1 1970 /dev/spidev0.0

Could it be a permissions problem?
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 6:21 am

Yes, Yours has the wrong permissions set.

I don't know if that is a Raspbian fault or (more likely) a Raspberrpy Pi org fault. The permissions have been wrong on /dev/gpiomem as well recentlly.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 6:40 am

joan wrote:Yes, Yours has the wrong permissions set.

I don't know if that is a Raspbian fault or (more likely) a Raspberrpy Pi org fault. The permissions have been wrong on /dev/gpiomem as well recentlly.
Just did a chmod 755 on both /dev/gpiomem and /dev/spidev0.0 Still not working. I'm starting to think I may have a faulty board.
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
rpdom
Posts: 20037
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 6:48 am

dmaho wrote:Just did a chmod 755 on both /dev/gpiomem and /dev/spidev0.0 Still not working. I'm starting to think I may have a faulty board.
Try chmod 660 instead. 755 will give you "rwxr-xr-x" where you really want either "rw-rw----" or "rw-rw-rw-".

User avatar
DougieLawson
Posts: 42155
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Thu Dec 31, 2015 9:45 am

Try creating a fresh SDCard with NOOBS 1.5 or plain Raspbian 2015-11-21. That spi permissions stuff was added to the standard build, so your copy must be out of date and may be too old for the Zero hardware.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Fri Jan 01, 2016 3:18 am

DougieLawson wrote:Try creating a fresh SDCard with NOOBS 1.5 or plain Raspbian 2015-11-21. That spi permissions stuff was added to the standard build, so your copy must be out of date and may be too old for the Zero hardware.
Just put noobs on an SD card and the Pi Zero wont even power on anymore! I'm almost certain that it is a faulty unit now, and yes I've tried everything, different cables different distro, different SD cards.

It's so frustrating! not the loss of money but the fact that it will be months until they are available again and then I have to wait another month for postage to Aus!

Thanks everyone for trying to help, I've got a much nicer response here than other places I've posted. Everyone has been so helpful.
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Fri Jan 01, 2016 5:36 am

My bad, it does still work. The problem was I flashed NOOBS the wrong way (using the zip file with win32 disk imager) Still, its pretty crazy that doing that can stop the Pi Zero from working completely. It wouldn't get any power at all, no lights nothing.
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

User avatar
DougieLawson
Posts: 42155
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Fri Jan 01, 2016 11:02 am

The green activity light is driven by bootcode.bin. If your zero can't load that from the SDcard you won't get any winking green LED.
Languages using left-hand whitespace for syntax are ridiculous

DMs sent on https://twitter.com/DougieLawson or LinkedIn will be answered next month.
Fake doctors - are all on my foes list.

The use of crystal balls and mind reading is prohibited.

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Sat Jan 02, 2016 2:03 am

DougieLawson wrote:The green activity light is driven by bootcode.bin. If your zero can't load that from the SDcard you won't get any winking green LED.
That is good to know.
I made a new SD card with the latest NOOBS and still get the same problem.

Code: Select all

pi@Pi-Zero:~/pySX127x $ uname -a
Linux Pi-Zero 4.1.15+ #830 Tue Dec 15 16:58:28 GMT 2015 armv6l GNU/Linux

pi@Pi-Zero:~/pySX127x $ lsmod | grep spi 
spi_bcm2835             7948  0 
I remember on the diet pi image it would detect the Zero as a Pi1 so maybe thats causing the problems?
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

dmaho
Posts: 14
Joined: Wed Dec 30, 2015 7:52 am
Location: Queensland, Australia

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Mon Jan 11, 2016 3:34 am

What is the best way to test that my soldering is working properly?
https://github.com/dmahony/Lora-Chat-Device - My project to make a cheap/long distance/encrypted chat device using Raspberry Pi and InAir9B (SX1276) - Feel free to contribute!

thadg
Posts: 5
Joined: Fri Aug 11, 2017 7:10 pm

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Fri Aug 11, 2017 9:04 pm

The SPI of my Pi Zero W is not working. I looked at the outputs of the SPI nodes of the Zero with a scope and found that the chip enable (CE) is inverted from what it should be. It turns high just before the clock and data start outputting signals.
Maybe this is why this thread is having a problem with SPI???

Does anyone else have a problem with the Zero W when using SPI?

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 14480
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Fri Aug 11, 2017 11:53 pm

The SPI interface does not formally standardise the polarity of the chip select active level, so your expectations might be wrong.
https://en.wikipedia.org/wiki/Serial_Pe ... _and_phase
Perhaps the SPI driver can be modified of controlled to give the expected result.

thadg
Posts: 5
Joined: Fri Aug 11, 2017 7:10 pm

Re: Is the SPI on PI Zero different to Pi2 SPI? Not working

Sat Aug 12, 2017 12:47 pm

Thanks for the link. After looking at the link, it seems that the modes allow the rising or falling edges of SCK to be positioned in the center of the data eye of CPHA. But the chip enable SS signal is active low and, as far as I see, cannot be changed.

If you know of a way of inverting the SS signal within the Zero, it would be helpful.

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