cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, Im using ST25DV04 with ESP32. Im unable to write tags onto NFC. I2C Communication fails.

Shruthi
Associate II

0693W00000DpfBTQAZ.jpgDuring initialization of CC, as I understand we should have values 0xe1,0x40,0x40,0x00

But I am getting 0xe1,0x40,0x40,0x43. Im trying to manually write 0xe1,0x40,0x40,0x00 at address 0xa6, 0x00 which is failing.

I ignored that and tried to write a text NDEF tag to it which is also failing.

Please check the screenshot.

Step1 : Im writing CC at 0xa6,0x00 address- which failed.

Step2 : Writing length at 0xa6,0x04 address - success

Step3 : writing text NDEF tag at 0xa6,0x06 address - fail

Step4 : reading NDEF data- reading old text NDEF tag present on NFC.

Why is the write operation failing ? Are there any other registers to be set before writing?

16 REPLIES 16

sent the file over mail.

Hi,
Here is the scope data when I run the entire NFC_init() function.
Starting from reading NFC ID, till writing my custom Media type tag.
JL. Lebon
ST Employee

Hello Shruthi,

Thank you for the trace, it really helps to understand the issue.

Your I2C trace shows that the I2C writes are not correctly framed.

In the Session_I2C_Init trace, you can see that starting at time 3172501208.

Your write frame is this:

Start/A6/Ack/00/Ack/04/Ack/03/Ack/Start/A6/Ack/C1/Ack/Stop.

I guess you are trying to write value 03h at address 0004h, and then value C1h.

There is two things wrong in this sequence:

  • An I2C write MUST be terminated by a STOP bit. After the byte 03h, you do a new START, so the write value 03h at address 0004h is not executed
  • After the second START bit, you present the device select slave address, and then what seems to be a value to be written. But after the START, the ST25DV assumes this is a new write sequence, and is waiting for a memory address on 2 bytes at this place. So the write of value C1h is not executed

This is all explained in detail in datasheet chapter "6.4 I2C Write operations".

Correct sequence is:

Start/A6/Ack/00/Ack/04/Ack/03/Ack/C1/Ack/Stop.

or, if you want to do it in 2 times:

Start/A6/Ack/00/Ack/04/Ack/03/Ack/Stop Start/A6/Ack/00/Ack/05/Ack/C1/Ack/Stop.

The next write sequences all suffer from the same problem, and this is why no data is ever written to the tag's memory.

Best regards.

Hello,
Thanks much for the support. I corrected the I2C sequence and I'm able to write the tag onto NFC now.
But after writing the tag, the last terminator byte 0xfe is failing. while addressing the device itself, there is no acknowledgment.
Saleae is used.
Ch0-SCL ; Ch1 - SDA
JL. Lebon
ST Employee

Hello,

"While addressing the device itself, there is no acknowledgement": do you mean after the first byte (the device slave address) there is not acknowledgement ?

This means that the device is not available for processing an I2C command. This can happen in 3 cases:

  • the device is not powered with Vcc.
  • the device is busy on the RF interface, processing an RF command.
  • the device is busy writing data into EEPROM after an I2C write command.

I guess you may be in the third case. I suppose you are writing the terminator TLV right after updating the NDEF message content ?

When updating the NDEF message, you are writing into the EEPROM memory. The I2C bus is then unavailable during the programming time of the EEROM: the device needs 5ms to program each 4 bytes of data. The write is starting at the stop bit of the I2C write command.

So, you should wait the end of EEPROM programming before being able to access the tag again.

This is explained in the datasheet, in chapter "6.4.2 I2C Sequential write".

Best regards.

Shruthi
Associate II

Got it. Thanks a lot for the support.

Connor_Gilgamesh
Associate

I meet the same question.

here is the solution.

for esp-idf, the i2c addr means bit0~bit6,

but for nfc06a, the i2c addr means bit1~bit7,

when I scan the i2c devices, 0x2d 0x53 0x57 are active,

so, just set (addr >> 1), during write and read.

 

int32_t pltf_i2c_read_reg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
    i2c_device_config_t i2c_dev_conf = {
        .scl_speed_hz = 1000000,
        .device_address = DevAddr >> 1,
    };

    i2c_master_dev_handle_t dev_handle;

    if (i2c_master_bus_add_device(i2c_master_handle, &i2c_dev_conf, &dev_handle) != ESP_OK)
    {
        return ESP_FAIL;
    }

    uint8_t reg_buf[2] = {Reg >> 8, Reg & 0xFF};
    esp_err_t ret = i2c_master_transmit_receive(dev_handle, reg_buf, 2, pData, Length, 50);

    i2c_master_bus_rm_device(dev_handle);
    return ret;
}

int32_t pltf_i2c_write_reg16(uint16_t DevAddr, uint16_t Reg, uint8_t *pData, uint16_t Length)
{
    i2c_device_config_t i2c_dev_conf = {
        .scl_speed_hz = 1000000,
        .device_address = DevAddr >> 1,
    };

    i2c_master_dev_handle_t dev_handle;

    if (i2c_master_bus_add_device(i2c_master_handle, &i2c_dev_conf, &dev_handle) != ESP_OK)
    {
        return ESP_FAIL;
    }

    uint8_t *p_data = malloc(Length + 2);
    if (p_data == NULL)
    {
        i2c_master_bus_rm_device(dev_handle);
        return ESP_FAIL;
    }

    p_data[0] = Reg >> 8;
    p_data[1] = Reg & 0xFF;
    memcpy(&p_data[2], pData, Length);

    esp_err_t ret = i2c_master_transmit(dev_handle, p_data, Length + 2, 50);

    i2c_master_bus_rm_device(dev_handle);
    free(p_data);
    return ret;
}

int32_t pltf_i2c_is_ready(uint16_t DevAddr, uint32_t Trials)
{
    esp_err_t ret = i2c_master_probe(i2c_master_handle, (DevAddr >> 1), 50);
    return ret;
}