cancel
Showing results for 
Search instead for 
Did you mean: 

Writing NDEF for ST25DV. Code failing

isaacseeto
Associate III

Hi I was just wondering if someone could help point out where I could be going wrong with my implementation of write NDEF function. This is a very rough implementation but I believe I am following the correct message structure. I know my i2c mem write commands are working as I have tested the addresses. When I use the ST25 Tap app I don't see NDEF storage being populated. 

My implementation:

HAL_StatusTypeDef write_ndef_pressure_message(int32_t pressure_mmHg_scaled) {

HAL_StatusTypeDef status;

 

// Create a buffer for the pressure message (e.g., "123.45 mmHg")

char pressure_str[16]; // Max size for the pressure string (with decimals and unit)

snprintf(pressure_str, sizeof(pressure_str), "%ld.%02ld mmHg", pressure_mmHg_scaled / 100, pressure_mmHg_scaled % 100);

 

uint16_t message_len = strlen(pressure_str);

 

// Ensure the total length doesn't exceed the memory limit

if (message_len + NDEF_HEADER_SIZE > 32) {

message_len = 32 - NDEF_HEADER_SIZE; // Limit to 32 bytes (adjust based on available memory size)

}

 

// 1. Clear User Memory Area 1 (32 bytes for this example)

uint8_t clear_memory[32] = {0}; // Clear memory

status = HAL_I2C_Mem_Write(&hi2c1, ST25DV_I2C_DATA_ADDRESS, USER_MEMORY_START, I2C_MEMADD_SIZE_16BIT, clear_memory, 32, HAL_MAX_DELAY);

 

// Ensure the device is ready for the next operation (check readiness)

while (HAL_I2C_IsDeviceReady(&hi2c1, ST25DV_I2C_DATA_ADDRESS, 1, HAL_MAX_DELAY) != HAL_OK) {

HAL_Delay(5); // Small delay to allow the device to complete the write

}

 

// 2. Adjust NDEF Header for the correct payload length

NDEF_Text_Header[2] = message_len; // Set the correct payload length in the NDEF header

 

// 3. Write the NDEF header to User Memory Area 1

status = HAL_I2C_Mem_Write(&hi2c1, ST25DV_I2C_DATA_ADDRESS, USER_MEMORY_START, I2C_MEMADD_SIZE_16BIT, NDEF_Text_Header, NDEF_HEADER_SIZE, HAL_MAX_DELAY);

 

// Ensure the device is ready for the next operation (check readiness)

while (HAL_I2C_IsDeviceReady(&hi2c1, ST25DV_I2C_DATA_ADDRESS, 1, HAL_MAX_DELAY) != HAL_OK) {

HAL_Delay(5); // Small delay to allow the device to complete the write

}

 

// 4. Write the NDEF payload (pressure value as string) right after the header

status = HAL_I2C_Mem_Write(&hi2c1, ST25DV_I2C_DATA_ADDRESS, USER_MEMORY_START + NDEF_HEADER_SIZE, I2C_MEMADD_SIZE_16BIT, (uint8_t*)pressure_str, message_len, HAL_MAX_DELAY);

 

// Ensure the device is ready for the next operation (check readiness)

while (HAL_I2C_IsDeviceReady(&hi2c1, ST25DV_I2C_DATA_ADDRESS, 1, HAL_MAX_DELAY) != HAL_OK) {

HAL_Delay(5); // Small delay to allow the device to complete the write

}

 

return status;

}

 

Thank you.

3 REPLIES 3
Brian TIDAL
ST Employee

Hi,

can you dump the user memory from block #0 to the last block being used by your NDEF and share it with us? You can use the ST25 NFC Tap application to dump the memory content

 

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.

Hi,

This is the memory bin file from the ST25 Tap app.

Thank you

Hi,

the NDEF message seems to be written starting from block 0:

BrianTIDAL_0-1727853071200.png

This is not compilant with NFC Forum T5T technical specification. Block 0 should contain the so-called Capability Container (aka CC). See Application Note AN4911 (ST25DV-I2C, ST25TV16K and ST25TV64K configuration to support a NDEF message).

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.