Skip to main content
Shruthi
Associate III
August 18, 2021
Solved

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

  • August 18, 2021
  • 9 replies
  • 3518 views

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?

Best answer by JL. Lebon

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.

9 replies

Brian TIDAL
Technical Moderator
August 24, 2021

Hi,

I would first suggest to make sure the byte write in not inhibited (see §6.4.1 in ST25DV04 datasheet)

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.
Shruthi
ShruthiAuthor
Associate III
August 27, 2021

Hi,

Thanks for the suggestion. I made the necessary changes and now I2c is writing without any return errors.

But I don't see the tag updated on NFC. I'm using NFCTools mobile app to scan, and the tag is not updated.

I'm writing a media type tag from program to NFC.

0693W00000DlOreQAF.jpg

Brian TIDAL
Technical Moderator
August 27, 2021

Hi,

can you read back the content of the tag through I2C after writing to check the 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.
Shruthi
ShruthiAuthor
Associate III
August 27, 2021

0693W00000DlPFXQA3.jpg 

This the NFC content I'm reading after my write function.

Im writing media type tag, whereas, there is already an existing text type tag which is not updated after my write.

Brian TIDAL
Technical Moderator
August 30, 2021

Hi,

can you connect a logic analyzer on the I2C and provide a trace of the I2C communication (including ACK and NAK bits)?

Thanks

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.
Shruthi
ShruthiAuthor
Associate III
September 3, 2021

0693W00000Dm4noQAB.jpg0693W00000Dm4kvQAB.jpg 

This is how I'm seeing on logic analyzer.

Brian TIDAL
Technical Moderator
September 3, 2021

Hi,

can you share the logic analyzer trace file so that I can see the full frame and do some analysis? (Please indicate whether this is Salae or digiview or picoscope, or other tool)

Thanks

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.
Shruthi
ShruthiAuthor
Associate III
September 3, 2021
Hi,
Im attaching the logic capture file.
This is generated using Saleae.
JL. Lebon
ST Employee
September 3, 2021

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.

Shruthi
ShruthiAuthor
Associate III
September 21, 2021
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
JL. LebonBest answer
ST Employee
September 23, 2021

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
ShruthiAuthor
Associate III
September 23, 2021

Got it. Thanks a lot for the support.

Visitor II
October 15, 2024

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;
}