NFC Temperature Logger Commands
Asked Answered
V

1

1

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.

Ventre answered 9/3, 2015 at 14:22 Comment(0)
P
2

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.

Presbytery answered 9/3, 2015 at 22:53 Comment(5)
Thank you for your answer. I tried your solution but the temperature (tempValue) is not correct. I get different results each time ( like: -97.7620, -11.234, 32.02999, and some others ). I also do not quite understand why you use 0x003 in ((0x003 & userdata[1]) << 8). And yes I think that calibration code is 32.Ventre
I think that correct way is: int tempCode = ((0x003 & userdata[2]) << 8) | ((0x0FF & userdata[1]) << 0);Ventre
@Ventre You are right. userdata[2] must be the MSB and userdata[1] the LSB.Presbytery
@Ventre Why 0x03: See the Data Log Format section of the datasheet. The temperature value has 10 bits (b9..b0). Thus, you have to use the whole LSB and the lower two bits of the MSB (masked with 0x03).Presbytery
Yes i have figured that out. At first I thought that temperature value is all 16 bits. That's why I was confused. Anyway, thanks for your help. I am gonna accept your answer.Ventre

© 2022 - 2024 — McMap. All rights reserved.