-
Notifications
You must be signed in to change notification settings - Fork 19
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
Can't get to pn532 to compile with esp32 esp-hal #21
Comments
Updating to embedded-hal 1.0 has been on my backlog for a while now. Sorry it hasn't happened yet. (I would welcome a PR) You should be able to write something like this replacing the generic with the concrete ESP I2C type Same goes for SPI |
I'm willing to take a shot at this. Do you expect it to be complex?
I just did it, but it seems the Timer also needs to be dealt with. I now receive an error, haven't had a chance to look into it yet, so just sharing:
|
Ah yeah, eh1 removed the CountDown trait without a replacement. In your case using a newtype around the timer and implementing the CountDown trait should get you going. For a general implementation I'm not sure how to proceed. Maybe we should provide our own timeout trait. I would guess that a PR won't be much more complicated than your own ESP implementation. But it might take some time to get everything (including the doc tests) compiling |
I managed to get it to compile with Eventually I managed to get it working but facing several issues, not completely sure if these are ESP32 related or PN532 related or this library related or maybe my eh1 changes related.
|
Awesome work! Thanks for taking the time.
|
I've place
Yes, the way it's done in the original code is by passing two read operations, first is supposed to fetch the I don't know whether it is a So what I did is to combine the two parts into a single larger read operation and copy the byte starting with the 2nd to the passed buffer. Less elegant since I need to assume a max buffer internally (esp32 max I2C is 32 bytes so I have a limit). Any ideas on what could cause such behavior? Another behavior that might be related is the following:
When I try that, I get an error the |
Hm the timeout thing seems strange, but maybe the problems will disappear after we fix the other issues. For the two reads you'll need to use What kind of tag are you reading? Maybe ntag_read is the wrong request for you. |
This is what I referred to when I wrote about 'two reads'. The text you see above (
I'm using |
Hm this might be a bug in the HAL then.
The two reads from a single transaction should appear as just one read on the bus |
Anyway, I now switched to test SPI and ... can't get it to work. The changes to the
Any ideas what to check? I exhausted everything I could think of.
|
You should use Mode 0 and you can set lsb first with https://docs.rs/esp-hal/latest/esp_hal/spi/master/struct.Spi.html#method.with_bit_order but it seems you've done that already. Frequency shouldn't matter and 100kHz sounds good. Full duplex and ExclusiveDevice sounds good. Chip select handling might be the problem. |
Ok, I'll try that. On another note: This made me decide to get a simple logic analyzer. Do you happen to know to recommend one that isn't expensive yet good for this type of work? I saw there are those cheap ones |
I use one from Kingst and I'm quite happy with it. Don't know how it compares to others. |
I replaced the wait_ready to use transaction, same results. I went into the PN532 user manual, and found this diagram: It shows that after a command the host is supposed to poll until it receives status Any ideas what to try next? |
Yeah I'm also not sure what's going on. I assume you checked the wiring and the dip switch position? I might have a chance to try your changes on Monday. Could you share what you've got so far? |
I submitted a PR #22 . On the SPI issues, I found the following on embedded-hal: At https://rtic.rs/dev/api/embedded_hal/spi/index.html : CS-to-clock delaysMany chips require a minimum delay between asserting CS and the first SCK edge, and the last SCK edge and deasserting CS. Drivers should NOT use Operation::DelayNs for this, they should instead document that the user should configure the delays when creating the SpiDevice instance, same as they have to configure the SPI frequency and mode. This has a few advantages: Allows implementations that use hardware-managed CS to program the delay in hardware Could this be related? |
I added async support for I2C (since SPI doesn't work for me) using Would you like me to submit a PR? |
Hey, sorry for the delay... |
I'm not in a rush, it's working for me, also in async 😀 |
Any chance this (PR #22) could be merged? I've been working with this and also the async version and it's been working great for quite some time. |
Hi @yanshay could you please provide a working example somewhere how to get it working with an esp32 and I2C? |
My fork of pn532 is public - https://github.com/yanshay/pn532 (I don't think you can fork a public repo and make it private). It include two branches prefixed with 'yanshay' which you can use depending on what you need. As for the AckCheckFailed, I had it as well, eventually what I think solved it was reducing the I2c to 20kHz (which is a huge drop from what I remember was the default speed the module is expected to work). And there are still errors that require retries which don't always work. The Pn532 is not that great to work with, especially not the AliExpress clones from what I've read. Also check your wiring/soldering, I think those had to do with issues as well. You can try using a logic analyzer to see what's going on with the bus if things still don't work. Sometimes connecting the LA made things work... Here (attached zip) is some old messy code I used for many trialslto get it working, I verified it to work (on esp32s3) but by no means is it a good example, it's just many trials I made. It's also on previous version of esp-hal so I believe things changed so it won't compile as is with later versions. It's also using 100kHz, since then I move to 20kHz in my real program, I think due to reliability issues. |
I'm trying to get this to work with
esp32
usingesp-hal
(theno_std
version ofesp32
rust framework) and I can't get a simple application to compile.I noticed that this library is based on
embedded_hal 0.2.7
which was released in Feb 9, 2022, so it's pretty old and I'm using currentesp-hal
that is compatible withembedded_hal 1.0
.So is this indeed the case and the code can't really work with today's
embedded_hal
?Is there a way to get it to work by doing some extra work of implementing some interfaces or something?
The text was updated successfully, but these errors were encountered: