Search code examples
androidtagsnfcrfidiso-15693

NFC Temperature Logger Commands


I am coding an Android aplication. I have a SL13A Temperature Data Logger and I am trying to read temperature from the logger, but I don't really know how.

Here is the datasheet: http://www.mouser.com/ds/2/588/AMS_SL13A_Datasheet_EN_v4-371531.pdf

I am using the Get Temperature Command (command code 0xAD).

My code is like that:

                NfcV nfcvTag = NfcV.get(tag);

                try {
                    nfcvTag.connect();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "Could not open connection!", Toast.LENGTH_SHORT).show();
                    return;
                }

                try {

                    byte[] comReadTemp = new byte[]{
                            (byte) 0x00, // Flags
                            (byte) 0xAD, // Command: Get Temperature
                            (byte) 0xE0,(byte) 0x36,(byte) 0x04,(byte) 0xCA,(byte) 0x01,(byte) 0x3E,(byte) 0x12,(byte) 0x01, // UID - is this OK?
                    };


                    byte[] userdata = nfcvTag.transceive(comReadTemp);


                    tvText.setText("DATA: " + userdata.length);

                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "An error occurred while reading!", Toast.LENGTH_SHORT).show();
                    return;
                }

I am not sure what flags to set and if I put UID parameter in the command correctly.

And also my question is, how do I get temperature bits from command reply? In datasheet it is shown that first 8 bits of command reply are flags, next 16 bits are temperature, and last 16 bits are CRC. But it seems that I only get 3 bytes in reply (userdata.length equals 3).

Any help would be appreciated.


Solution

  • First of all (though you seem to get the correct response anyways), when you want to use the addressed version of the command (i.e. the one that contains the optional UID field), you need to set the addressed bit in the flags byte. So flags should be 0x20.

    Typically, you would create the command like this:

    byte[] comReadTemp = new byte[]{
            (byte) 0x20, // Flags
            (byte) 0xAD, // Command: Get Temperature
            (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,  // placeholder for tag UID
    };
    System.arraycopy(tag.getId(), 0, comReadTemp, 2, 8);
    

    The response that you get from the transceive() method will only be the payload of the ISO 15693 frame. Thus, you will get the flags byte (1 byte) and the temperature value (2 bytes). The SOF, CRC and EOF are automatically stripped by the NFC stack (just as they are automatically added when sending data).

    So bytes 1..2 of userdata contain the temperature value:

    int tempCode = ((0x003 & userdata[2]) << 8) |
                   ((0x0FF & userdata[1]) << 0);
    double tempValue = 0.169 * tempCode - 92.7 - 0.169 * 32;
    

    Assuming that offset calibration code is 32. The datasheet is not very clear if that's a per chip calibration value or a static value for that type of chip.