1
votes

I'm trying to read a NFC tag developed by NXP in my Android Application. It is possible to read the tag with Android: the App by NXP and one other read it correctly.

The exact Tag type is "ICODE SLI-L (SL2ICS50)" and the RF technology is "Type V / ISO 15693" (data taken from those working apps). The memory consists of 2 pages with 4 blocks each, the blocks have 4 bytes each – I just want to have whole data stored in the memory.

The tag has to be handled with Android's NfcV class and the datasheet of the tag is available here, but it is hard to find any working code example using NfcV. I tried several things which I concluded by the datasheet by myself and I tried the communication samples from this PDF I found with Google, but nothing works.

The corresponding method in my activity (I use NFC Foreground Dispatch) looks like this:

public void onNewIntent(Intent intent) {
    android.nfc.Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    NfcV tech = NfcV.get(tag);
    try {
        tech.connect();
        byte[] arrByt = new byte[9];
        arrByt[0] = 0x02;
        arrByt[1] = (byte) 0xB0;
        arrByt[2] = 0x08;
        arrByt[3] = 0x00;
        arrByt[4] = 0x01;
        arrByt[5] = 0x04;
        arrByt[6] = 0x00;
        arrByt[7] = 0x02;
        arrByt[8] = 0x00;
        byte[] data = tech.transceive(arrByt);
        // Print data
        tech.close();
    } catch (IOException e) {
        // Exception handling
    }
}

The method is called correctly when I place my phone on the tag, but the transceive() method of the NfcV object always throws an IOException: android.nfc.TagLostException: Tag was lost.. This is the result of all byte arrays I tried (the one above is unlikely correct but over the last days I tried a bunch of others which all resultet in the same behaviour.

From what I read on the Internet, I conclude that the error occurs because I send the wrong commands to the tag – but I just cannot come up with the right ones. Any ideas?

1
I even emailed NXP, but they linked me to the datasheet I already had and suggested that I ask here on StackOverflow ;-)Raphael Michel

1 Answers

6
votes

ISO 15693 defines different read commands and manufacturers also may define proprietary read commands. All ICODE tags support the ISO 15693 Single Block Read command. You can send it as follows:

public static void processNfcIntent(Intent intent){
    Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
    if(tag != null){
      // set up read command buffer
      byte blockNo = 0; // block address
      byte[] readCmd = new byte[3 + id.length];
      readCmd[0] = 0x20; // set "address" flag (only send command to this tag)
      readCmd[1] = 0x20; // ISO 15693 Single Block Read command byte
      byte[] id = tag.getId();
      System.arraycopy(id, 0, readCmd, 2, id.length); // copy ID
      readCmd[2 + id.length] = blockNo; // 1 byte payload: block address

      NfcV tech = NfcV.get(tag);
      if (tech != null) {
        // send read command
        try {
          tech.connect();
          byte[] data = tech.transceive(readCmd); 
        } catch (IOException e) {
          e.printStackTrace();
        } finally {
          try {
            tech.close();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }
      }
    }
}