interrupt falling edge
jens18 opened this issue · comments
I am trying to use the RF522 library with the following card:
https://www.amazon.com/gp/product/B01KFM0XNG/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
This card can be successfully used with the Python implementation:
https://github.com/pimylifeup/MFRC522-python.git
Note: This implementation does not rely on the 'interrupt' line.
After adding the 'interrupt' line (in my case GPIO23) and initialization with:
rfid, err := rf522.MakeRFID(0, 0, 1000000, 25, 23)
the Wait() method unfortunately gets into an endless loop:
root@carmel:~/Projects/go/src/github.com/jdevelop/golang-rpi-extras # go run rf522_main.go
DEBU[0000] >>[01, 0f] [00, 00]
DEBU[0000] >>[2a, 8d] [00, 00]
DEBU[0000] >>[2b, 3e] [00, 00]
DEBU[0000] >>[2d, 1e] [00, 00]
DEBU[0000] >>[2c, 00] [00, 00]
DEBU[0000] >>[15, 40] [00, 00]
DEBU[0000] >>[11, 3d] [00, 00]
DEBU[0000] <<[54, 00] [00, 00]
DEBU[0000] Antenna0
DEBU[0000] Set mask 20 3
DEBU[0000] <<[54, 00] [00, 00]
DEBU[0000] Set mask value 20 3
DEBU[0000] >>[14, 03] [00, 00]
DEBU[0000] Init done
ReadCard: before selectCard
selectCard: before Wait
DEBU[0000] >>[01, 0f] [00, 00]
DEBU[0000] >>[2a, 8d] [00, 00]
DEBU[0000] >>[2b, 3e] [00, 00]
DEBU[0000] >>[2d, 1e] [00, 00]
DEBU[0000] >>[2c, 00] [00, 00]
DEBU[0000] >>[15, 40] [00, 00]
DEBU[0000] >>[11, 3d] [00, 00]
DEBU[0000] <<[54, 00] [00, 00]
DEBU[0000] Antenna0
DEBU[0000] Set mask 20 3
DEBU[0000] <<[54, 00] [00, 00]
DEBU[0000] Set mask value 20 3
DEBU[0000] >>[14, 03] [00, 00]
DEBU[0000] Init done
DEBU[0000] >>[04, 00] [00, 00]
DEBU[0000] >>[02, a0] [00, 00]
wait: before interruptLoop
timout
...
I do not have an oscilloscope to analyze the actual behavior of the 'interrupt' line and
would very much appreciate any suggestion on how to potentially resolve this issue.
Thanks,
-jens
You should (if I remember that correctly) use BCM numbering there:
so GPIO23
should refer to BCM 13
- not 23
. Also the reset pin should be 26
(that BCM numbering drives me nuts sometimes).
Pls let me know if that helped. I suspect that you have the GPIO23
pin configured for the IN
mode and it gives the random noise, that's why you have that infinite loop.
I tried the BCM numbering:
rfid, err := rf522.MakeRFID(0, 0, 1000000, 26, 13)
unfortunately without success.
I then tried Dave Cheney's 'watch.go' test program for 'falling edge':
go run watch.go
Now watching pin 22 on a falling edge.
Setting power high
Setting power low
Callback for 22 triggered!
Setting power high
Setting power low
Callback for 22 triggered!
and I use the following GPIO names:
func main() {
// set GPIO22 to input mode
pin, err := gpio.OpenPin(gpio.GPIO22, gpio.ModeInput) // physical pin 15
if err != nil {
fmt.Printf("Error opening pin! %s\n", err)
return
}
// set GPIO2 to output mode
power, err := gpio.OpenPin(gpio.GPIO2, gpio.ModeOutput) // physical pin 3
I now understand that Dave Cheney uses essentially 2 numbering schemes:
GPIO number scheme in: https://github.com/davecheney/gpio/blob/master/gpio_linux.go
BCM number scheme in: https://github.com/davecheney/gpio/blob/master/rpi/rpi.go
Is it possible to use the RF522 library without the 'interrupt' line?
I think yes, but unfortunately you are on your own here.
Hi, I just got back to this project and tried my own wiring for Raspberry Pi Zero as the following setup:
RPI Pin (physical) | RFID Pin |
---|---|
24 | 0 (SDA) |
23 | 1 (SCK) |
19 | 2 (MOSI) |
21 | 3 (MISO) |
11 | 4 (IRQ) |
6 | 5 (GND) |
13 | 6 (RST) |
1 | 7 (+3.3V) |
Basically the same as listed for the Python version, except the different ping for IRQ.
Now, looking at your gpio readall
diagram I see that most of your pins are in IN
mode - which is wrong.
So if you are still interested in troubleshooting this - please let me know. So far I can confirm that IRQ works fine on Raspberry Pi Model 2
and Raspberry Pi Zero
.
@jdevelop on Raspberry Pi 3 Model B
not receiving any info from RC522.
rfid, err := rf522.MakeRFID(0, 0, 1000000, 27, 17)
Here irq Pin connected to physical 11
this is what prints
# go run rf522_main.go
DEBU[0000] >>[01, 0f] [87, 00]
DEBU[0000] >>[2a, 8d] [0f, 6a]
DEBU[0000] >>[2b, 3e] [8d, 6a]
DEBU[0000] >>[2d, 1e] [3e, 6c]
DEBU[0000] >>[2c, 00] [1e, 6c]
DEBU[0000] >>[15, 40] [00, 14]
DEBU[0000] >>[11, 3d] [40, 10]
DEBU[0000] >>[26, 40] [3d, 66]
DEBU[0000] <<[54, 00] [40, 80]
DEBU[0000] Antenna128
DEBU[0000] Set mask 20 3
DEBU[0000] <<[54, 00] [00, 80]
DEBU[0000] Set mask value 20 131
DEBU[0000] >>[14, 83] [00, 14]
DEBU[0000] Init done
DEBU[0000] >>[01, 0f] [83, 00]
DEBU[0000] >>[2a, 8d] [0f, 6a]
DEBU[0000] >>[2b, 3e] [8d, 6a]
DEBU[0000] >>[2d, 1e] [3e, 6c]
DEBU[0000] >>[2c, 00] [1e, 6c]
DEBU[0000] >>[15, 40] [00, 14]
DEBU[0000] >>[11, 3d] [40, 10]
DEBU[0000] >>[26, 40] [3d, 66]
DEBU[0000] <<[54, 00] [40, 80]
DEBU[0000] Antenna128
DEBU[0000] Set mask 20 3
DEBU[0000] <<[54, 00] [00, 80]
DEBU[0000] Set mask value 20 131
DEBU[0000] >>[14, 83] [00, 14]
DEBU[0000] Init done
DEBU[0000] >>[04, 00] [83, 04]
DEBU[0000] >>[02, a0] [00, 02]
Can you give a shot to http://github.com/google/periph ?
They use a different library for the interrupts, and I have ported the MFRC522 code for that framework.
Side note - I never tested this code with RPi 2 or 3, only Zero / ZeroW
@jdevelop thanks, will try it, but can't find any example of usage
https://github.com/google/periph/blob/HEAD/experimental/devices/mfrc522/mfrc522.go
Also, by docs there are no pin difference between RasPiZero and RasPiModel3