Seeed-Studio / PN532

NFC library using PN532 to read/write card and communicate with android
421 stars 174 forks source link

PN532 Emulate not working randomly #125

Open mdjavedakhtar opened 2 years ago

mdjavedakhtar commented 2 years ago

Hi i have tried emulating a card with PN532 module. it works like 1 out of 20 times

i debug i get tgInitAsTarget Failed or timeout

if i keep the phone on the pn532 with 1 sec timeout in sketch after about 20 retry i get data on phone. then again it stops.

i am using SPI connection.

mywalkb commented 2 years ago

Try to see if my changes mywalkb/PN532 improve your experience. nfc.emulate use timeout 0, it don't give time to read response from chip, is not infinite timeout.

jlkalberer commented 10 months ago

@mywalkb - Can you explain what changes you're making in your branch? There is a lot going on there and I'd like to understand the changes before I try to use your solution as I'm sure I'd only need parts of it.

These are the changes I added. I'm using a Particle Photon (not Arduino) so there are some slight differences. I haven't tested this yet but it compiles. The other commits on your branch looked like it was for supporting callbacks which I don't want or need.

Cheers!

mywalkb commented 10 months ago

@mywalkb - Can you explain what changes you're making in your branch?

it's been over a year it's hard to remember all the changes and why I made them. With my changes I tried to implement libnfc's functions which works very well with PN532. I report the comment in my first commit:

- change include path
- fix some functions with readresponse when it's return 0 length (is not an error). Some other todo
- add setTimeoutComm for change timeout for command inCommunicateThru
- improvement function inCommunicateThru manage buffer len 0 so we can ignore response from TAG
- improvement function startPassiveTargetIDDetection manage better paramenters for all cardbaudrate

The other commits on your branch looked like it was for supporting callbacks which I don't want or need.

you can fork and remove that commit if you don't want it. When you emulate a tag without callback, how can you know when you receive data? Polling is not a good method in my opinion.

jlkalberer commented 10 months ago

Thanks @mywalkb

I took a lot of what you did and put it in this branch I'll test this out and let you know if it works for me. If it does, I'll make a smaller patch and put a PR up on this repo.


Polling is not a good method in my opinion.

Yeah, I'd generally agree with this but my code runs in a loop/state machine so a callback doesn't help me too much :)