Skip to main content
Schuyler
Associate III
December 29, 2023
Solved

Why can't ST25 read sensor data?

  • December 29, 2023
  • 4 replies
  • 2974 views

 

float K_Temperature ; //K型热电偶 温度值
char temperaturebuffer[30] = { 0xD1, 0x01, 0x1B, 0x54, 0x02, 0x65, 0x6E };
uint16_t TarAddr= 0x0000; 
/* Write NDEF to EEPROM */
	 K_Temperature=MAX6675_ReadTemperature(); //读取热电偶温度值
	 sprintf(&temperaturebuffer[7], "Temperature: %.2f C", K_Temperature);
	 NFC07A1_NFCTAG_WriteData(NFC07A1_NFCTAG_INSTANCE, (uint8_t *)temperaturebuffer, TarAddr, strlen(temperaturebuffer) + 1);
	 uint8_t ReadData[30];
	 NFC07A1_NFCTAG_ReadData(NFC07A1_NFCTAG_INSTANCE, ReadData, TarAddr, sizeof(ReadData));
	 // 延时一段时间
	 HAL_Delay(300);
	 NFC07A1_LED_On( GREEN_LED );

I converted the temperature data into a string and wrote it to the address, but NFC couldn't get the temperature information. I don't know if it's a write function usage error or a write address error, but here's what NFC gets.

GHB9{7%0R[`BO1C45YN5L1H.png

 

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

Hi,

if your application is supposed to write the temperature data as a TEXT NDEF record, the tag has to be properly NDEF formatted (i.e. with a Capability Container starting at block 0 followed by an NDEF TLV). See 

AN4911 (NDEF management with ST25DV-I2C Series, and ST25TV16K and ST25TV64K products) for detailed information.
Rgds
BT

4 replies

Brian TIDAL
Technical Moderator
December 29, 2023

Hi,

see the first reply of https://community.st.com/t5/st25-nfc-rfid-tags-and-readers/x-cube-nfc7-no-ndef-seen-by-the-phone/td-p/144185NFC07A1_NFCTAG_WriteData writes raw data into the tag and therefore this is not NDEF formatted. 

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
SchuylerAuthor
Associate III
December 29, 2023

Hi @Brian TIDAL 

But what I am writing is sensor data, which is dynamic data. Can I follow the above reference? Is there a specific method for writing NFC into sensors?

Brian TIDAL
Technical Moderator
December 29, 2023

HI,

I've just seen that temperaturebuffer contains an NDEF TEXT record header (D1 01 etc.). So I assume you write the temperature value inside a TEXT record. But as TarAddr  equals 0, this NDEF is written by NFC07A1_NFCTAG_WriteData at block 0 whereas block 0 should contain the NFC Forum Capability Container. Therefore the tag is no longer properly formatted. 

I would suggest to reuse X-CUBE-NFC7\1.0.0\Projects\NUCLEO-L476RG\Applications\NDEF_URI in your application and to modify it to use a TEXT record instead of an URI record.

If you still prefer to use NFC07A1_NFCTAG_WriteData, make sure to have a Capability container in block 0 and the NDEF Type and Length fields before the NDEF TEXT record.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Brian TIDAL
Brian TIDALBest answer
Technical Moderator
January 2, 2024

Hi,

if your application is supposed to write the temperature data as a TEXT NDEF record, the tag has to be properly NDEF formatted (i.e. with a Capability Container starting at block 0 followed by an NDEF TLV). See 

AN4911 (NDEF management with ST25DV-I2C Series, and ST25TV16K and ST25TV64K products) for detailed information.
Rgds
BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
SchuylerAuthor
Associate III
January 3, 2024

Hi @Brian TIDAL 

Thank you for your answer. According to the instructions of AN4911, I can only know the theoretical knowledge of NDEF, but I currently need to read the dynamic temperature data without code instructions, how should I deal with K_Temperature in the software design?

K_Temperature=MAX6675_ReadTemperature(); // Read the thermocouple temperature value.

Brian TIDAL
Technical Moderator
January 3, 2024

Hi,

I am sorry but I do not understand your last post. I am afraid I cannot help more.

Rgds

BT

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Schuyler
SchuylerAuthor
Associate III
January 3, 2024

Hi @Brian TIDAL 

I know the  Capability Container starting at block 0 followed by an NDEF TLV, I change the write address to 0XD1, which is block 01:03 11 D1 01: NDEF TLV (T=03h, L=11h,), can the following corrected code write temperature data correctly?

float K_Temperature ; 
char temperaturebuffer[30] = { 0xD1, 0x01, 0x1B, 0x54, 0x02, 0x65, 0x6E };
uint16_t TarAddr= 0xD1;
void MX_NFC7_NDEF_URI_Init(void)
{
	 /******************************************************************************/
 /* Configuration of X-NUCLEO-NFC02A1 */
 /******************************************************************************/
 /* Init of the Leds on X-NUCLEO-NFC07A1 board */
 NFC07A1_LED_Init(GREEN_LED );
 NFC07A1_LED_Init(BLUE_LED );
 NFC07A1_LED_Init(YELLOW_LED );
 NFC07A1_LED_On( GREEN_LED );
 HAL_Delay( 300 );
 NFC07A1_LED_On( BLUE_LED );
 HAL_Delay( 300 );
 NFC07A1_LED_On( YELLOW_LED );
 HAL_Delay( 300 );

 /* Init ST25DVXXKC driver */
 while( NFC07A1_NFCTAG_Init(NFC07A1_NFCTAG_INSTANCE) != NFCTAG_OK );

 /* Reset Mailbox enable to allow write to EEPROM */
 NFC07A1_NFCTAG_ResetMBEN_Dyn(NFC07A1_NFCTAG_INSTANCE);

 NfcTag_SelectProtocol(NFCTAG_TYPE5);

 /* Check if no NDEF detected, init mem in Tag Type 5 */
 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 );

}

/**
 * @brief Process of the NDEF_URI application
 * @retval None
 */
void MX_NFC7_NDEF_URI_Process(void)
{
	 /* Write NDEF to EEPROM */
	 K_Temperature=MAX6675_ReadTemperature(); 
	 sprintf(&temperaturebuffer[7], "Temperature: %.2f C", K_Temperature);
	 NFC07A1_NFCTAG_WriteData(NFC07A1_NFCTAG_INSTANCE, (uint8_t *)temperaturebuffer, TarAddr, strlen(temperaturebuffer) + 1);
	 uint8_t ReadData[NFCTAG_64K_SIZE];
	 NFC07A1_NFCTAG_ReadData(NFC07A1_NFCTAG_INSTANCE, ReadData, TarAddr, strlen(temperaturebuffer) + 1);
	 HAL_Delay(300);
	 NFC07A1_LED_On( GREEN_LED );
}