Reading NDEF-Message using PN532

Posted on
  • Hi,

    I would like to create an NFC tag reader using a PN532. In the end I would like to read NDEF messages from any NDEF tag.

    The general interfacing already works. I wired up the MDBT42Q breakout and a PN532 breakout board.

    Using the PN532 module I am able to read the card id, as it's shown in the tutorial.

    Now, I would like to read all bytes and parse an NDEF message with the library

    The idea is to read all bytes of the NDEFMessage and then parse them with the following call:

    var ndefMessage = NdefLibrary.NdefMessage.fromByteArray(by­teArray);

    I managed to load the minified version of the library within espruino, I just need to read all the bytes of the tag.
    So I started modifying the PN532 module in an own fork and created the function findCardsAllBytes, which looks like this:

    PN532.prototype.findCardsAllBytes = function(callback) {
                 1, // max targets (max=2)
                 C.PN532_BRTY_ISO14443A // modulation type
      var p = this;
      setTimeout(function() { // wait for NFC poll (30ms)
        var d = p.i2c.readFrom(C.PN532_I2C_ADDRESS, 20+1).slice(1);
        if (d[6]==C.PN532_COMMAND_INLISTPASSIVETARG­ET+1) {
          if (d[7]!=1) print("Expecting 1 tag, got "+d[7]);
      }, 30);

    Do you have an idea which I2C commands I need to read all the raw bytes of the tag?

    Thank you!

  • Hi Martin,

    I'm afraid I don't personally, but maybe looking at another library would help. For example Adafruit have a library, and if you're reading mifare (example at­32/blob/master/examples/readMifare/readM­ifare.ino) they seem to authenticate and then read, which both seem to be done with PN532_COMMAND_INDATAEXCHANGE:

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Reading NDEF-Message using PN532

Posted by Avatar for user155724 @user155724