-
Notifications
You must be signed in to change notification settings - Fork 167
sysfs-spi: invalid SPI KeepCS handling [was: can't set antenna for mfrc522 device] #222
Comments
Hi @svenwoldt ! Sorry for the late response. Did you manage to figure out what was wrong? |
I see that in the Python code:
they don't fail if the command register has no bits 0 and 1 set. Perhaps you can try to replace the line https://github.com/google/periph/blob/HEAD/experimental/devices/mfrc522/mfrc522.go#L154 with
|
I didn't have a chance to dig into the code yet, but it seems that it's not the only problem. |
as per your recommendation trying to use this implementation instead of rpi-extras. However, I'm having troubles to make it work. Getting the same timeout as @svenwoldt Moreover, device becomes totally unresponsive after irq pin setup in
Basically after this call the only way to bring reader back is to reboot rpi. I don't see any other devices using P.S. One thing I don't understand so far, I can see that |
This happens on Raspberry Pi 3 Model B+, right? |
Yes |
Okay, I will try to test that out in a couple of days, I think I have RPi 3 B+. I tested this code on Pi Zero / Pi Zero W @maruel is there any possibility that there's something off in the GPIO drivers for these models? |
Ok, I don't think it has something to do with the device implementation itself tbh, simply running this locks the device:
Which seems to output correct values for the pins, but not for the pin mode (added debug output into sysfs.gpio)
|
|
This is exactly how current implementation is initializing the device:
I've googled today and it seems that it should support 10Mhz, not that it matters though -- changing frequency does nothing. |
Ok, so pull mode is implemented in bcm283, that's why it always NoChange in sysfs. But it seems that it's enough to simply call |
Sorry for spamming, but it's definitely not a device implementation issue.
which corresponds to commit cc45cbc Worth mentioning, that using 13 and 11 as an input pins is incorrect, documentation of I was able to narrow down the problem to the range of commits between 78a6876 and 6e2faaa Unfortunately there were a lot of changes related to the pin functions and I'm not completely familiar with periph.io core yet. |
@maruel shall we create another issue for this new details or you / someone will be looking into that in scope of this one? |
@vkorn Thanks a lot for the investigation. https://github.com/google/periph/compare/78a68761ff34ae411e312b7553ce6009cf712f5a..6e2faaa5091f07b7ddd6e3d97919c85cdf881451 includes a lot of SPI driver changes, so I could have messed up there. That's one possibility. The bcm283x driver registers the number aliases as the GPIO number as exposed by the CPU. This means that 13 == GPIO13. To get the rpi board numbers, you need to either use the rpi package or the form Background info that may have led to a bit of the confusion above:
Any idea how to make this clearer for user with better doc is appreciated. |
Re gpio number documentation, https://periph.io/device/gpio/ is clear about this. Maybe worth adding a link from within gpioreg package to this page? |
Ok, so the problem is here Lines 399 to 401 in 6c72da6
I'm not sure whether it was intended to change the behavior of Here periph/experimental/devices/mfrc522/mfrc522.go Lines 680 to 682 in 6c72da6
And here periph/experimental/devices/mfrc522/mfrc522.go Lines 685 to 688 in 6c72da6
|
Thanks a lot for the analysis @vkorn ! |
@maruel yes, with this change everything is back to normal, thank you. I would assume all other devices still should work fine since previously this flag was not present while calling regular |
Dang, thanks for diagnosing! I'll push this and will try to release soon. |
I invite you to join the slack channel to discuss this more. I'm really looking forward to have someone move it out of experimental, albeit I need someone to write a page at https://periph.io/device/ first. Thanks! |
While my fix worked for Tx(), it didn't for TxPacket(). I verified the behavior on the oscilloscope and sending a follow up fix. Sorry for the annoyance. |
Here's screenshots of the oscilloscope with the fix be61657.
3 transactionsEither
or
TxPackets with 3 packetsEither
or
TxPackets with KeepCS true
|
spi: improve documentation accordingly. A 'fix' was implemented in a851c85 but it was not good for TxPackets(). Fix the implementation and fix the documentation. The next step is to fix sysfs SPI implementation to stop refusing large transactions, and instead transparently split them up. Filed as issue google#310. Fixes google#222 (again)
I built my app against the head, and at the moment IRQ doesn't work at all, e.g there is no signal on failing edge. I will do some more research on that, but generally speaking there should be a way to not break the existing functionality with the updates. My hardware is Raspberry Pi Zero. |
@maruel thanks, tried v3.3.0 with the same result, there's no IRQ intercepted. I wonder whether there was some API change that requires doing something in order to get The pin is set up as if err := irqPin.In(gpio.PullUp, gpio.FallingEdge); err != nil {
return nil, err
} Anything else to try out? As for now I'm stuck with the version that is 6 months old :( |
The 6-month version was the only one working prior to this fix on Pi3. Head is working on Pi3 correctly, so I would assume something is different in handling edges on Pi0 :( |
Hello jdevelop and maruel,
great to see this merge. pull/220
I am busy trying out the experimental mfrc522 code but it fails to set the antenna.
The pins follow the layout described here by jdevelop.
interrupt falling edge by jens18
So after initially running into this:
mfrc522: mfrc522: timeout waitinf for IRQ edge: 30s.
I used the following command which worked for the irq pin timeout but it would then run into this issue:
pi@raspberrypi:~/go/src/github.com/google/periph/experimental $ go run cmd/mfrc522/main.go -rs-pin 13 -irq-pin 11
mfrc522: mfrc522: can not set the bitmask for antenna.
exit status 1
Could anybody help me troubleshoot this? Running on a raspberry pi zero or 3 b
I am using this device joy-it/RFID_RC522 I can confirm that it works with this library mxgxw/MFRC522-python
Much thanks
The text was updated successfully, but these errors were encountered: