Skip to main content
Explorer
April 23, 2023
Solved

temperature sensor NDEF

  • April 23, 2023
  • 11 replies
  • 2438 views

I have programmed the temperature sensor, but it seems that it has not been successful, the NDEF reading result is shown in the figure, what should I do?

if( NfcType5_NDEFDetection( ) != NDEF_OK )

 {

  CCFileStruct.MagicNumber = NFCT5_MAGICNUMBER_E1_CCFILE;

  CCFileStruct.Version = NFCT5_VERSION_V1_0;

  CCFileStruct.MemorySize = ( ST25DVXXKC_MAX_SIZE / 8 ) & 0xFF;

  CCFileStruct.TT5Tag = 0x05;

  /* Init of the Type Tag 5 component (M24LR) */

  while( NfcType5_TT5Init( ) != NFCTAG_OK );

 }

 /* Init done */

 NFC07A1_LED_Off( GREEN_LED );

 HAL_Delay( 300 );

 NFC07A1_LED_Off( BLUE_LED );

 HAL_Delay( 300 );

 NFC07A1_LED_Off( YELLOW_LED );

 HAL_Delay( 300 );

 /* write text message to EEPROM */

 K_Temperature= MAX6675_ReadTemperature(); //读�?�热电�?�温度值

 HAL_Delay(1000);

 // 将浮点数转�?�为字符串

 char temp_str[20];

 sprintf(temp_str, "%f", K_Temperature);

 // 将字符串转�?�为无符�?�8�?整数数组

 uint8_t temp_data[strlen(temp_str)];

 memcpy(temp_data, temp_str, strlen(temp_str));

 // 写入NDEF消�?�

 NDEF_WriteNDEF(strlen(temp_str), temp_data);

  //读�?�NDEF消�?�

  NDEF_ReadNDEF(temp_data);

 /* Set the LED3 on to indicate Programing done */

 NFC07A1_LED_On( YELLOW_LED );

}


_legacyfs_online_stmicro_images_0693W00000bidNeQAI.png

    This topic has been closed for replies.
    Best answer by Brian TIDAL

    Hi,

    as already explained in a previous post:

    when the NDEF TEXT message is properly formatted, Android displays the text (i.e. decodes the NDEF and extracts the payload). If using the ST25 NFC Tap app, the NDEF tab display "Text record"; the content of the record is displayed when pressing on the "Text record" field.

    This is the way you should check.

    Rgds

    BT

    11 replies

    Technical Moderator
    April 23, 2023

    Hi

    I see several issues in your code:

    1. the input parameter of NDEF_WriteNDEF is supposed to be a formatted NDEF buffer whereas temp_data is not a NDEF buffer. If you want to write a TEXT record, make sure to use the NDEF_WriteText API.
    2. obviously MAX6675_ReadTemperature returns 0. You should debug this API
    3. memcpy(temp_data, temp_str, strlen(temp_str)) seems to be useless. Why don't using temp_str direclty?

    I would also remind that this community has ground rules so please make sure to avoid to duplicate your posts.

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 24, 2023

    Hi,@Brian TIDAL_O​ 

    I understand your mean, but the NDEF_WriteText function can only implement text repetition. I need to read the temperature data instead of the text,so I use NDEF_WriteNDEF and NDEF_ReadNDEF. Please give me some concrete suggestions.

    Technical Moderator
    April 24, 2023

    Hi

    since you have converted the float temperature value to a string (see  sprintf(temp_str, "%f", K_Temperature); in your code), what you have to write to the tag is a text. Therefore, NDEF_WriteNDEF is not the proper API except if you want to format the record by yourself. So, I would again suggest to use NDEF_WriteText API.

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 24, 2023

    Hi,@Brian TIDAL_O​ 

    I am a beginner,so can you give me more information about NDEF_WriteText API?I read out the memory through the following code as shown in the image,but I don't know why is it displayed like this?I need your help�?Thanks

    while (1)

     {

      /* USER CODE END WHILE */

     /* write text message to EEPROM */

      K_Temperature= MAX6675_ReadTemperature(); //读�?�热电�?�温度值

      HAL_Delay(1000);

      // 将浮点数转�?�为字符串

      char temp_str[20];

      sprintf(temp_str, "%f", K_Temperature);

      // 将字符串转�?�为无符�?�8�?整数数组

      uint8_t temp_data[strlen(temp_str)];

      memcpy(temp_data, temp_str, strlen(temp_str));

      // 写入NDEF消�?�

      NDEF_WriteNDEF(strlen(temp_str), temp_data);

       /* Extract record info */

       sRecordInfo_t record;

       NDEF_ReadNDEF(temp_data);

       /* Extract record info */

       NDEF_IdentifyBuffer(&record,temp_data);

       if (strcmp((char*)record.Type, (char*)URL_TYPE) == 0)

       {

        /* Extract URI from NDEF Message */

        char uri[record.PayloadLength];

        memcpy(uri, record.PayloadBufferAdd, record.PayloadLength);

        /* Parse URI to get temperature value */

        sscanf(uri, "Temperature=%f", &K_Temperature);

       }

      /* Set the LED3 on to indicate Programing done */

      NFC07A1_LED_On( YELLOW_LED );

     MX_NFC7_Process();

      /* USER CODE BEGIN 3 */

     }


    _legacyfs_online_stmicro_images_0693W00000big8IQAQ.png

    Technical Moderator
    April 24, 2023

    Hi,

    in a nutshell, an NDEF message is a set of NDEF records. Each NDEF record carries a payload identified by a payload type (e.g. TEXT, URI, etc.).

    NDEF_WriteNDEF is designed to write a buffer containing an NDEF formatted message. In your case, the content of NDEF_WriteNDEF buffer is not an NDEF message but the payload with the temperature value as a text. As the temperature value is a text, the proper API to be used is NDEF_WriteText (see description inside lib_NDEF_text.c). NDEF_WriteText encodes the payload into a TEXT record and then writes this NDEF buffer thanks to NDEF_WriteNDEF.

    What you currently have in the tag memory is:

    block 00: E1 40 40 05: Capability Container

    block 01: 03 0B 31 30: NDEF TLV (T=03h, L=0Bh, V= 31 30 39 32 2E 32 35 30 30 30 30 etc.)

    ...

    block 04: xx FE xx xx : Terminator TLV

    Here the V-field (31 30 39 32 2E 32 35 30 30 30 30) is the payload whereas it should be the encoded TEXT message. If you use NDEF_WriteText, the V-field will have the proper TEXT message format

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 24, 2023

    Hi,@Brian TIDAL_O​ 

    According to your words, I have got the temperature data correctly,So I just have to watch the V-field to get the temperature data,Is that so?

    Technical Moderator
    April 24, 2023

    Hi,

    when the NDEF TEXT message is properly formatted, Android displays the text (i.e. decodes the NDEF and extracts the payload). If using the ST25 NFC Tap app, the NDEF tab display "Text record"; the content of the record is displayed when pressing on the "Text record" field.

    The memory content will be:

    block 00: E1 40 40 05: Capability Container

    block 01: 03 11 D1 01: NDEF TLV (T=03h, L=11h,

    block 02: 0D 54 02 66 V=D1 01 0D 54 02 66 72 31 30 39 32 2E 32 35 30 30 30)

    block 03: 72 31 30 39

    block 04: 32 2E 32 35

    block 05: 30 30 30 FE: xx xx xx FE Terminator TLV

    V-field decoded:

    D1 01 0D 54 02 66 72 31 30 39 32 2E 32 35 30 30 30
    D1 Record header, TNF=001 
     01 Type Length
     0D Payload length
     54 Type: T (Text)
     02 66 72 31 30 39 32 2E 32 35 30 30 30 
     02 66 72 Text lang = en
     31 30 39 32 2E 32 35 30 30 30 
     Text = 1092.25000

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 26, 2023

    Hi,@Brian TIDAL_O 

    I have understood  V-field decoded correctly,but I have another question,why do I get more than 1,000 temperature figures? Is there a problem with the data conversion?

    Technical Moderator
    April 26, 2023

    Hi,

    the 12-bit temperature value is returned as bits[14:3] of the 16-bit SO output of the thermocouple to digital converter device (see datasheet of this device). As each step correspond to (1/4)°C, it is unlikely that the output value of this 12-bits value is greater that 1024 (1/4 * 2^12). Actually the datasheet states " A sequence of all ones means the thermocouple reading is +1023.75°C." which is the max possible value.

    Therefore, having 1092.25 is likely a data conversion issue in your code.

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 26, 2023

    Hi,@Brian TIDAL_O​ 

    I also think I have a problem. I don't know what's wrong with the data,and I'm sure there is no problem with the data of the MAX6675, it may be that there is a discrepancy in the conversion, please check it for me.

    Technical Moderator
    April 26, 2023

    Hi,

    This a community for ST products and as far as I know MAX6675 is not an ST product. Therefore I would suggest you contact the manufacturer of this device for proper support on this device. I believe that the initial NDEF issue reported in your post is now solved and can be closed.

    Rgds

    BT

    SchuylerAuthor
    Explorer
    April 26, 2023

    Hi,@Brian TIDAL_O​ 

    OK. Are you sure the code I mentioned is correct about the use of NDEF related functions? Is the temperature data correctly written to memory?