Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Failed SPI Loopback Test

Sun Sep 22, 2019 3:08 pm

I have wired the MISO and MOSI pins together and ran

Code: Select all

./spidev_test -D /dev/spidev0.0
I have alose tried other pins and spidev #'s.

No matter what I try I get

Code: Select all

spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 KHz)
with no output afterward (not even a 0 bit array)
Is this still possibly a software issue? Or is my BCM chip most likely broken?
Last edited by Newguys on Mon Sep 23, 2019 1:14 pm, edited 1 time in total.

RattusRattus
Posts: 102
Joined: Sat Sep 29, 2018 11:27 am

Re: Failed SPI Loopback Test

Sun Sep 22, 2019 7:02 pm

Have you enabled SPI / loaded the device driver?

https://www.raspberrypi.org/documentati ... /README.md

/Rattus

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

Re: Failed SPI Loopback Test

Sun Sep 22, 2019 7:42 pm

Check the version of spidev test you are using. The old version didn't correctly zero the struct passed to the ioctl. This didn't matter on old kernels but causes the error you describe on current kernels.

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 1:03 pm

RattusRattus wrote:
Sun Sep 22, 2019 7:02 pm
Have you enabled SPI / loaded the device driver?

https://www.raspberrypi.org/documentati ... /README.md

/Rattus
Yes I have.

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 1:06 pm

joan wrote:
Sun Sep 22, 2019 7:42 pm
Check the version of spidev test you are using. The old version didn't correctly zero the struct passed to the ioctl. This didn't matter on old kernels but causes the error you describe on current kernels.
I am on the most recent kernel (4.19.73-v7+) and I think the latest spidev test. (wget https://raw.githubusercontent.com/torva ... dev_test.c)

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 1:18 pm

Update

I now am producing bits correctly, but reading 0's. I definitely have the correct pins wired together and am using the correct chipset.

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 1:21 pm

Newguys wrote:
Mon Sep 23, 2019 1:18 pm
Update

I now know I am producing bits correctly using a slightly altered test (https://github.com/torvalds/linux/blob/ ... dev_test.c) but reading 0's. I definitely have the correct pins wired together and am using the correct chipset.

Code: Select all

max speed: 500000 Hz (500 KHz)
TX | FF FF FF FF FF FF 40 00 00 00 00 95 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF F0 0D  | ......@....▒..................▒.
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  | ................................

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

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 3:17 pm

The error seems to be as described. New kernel with old version of spidev test. Perhaps spidev test simply hasn't been updated.

You need to ensure the struct spi_ioc_transfer is zeroed before you use it.

E.g. see http://abyz.me.uk/rpi/pigpio/code/spi-driver-speed.c

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 4:22 pm

joan wrote:
Mon Sep 23, 2019 3:17 pm
The error seems to be as described. New kernel with old version of spidev test. Perhaps spidev test simply hasn't been updated.

You need to ensure the struct spi_ioc_transfer is zeroed before you use it.

E.g. see http://abyz.me.uk/rpi/pigpio/code/spi-driver-speed.c
I am confused on what I am supposed to do. I tried running that code and it returned

Code: Select all

sps=16453.0: 3 bytes @ 1000000 bps (loops=10000 time=0.6)

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

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 4:36 pm

The code I linked contained an example of how to zero the struct.

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 5:23 pm

joan wrote:
Mon Sep 23, 2019 4:36 pm
The code I linked contained an example of how to zero the struct.
I figured out what you meant. Still receiving 0's. Tried the same SD card on another pi and got the same problem so at least I know it's a software issue. At this point I am wondering if it would take less time to backup what is important and reflash raspbian.

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

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 5:30 pm

Assuming you still have MOSI and MISO linked try the following.

Code: Select all

sudo pigpiod

pigs spio 0 50000 0

pigs spix 0 1 2 3 4 5 6 7 8 9 10 11
http://abyz.me.uk/rpi/pigpio/pigs.html#SPIO
http://abyz.me.uk/rpi/pigpio/pigs.html#SPIX

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 5:44 pm

I changed jumper wires and checked the positioning for probably the 10th time just to be sure.

I still get 0 return:

Code: Select all

11 0 0 0 0 0 0 0 0 0 0 0
Also if I try to use python spi from the adafruid-blinka library it gives an error and says to check if it is enabled in the kernel.
As far as I know, it should be enabled if I enabled it in the config, I have dtparam=spi=on in my /boot/config.txt, and spidev0.0 and 0.1 are present in /dev. Correct?

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

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 8:00 pm

I think you are probably not connecting the correct pins.

Can we have a link to a clear photo of your Pi?

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 8:13 pm

joan wrote:
Mon Sep 23, 2019 8:00 pm
I think you are probably not connecting the correct pins.

Can we have a link to a clear photo of your Pi?
I know they are the correct pins (10th and 11th from the bottom on the left row), they are the same ones I was using before the SPI stopped working on my Pi, I don't have access to it for a picture at the moment.

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

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 9:26 pm

I didn't know it was working and then stopped.

Run wiringPi's pintest or pigpio's gpiotest.

http://abyz.me.uk/rpi/pigpio/examples.h ... l_gpiotest

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 9:48 pm

joan wrote:
Mon Sep 23, 2019 9:26 pm
I didn't know it was working and then stopped.

Run wiringPi's pintest or pigpio's gpiotest.

http://abyz.me.uk/rpi/pigpio/examples.h ... l_gpiotest

Code: Select all

Testing...
Skipped non-user gpios: 0 1 28 29 30 31 
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
Failed user gpios: None

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Mon Sep 23, 2019 10:00 pm

I dont know what I did, but now I'm getting

Code: Select all

pi@smokercontrol:~ $ pigs spix 0 1 2 3 4 5 6 7 8 9 10 11
11 0 0 1 0 1 2 3 8 1 10 11
.....and after a reboot it's back to the old behavior

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Tue Sep 24, 2019 12:27 am

I think I might have somehow corrupted the chipset functions in the kernel? I have no other ideas at this point. I tried the SD card on a different ras pi and got the same result, with two other people checking that the correct pins were shorted.

Newguys
Posts: 48
Joined: Sun Sep 22, 2019 3:02 pm

Re: Failed SPI Loopback Test

Tue Sep 24, 2019 12:36 am

OH MY GOD.

So just for the heck of it, I tried a third jumper wire and it passed the pigpiod test. I managed to grab two different jumper wires that were faulty when testing this.

[strike]I am still getting the following error in python, but my SPI is working correctly.[/strike]

I must have somehow typo'd when I was revising python script without realizing it. There was an extra 1 in my spi initialization, so I was trying to use spi on BCM 111. So a typo in my code, lead me to checking with a bad wire, which led me down a rabbit hole of thinking my SPI was not working.

Code: Select all

 Could not open SPI device - check if SPI is enabled in kernel!
value = AnalogIn(mcp, MCP.P0).value #read the adc
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp3xxx/analog_in.py", line 61, in value
    return self._mcp.read(self._pin_setting, is_differential=self.is_differential) << 6
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mcp3xxx/mcp3xxx.py", line 93, in read
    out_end=len(self._out_buf), in_start=0, in_end=len(self._in_buf))
  File "/usr/local/lib/python3.7/dist-packages/busio.py", line 169, in write_readinto
    return self._spi.write_readinto(buffer_out, buffer_in, out_start, out_end, in_start, in_end)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_blinka/microcontroller/generic_linux/spi.py", line 93, in write_readinto
    self._spi.open(self._port, 0)
FileNotFoundError: [Errno 2] No such file or directory

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