You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SPI hardware (MFRC522) not working with Latest Jessie release (2016-05-10-raspbian-jessie) #1547
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
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.
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?
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?
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..
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.
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?
Unless I've made a mistake (I haven't tested that patch), yes - that should fix it. It's a shame there wasn't a backwards-compatible way to make the SPI-Py changes.
Thanks guys, but even with the old version of the library it still doesn't scan my card. @pelwell I followed your instructions (#2613) but right at step 1, I don't see options named SPI in Advanced Options (in raspi-config). Therefore, when I run dtoverlay -l I get No overlays loaded
@cscuilla I just did that but the command dtoverlay - l still returns the same thing. It should be noted that I do see the line dtparam=spi=on in my /boot/config.txt folder.
Also when I run lsmod | grep spi I get spidev 20480 spi_bcm2835 20480 0
@pelwell After your fix, I see get the following warning when I run Read.py:
/home/pi/MFRC522-python/MFRC522.py:133: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings.
dtoverlay -l will only list overlays (and DT parameters) applied by Linux at run time. Overlays applied by the firmware become part of the base DTB, so Linux isn't aware that is what they are.
That warning is because GPIO 25 (pin 22) has been left as an output by a previous failed run. Run raspi-gpio set 25 ip and try again. Once the script is working, provided you exit cleanly with Ctrl-C you shouldn't see that warning.
@pelwell I tried to run this and I get this output
00: 00 82 84 86 88 8a 8c 8e
08: 90 92 94 96 98 9a 9c 9e
10: a0 a2 a4 a6 a8 aa ac ae
18: b0 b2 b4 b6 b8 ba bc be
20: c0 c2 c4 c6 c8 ca cc ce
28: d0 d2 d4 d6 d8 da dc de
30: e0 e2 e4 e6 e8 ea ec ee
38: f0 f2 f4 f6 f8 fa fc fe
which tells me that, at least, the spi part of the equation is working properly. Also, every time I run the script, the values change entirely.
The values the test app is reading back are the same as those it is sending. (If you are curious, you could try deliberately connecting MOSI to MISO to see what the results are.)
Is the CS line connected correctly? And is the device powered. As part of the diagnostic process you can disconnect each pin, one at a time (but not GND) and observe the changes in the output.
Activity
pelwell commentedon 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 commentedon Jun 28, 2016
To get it working on previous Jessie Release (2016-03-18) I have to add the following to /boot/config.txt
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 commentedon Jun 28, 2016
Can you confirm that with just
dtparam=spi=onin config.txt (by which I mean no other spi-related settings) andspi-devin /etc/modules that /dev/spi0.0 and /dev/spi0.1 appear but your script fails?pelwell commentedon 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 commentedon Jun 28, 2016
what do you mean by this part
pelwell commentedon 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 commentedon 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 commentedon Jun 28, 2016
I can confirm this.. In /boot/config.txt I have the following
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 commentedon 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..
EECSdude commentedon 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 commentedon 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 commentedon 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 commentedon Jun 28, 2016
I can answer the second question myself now - the SPI-Py (spi) module drives the spidev interface from C code.
EECSdude commentedon Jun 28, 2016
PIN 22 is GPIO25, what pin configuration is the code using? Moving the wire now.
cscuilla commentedon 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.
459 remaining items
pelwell commentedon May 24, 2019
That's true - with the newer SPI-Py, the
openSPImethod returns a device handle that needs to be passed to thetransfermethod, so something like:cscuilla commentedon May 24, 2019
Thanks again @pelwell so to clarify, are you saying to make those changes to the MFRC522.py file and it should work with latest SpI-Py library?
pelwell commentedon May 24, 2019
Unless I've made a mistake (I haven't tested that patch), yes - that should fix it. It's a shame there wasn't a backwards-compatible way to make the SPI-Py changes.
ksanchez15 commentedon May 24, 2019
Thanks guys, but even with the old version of the library it still doesn't scan my card. @pelwell I followed your instructions (#2613) but right at step 1, I don't see options named SPI in Advanced Options (in raspi-config). Therefore, when I run
dtoverlay -lI getNo overlays loadedcscuilla commentedon May 24, 2019
@pelwell thanks again i will test early next week.. @lesanchez try "Interface Options" under raspi-config. Enable SPI, then reboot and try again.
ksanchez15 commentedon May 24, 2019
@cscuilla I just did that but the command
dtoverlay - lstill returns the same thing. It should be noted that I do see the linedtparam=spi=onin my /boot/config.txt folder.Also when I run
lsmod | grep spiI getspidev 20480spi_bcm2835 20480 0ksanchez15 commentedon May 24, 2019
@pelwell After your fix, I see get the following warning when I run Read.py:
pelwell commentedon May 24, 2019
dtoverlay -lwill only list overlays (and DT parameters) applied by Linux at run time. Overlays applied by the firmware become part of the base DTB, so Linux isn't aware that is what they are.cscuilla commentedon May 24, 2019
@lesanchez It's probably your wiring or soldering that is the problem then.
ksanchez15 commentedon May 24, 2019
@cscuilla @pelwell all right thank you guys
pelwell commentedon May 24, 2019
That warning is because GPIO 25 (pin 22) has been left as an output by a previous failed run. Run
raspi-gpio set 25 ipand try again. Once the script is working, provided you exit cleanly with Ctrl-C you shouldn't see that warning.ksanchez15 commentedon May 24, 2019
I have quadruple check my wiring (even asked a colleague who is an electrical engineer) and everything is good. I have checked out the old version of SPI-Py and I'm using https://github.com/mxgxw/MFRC522-python's latest version.
Still, the tag (which was sent with the RC522 board) doesn't trigger anything. Could the issue come from somewhere else?
ksanchez15 commentedon May 27, 2019
@pelwell I tried to run this and I get this output
which tells me that, at least, the spi part of the equation is working properly. Also, every time I run the script, the values change entirely.
pelwell commentedon May 27, 2019
The values the test app is reading back are the same as those it is sending. (If you are curious, you could try deliberately connecting MOSI to MISO to see what the results are.)
Is the CS line connected correctly? And is the device powered. As part of the diagnostic process you can disconnect each pin, one at a time (but not GND) and observe the changes in the output.
cscuilla commentedon Jul 26, 2019
@pelwell i can confirm your patch works with latest spi library! thanks again.