2024-10-01 01:10 AM
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.
2024-10-01 08:05 AM - edited 2024-10-01 08:07 AM
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
2024-10-01 05:17 PM
2024-10-02 12:19 AM
Hi,
the NDEF message seems to be written starting from block 0:
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