New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPI hardware (MFRC522) not working with Latest Jessie release (2016-05-10-raspbian-jessie) #1547

Closed
cscuilla opened this Issue Jun 28, 2016 · 170 comments

Comments

Projects
None yet
@cscuilla

cscuilla commented Jun 28, 2016

The rfid reader (MFRC522) does not work with the latest release of Jessie(2016-05-10). It works fine on the previous version (2016-03-18). I believe this is due to the new version of SPI.

On previous Jessie version (2016-03-18-raspbian-jessie) if I type lsmod after installing spi I get the following..
spi_bcm2708

On recent Jessie version (2016-05-10-raspbian-jessie) if I type lsmod after installing spi I get the following..
spi_bcm2835

Others, are having the same issue as described on the raspberry pi forum at this link..
https://www.raspberrypi.org/forums/viewtopic.php?f=107&t=148890

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

Can you describe the configuration of your system - any relevant entries in config.txt, cmdline,txt, /etc/modules or /etc/modprobe.d/*.conf?

Also, can you explain the failure mode - what do you expect to happen, and what actually happens?

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

To get it working on previous Jessie Release (2016-03-18) I have to add the following to /boot/config.txt

device_tree_param=spi=on
dtoverlay=spi-bcm2708
This does NOT work on latest Jessie release. I've also tried
dtoverlay=spi-bcm7835

The failure mode is as follows.. Once I run the script it appears to work as it is waiting for a card to be scanned, however when I scan a card, nothing is output.

On previous Jessie(where card reader works), when I run the script and scan a card, the UID of the card is printed.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

Can you confirm that with just dtparam=spi=on in config.txt (by which I mean no other spi-related settings) and spi-dev in /etc/modules that /dev/spi0.0 and /dev/spi0.1 appear but your script fails?

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

I've just ordered one of these devices, but it probably won't arrive before next week and I can't promise much time to look at this.

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

what do you mean by this part

and spi-dev in /etc/modules that /dev/spi0.0 and /dev/spi0.1 appear but your script fails?
Currently, if I open /etc/modules all I have is
i2c-dev

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

Sorry, that's correct. SPI and I2C are strangely different in that respect the layered, user-space interface to I2C (i2c-dev) isn't loaded by Device Tree because it isn't hardware-specific, but the equivalent module for SPI (spidev) is.

So, to be more accurate: can you confirm that with just dtparam=spi=on in config.txt (by which I mean no other spi-related settings) that /dev/spi0.0 and /dev/spi0.1 appear but your script fails?

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

OK, thanks, I am setting up a new memory card now with the latest release so I can confirm this for you.

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

I can confirm this.. In /boot/config.txt I have the following

dtparam=spi=on

If I go into the /dev folder and type "ls"
I see spidev0.0 and spidev0.1

When I start my script, I receive no output once I scan a card.

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

Thank you for ordering the hardware. I understand your time is limited but do appreciate the help. Here are the full steps to get the reader working on previous debian OS in case it helps you to troubleshoot..

  1. add to the bottom of /boot/config.txt
    • device_tree_param=spi=on
    • dtoverlay=spi-bcm2708
  2. Install python-dev
    • sudo apt-get install python-dev
  3. Install SPI
  4. Install Sample RFID Reader python library and sample script.
  5. Run sample script.
    • sudo python ~/MFRC522-python/read.py
@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

I am running Raspberry Pi 2 B on Linux 4.4.11-v7+ #888 SMP Mon May 23 20:10:33 BST 2016 armv7l GNU/Linux with exact same behavior. I am online the next hour and happy to run any tests, provide any files.

Scope traces show the following.
GPIO 25, the RST line is always high, I don’t see it move.
GPIO 8 is always low, I don’t see it move, although I do see digital noise similar to SCLK at the millivolt level.
SCLK toggles the whole time Read.py is running, as expected.
As an experiment, I rebooted then ran a few commands to toggle GPIO25 up and down to check my scope setup. When I ran the same script with 25 set to 8, I got a runtime warning in response to GPIO.setup(8, GPIO.OUT) “this channel is already in use”.

I would expect to get that message if the GPIO was in CE0 mode, not a GPIO output as gpio readall says it is.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

You say that GPIO 25 is the reset line, but the code appears to use GPIO 22 - is this a non-standard numbering issue, or have you modified your version of the code?

As mentioned in the Forum thread, the spi-bcm2835 driver uses software-controlled CE lines rather than ones driven by the hardware block, to work around a hardware glitch, which means that the driver is claiming the pin for GPIO - this explains the contention.

I see there is an spidev Python module that uses the spidev interface - does the spi module also do this, or is it a pure user-space software implementation?

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

I have not modifed Read.py. Interesting, I'll move the wire and see what happens.

https://github.com/mxgxw/MFRC522-python shows:

Name Pin # Pin name
SDA 24 GPIO8
SCK 23 GPIO11
MOSI 19 GPIO10
MISO 21 GPIO9
IRQ None None
GND Any Any Ground
RST 22 GPIO25
3.3V 1 3V3

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

I can answer the second question myself now - the SPI-Py (spi) module drives the spidev interface from C code.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

PIN 22 is GPIO25, what pin configuration is the code using? Moving the wire now.

@cscuilla

This comment has been minimized.

cscuilla commented Jun 28, 2016

For me, The python script uses "board" as the mode for rip.gpio. So the reset is on pin 22 but GPIO number 25.

I'm not sure what u mean in regards to the spidev Python module.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

Moving the RFID modules RST pin from Raspberry Pi pin 22 / GPIO25 to pin 15/GPIO 22 doesn't make it work.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

OK - I see that RPi.GPIO is configured in BOARD mode, so 22 is the header pin number but it carries GPIO 25, so that isn't the problem.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

LONG - Here's all the pertinent information in my system that has been asked for in the thread above:

I did one more thing than the previous post, suggested by a website I have forgotten:

Install latest version of bcm2835, C library for Broadcom BCM 2835 as used in Raspberry Pi; version 1.46 currently.
(http://www.airspayce.com/mikem/bcm2835/)

# download the latest version of the library, say bcm2835-1.xx.tar.gz, then:
$ tar zxvf bcm2835-1.xx.tar.gz
$ cd bcm2835-1.xx
$ ./configure
$ make
$ sudo make check
$ sudo make install

The above didn’t cause MFRC522-python\Read.py to work

It felt like the problem is a conflict between 2835 and 2708, so I have added and commented out things with no success and no error indication.

Here's a snapshot of a system that runs Read.py with no error and no card read:

$ ls /dev/spi*
/dev/spidev0.0  /dev/spidev0.1
$ lsmod
Module                  Size  Used by
xt_multiport            1756  1
iptable_filter          1409  1
ip_tables              11637  1 iptable_filter
x_tables               12507  3 ip_tables,xt_multiport,iptable_filter
cfg80211              427855  0
rfkill                 16037  1 cfg80211
evdev                  11396  4
bcm2835_wdt             3225  0
bcm2835_gpiomem         3040  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
spi_bcm2835             7286  0
snd_bcm2835            20511  0
snd_pcm                75698  1 snd_bcm2835
snd_timer              19160  1 snd_pcm
snd                    51844  3 snd_bcm2835,snd_timer,snd_pcm
i2c_bcm2708             4770  0
i2c_dev                 5859  0
fuse                   83461  1
ipv6                  347530  45
$ cat /boot/config.txt (clipped only bottom)
# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on
# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on
dtparam=spi=on
dtparam=i2c_arm=on
start_x=1
gpu_mem=128

dtoverlay=spi-bcm2835

#dtoverlay=spi-bcm2708
$ cat /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

i2c-dev
i2c-bcm2708
snd-bcm2835
#i2c-bcm2835
#rtc-ds1307
#spi-dev
spi-bcm2835
#spi-bcm2708

The files “etc/modprobe.d/*.conf” are only empty blacklist files.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 28, 2016

Thanks for all of that information. A few comments:

  1. Don't use dtoverlay=spi-bcm2835 - that overlay isn't needed and doesn't exist anymore.
  2. You don't need to load i2c-bcm2708, snd-bcm2835 or spi-bcm2835 - they are all loaded by Device Tree nowadays.

I don't think either of these will cause your problem, I'm just trying to encourage best practises.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

Just noticed the original post and I are using different libraries with same result.
Original post is: https://github.com/rasplay/MFRC522-python
I'm using: https://github.com/mxgxw/MFRC522-python.

Both are 2 years since last update.
Both use SPI-Py. Common failure point?

@EECSdude

This comment has been minimized.

EECSdude commented Jun 28, 2016

Thank you pelwell, followed best practices and still no joy, but I feel so much cleaner! Just FYI, I have moved this particular RFID hardware to an Arduino and it works.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 29, 2016

There was an issue around the time of the Pi2 launch caused by a change to the SPI ioctl interface - a field in a structure that was an output became an input and output, and many libraries had to be changed to zero that field before calling the ioctl in question. I'll find the details later.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 29, 2016

Anything like this: http://stackoverflow.com/questions/10828194/issue-with-spi-serial-port-comm-stuck-on-ioctl

or this:

http://www.raspberry-projects.com/pi/programming-in-c/spi/using-the-spi-interface

Issues:
"Error – Problem transmitting spi data..ioctl: Invalid argument

Due to changes in the underlying library the spi_ioc_transfer struct now needs to be initialised to NULL, and a hacky fix is to add this to the beginning of the for loop (this has been done in the code example above)

memset(&spi[i], 0, sizeof (spi[i]));

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 29, 2016

That second link is the issue I was referring to. You could try adding this to spi.c in the SPI-Py library at line 190:

                .cs_change = 1,
+               .pad = 0,
    };

A more future-proof fix would be to memset the structure to zero before setting the required fields, but that would need a bit more restructuring.

If a non-zero pad field is the cause of the problem then I'm slightly surprised that you don't see the "can't send spi message" error message.

@cscuilla

This comment has been minimized.

cscuilla commented Jun 29, 2016

I tried adding the change to spi.c, but the issue is the same. No error message when running script, but no output when trying to read a card.

@EECSdude

This comment has been minimized.

EECSdude commented Jun 30, 2016

Any more help I can provide? We have some great momentum on this.

@pelwell

This comment has been minimized.

Contributor

pelwell commented Jun 30, 2016

I won't do any more on this until the hardware arrives, which should be next week.

@Jbithell

This comment has been minimized.

Jbithell commented Jun 30, 2016

I'm having issues with this as well - I've had it working quite well for some time - a quick SD flash and new raspian install (as I change project) and nothing with SPI seems to be working.

I've tried everything I can think of, on 2 different Pi's (B+ and 3) - and nothing working on either of them. Currently resorting to banging my head against a wall

@Jbithell

This comment has been minimized.

Jbithell commented Jun 30, 2016

I'm going to try a rollback using http://downloads.raspberrypi.org/raspbian/images/

popcornmix added a commit that referenced this issue Aug 22, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Aug 22, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Aug 29, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Aug 29, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 5, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 10, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 10, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 17, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 17, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 21, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 25, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Sep 26, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 1, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 2, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 8, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 8, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

APokorny pushed a commit to ubports/ubuntu_kernel_xenial that referenced this issue Oct 11, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: raspberrypi/linux#1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

APokorny pushed a commit to ubports/ubuntu_kernel_xenial that referenced this issue Oct 11, 2018

BCM270X_DT: Overlay to re-enable HW CS on SPI0
See: raspberrypi/linux#1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 15, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 15, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

bluegray pushed a commit to bluegray/ubuntu-bionic that referenced this issue Oct 17, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: raspberrypi/linux#1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 22, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Oct 22, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Nov 4, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Nov 4, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

raspbian-autopush added a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018

rpi_1014_88a246c7a00a25567c4b9ea445ee34e8bf97ba24
commit 88a246c
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Fri Jul 1 22:09:24 2016 +0100

    spi-bcm2835: Disable forced software CS
    
    Select software CS in bcm2708_common.dtsi, and disable the automatic
    conversion in the driver to allow hardware CS to be re-enabled with an
    overlay.
    
    See: raspberrypi/linux#1547
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1014_88a246c7a00a25567c4b9ea445ee34e8bf97ba24.patch

raspbian-autopush added a commit to raspbian-packages/linux-4.9 that referenced this issue Nov 11, 2018

rpi_1122_01d2ad99ffa4739c2afb99ed023ab965e830d6da
commit 01d2ad9
Author: Phil Elwell <phil@raspberrypi.org>
Date:   Fri Jul 1 22:09:24 2016 +0100

    spi-bcm2835: Disable forced software CS
    
    Select software CS in bcm2708_common.dtsi, and disable the automatic
    conversion in the driver to allow hardware CS to be re-enabled with an
    overlay.
    
    See: raspberrypi/linux#1547
    
    Signed-off-by: Phil Elwell <phil@raspberrypi.org>


Gbp-Pq: Topic rpi
Gbp-Pq: Name rpi_1122_01d2ad99ffa4739c2afb99ed023ab965e830d6da.patch

jiangyilism pushed a commit to jiangyilism/linux-ubuntu-backport-test that referenced this issue Nov 12, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: raspberrypi/linux#1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Nov 12, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>

popcornmix added a commit that referenced this issue Nov 13, 2018

spi-bcm2835: Disable forced software CS
Select software CS in bcm2708_common.dtsi, and disable the automatic
conversion in the driver to allow hardware CS to be re-enabled with an
overlay.

See: #1547

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment