Hello Tomas,
I added a log message to how much characters are being printed an it turned out that there were always 258 characters printed. The Issue was, that I am working with the NXP Pn7160 Devkit and an NRF52840 as a Microcontroller, therefore i had to write an adapter for the example. It is quite sketchy but the key point was that i didnt read the first 3 bytes first to determine the payload length. Instead I read 258 Bytes every time. I fixed that and now the listen Mode works just fine. In the sense that there are still some failed attempts, but after on average 2 tries the ndef can be read by the phone. This looks like the following:
WAITING FOR DEVICE DISCOVERY
NCI << 61 05 15 01 02 04 81 ff 01 01 00 81 00 00 09 08 e7 62 e9 2e 00 08 01 00
- LISTEN MODE: Activated from remote Reader
NCI << 61 06 02 01 01
RF Deactivate ntf
NCI >> 21 06 01 00
NCI << 61 06 02 03 02
NCI << 41 06 01 00
Wait for reception
NCI >> 21 03 0d 06 00 01 02 01 01 01 06 01 80 01 81 01
NCI << 41 03 01 00
READER DISCONNECTED
WAITING FOR DEVICE DISCOVERY
NCI << 61 05 0c 01 02 04 80 ff 01 00 80 00 00 01 80
- LISTEN MODE: Activated from remote Reader
NCI << 00 00 0d 00 a4 04 00 07 d2 76 00 00 85 01 01 00
recv dataNDEF APP SEL
NCI >> 00 00 02 90 00
NCI << 60 06 03 01 00 01
NCI << 00 00 07 00 a4 00 0c 02 e1 03
recv dataNDEF CC SEL
NCI >> 00 00 02 90 00
NCI << 60 06 03 01 00 01
NCI << 00 00 05 00 b0 00 00 0f
recv dataNDEF read
NCI >> 00 00 11 00 0f 20 00 ff 00 ff 04 06 e1 04 00 ff 00 00 90 00
NCI << 60 06 03 01 00 01
NCI << 00 00 07 00 a4 00 0c 02 e1 04
recv dataNDEF NDEF SEL
NCI >> 00 00 02 90 00
NCI << 60 06 03 01 00 01
NCI << 00 00 05 00 b0 00 00 02
recv dataNDEF read
NCI >> 00 00 04 00 2b 90 00
NCI << 60 06 03 01 00 01
NCI << 00 00 05 00 b0 00 02 2b
recv dataNDEF read
--- NDEF message written
NCI >> 00 00 2d c4 0f 00 00 00 16 61 6e 64 72 6f 69 64 2e 63 6f 6d 3a 70 6b 67 63 6f 6d 2e 70 72 ...
NCI << 60 06 03 01 00 01
NCI << 61 06 02 03 02
RF Deactivate ntf
READER DISCONNECTED
But I dont think this is a Problem from a User Experience Point of View. I tested it with the NFC Tools -> worked, NFC Info -> worked and even opening an App by NDEF Record worked. THANKS!
Then I tried adding the other Modes again, MODE_POLL | TECH_PASSIVE_NFCA and so on, but now it doesn't work that flawlessly anymore. In some rare cases the Phone is recognized as a Reader how it should be, but most of the times the PN7160 just goes into Reader/Poll mode and tries to read the Phone.
NCI << 61 05 1a 01 02 04 00 ff 01 0a 04 00 04 08 ae f5 0a 01 20 00 00 00 00 05 04 78 80 40 00
NCI >> 21 06 01 03
NCI << 41 06 01 00
NCI << 61 06 02 03 00
NCI << 61 05 1a 01 02 04 00 ff 01 0a 04 00 04 08 b7 ee 7a 01 20 00 00 00 00 05 04 78 80 40 00
- POLL MODE: Remote T4T activated
SENS_RES = 0x04 0x00
NFCID = 08 ae f5 0a
SEL_RES = 0x20
NCI >> 00 00 0d 00 a4 04 00 07 d2 76 00 00 85 01 01 00
NCI << 60 06 03 01 00 01
NCI << 00 00 02 6a 82
NCI >> 00 00 0c 00 a4 04 00 07 d2 76 00 00 85 01 00
NCI << 60 06 03 01 00 01
NCI << 00 00 02 6a 82
NCI >> 2f 11 00
NCI << 4f 11 01 00
NCI << 6f 11 01 01
NCI >> 2f 11 00
NCI << 4f 11 01 00
NCI << 6f 11 01 01
NCI >> 2f 11 00
NCI << 4f 11 01 00
NCI << 6f 11 01 00
CARD REMOVED
NCI >> 21 06 01 00
NCI << 41 06 01 00
NCI << 61 06 02 00 00
NCI >> 21 03 0d 06 00 01 02 01 01 01 06 01 80 01 81 01
NCI << 41 03 01 00
I tried to distinguish the Phone from a Desfire Tag by the length of the NFCID, which is in the case of Desfire 7 Bytes, and in the case of the Phone only 4. But that didn't work.
If a 4 Byte NFCID was recognized i tried to StopDiscovery and restarting it by StartDiscovery with a different set of DiscoveryTechnologies.
unsigned char DiscoveryTechnologies_passive[] = {
MODE_LISTEN | TECH_PASSIVE_NFCA,
MODE_LISTEN | TECH_PASSIVE_NFCB,
};
....
NxpNci_StopDiscovery();
while(NxpNci_StartDiscovery(DiscoveryTechnologies_passive,sizeof(DiscoveryTechnologies_passive)));
But that resulted somehow in that the phone could not read the pn7160 at all. On the other hand, Desfire tags were readable.
Is there a smart way to set the reader into passive mode if there is a smartphone approaching?
Thanks a lot so far!
Greetings Erik