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.

4

1 回答 1

2

首先(尽管您似乎得到了正确的响应),当您想使用命令的寻址版本(即包含可选 UID 字段的命令)时,您需要在标志字节中设置寻址位。所以标志应该是0x20.

通常,您会像这样创建命令:

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);

您从该transceive()方法获得的响应将只是 ISO 15693 帧的有效负载。因此,您将获得标志字节(1 个字节)和温度值(2 个字节)。SOF、CRC 和 EOF 由 NFC 堆栈自动剥离(就像它们在发送数据时自动添加一样)。

所以字节 1..2userdata包含温度值:

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

假设偏移校准代码为 32。如果这是每个芯片的校准值还是该类型芯片的静态值,数据表不是很清楚。

于 2015-03-09T22:53:28.970 回答