Skip to main content
Graduate II
December 21, 2023
Solved

Issue with I2C communication with ST25DV64KC tag

  • December 21, 2023
  • 9 replies
  • 3829 views

Hi @Rene Lenerve  @JL. Lebon  @Brian TIDAL 

So basically I am connecting ST25DV64KC tag with MKE14F512VLL16 based controller and I want to write on the tag through i2c but as I am sending data using I2c write and as I am checking using Logic analyzer it showing its writing and sending ack but when I am checking using st nfc tap app  options read memory  there nothing was written can you guys confirm few things like is tag slave  device address  is 0xA6  for writing on tag and is it mandatory to give memory address or it will assume 0000h as base address and write on it  and to write on tag do we need to send one byte at a time .Can you please provide details about i2c communication to  write on tag by the way I have already gone through the datasheet.

    This topic has been closed for replies.
    Best answer by JL. Lebon

    Hello, 

    Sorry for my late answer, I missed your question.
    We do have the M24SR in which RF passwords can be modified from I2C interface. The M24SR is an NFC type 4 (ISO14443), so quite different from the ST25DV though.

    Best regards.

    9 replies

    ST Employee
    December 21, 2023

    Hello, 

    I will try to answer to your questions one by one.

    "tag slave  device address  is 0xA6  for writing on tag": yes, that's it to write the user memory. But be aware that this includes the R/W bit, so do not append the R/W bit to this address.

    "is it mandatory to give memory address or it will assume 0000h as base address": yes, for a write it is mandatory to provide the 2 Bytes of the memory address.

    "to write on tag do we need to send one byte at a time": if you write in user memory (not system configuration memory or registers) you can write from 1 up to 256 Bytes at a time.

    A correctly formed I2C write command to user memory should be like this:

    Start/0xA6/ack/MSB_memory_address/ack/LSB_memory_address/ack/data_byte1/ack/data_byte2/ack/.../last_data_byte/ack/Stop

    Please check if your I2C command is formatted in this way.
    Then please try to read back the data from the I2C interface to ensure it has been correctly written. The I2C read command would be:

    Start/0xA6/ack/MSB_memory_address/ack/LSB_memory_address/ack/Start/0xA7/ack/data_byte1/ack/data_byte2/ack/.../last_data_byte/Nack/Stop (please note that after 0xA7/ack/, all data bytes are sent by the ST25DV and all ack are sent by the MCU).

    Then, if you can read the data from I2C, you can try again to read it from RF.

    Best regards.

     

     

    PoolBearAuthor
    Graduate II
    December 22, 2023

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL 

    First of all thank you for your reply so I am using I2C write and initialization commands to write on the tag so like-

    I2c__Initialize(I2C0 ,I2C_100KHZ ,I2C_ADDR_7BITS ,0xA6 );

    Then I used something like I2Cmemorywrite function where passing --------

    params.i2c = I2C0;
    params.deviceAddress = 0xA6;
    params.memoryAddress = 0x03E8;
    params.memoryAddressSize = 2;
    params.dataBuffer = (uint8[]){0x05};
    params.dataSize = 1;

    parameter and now after that I am sending like this ------------

    void I2C_MemoryWrite(I2C_MemoryWrite_Params *params) {
    // Send start condition

    // Send device address with write bit
    uint8 deviceAddress = (params->deviceAddress << 1) | 0; // Set LSB to 0 for write

    // Send memory address
    for (uint8 i = 0; i < params->memoryAddressSize; ++i) {
    // I2C_SendByte exists to send a byte
    I2C_SendByte(params->i2c, (params->memoryAddress >> (8 * (params->memoryAddressSize - 1 - i))) & 0xFF);
    }

    // Send data
    for (uint16 i = 0; i < params->dataSize; ++i) {
    I2C_SendByte(params->i2c, params->dataBuffer[i]);

    }

    // I2c__Disable(params->i2c);


    }

    BOOL_TYPE I2C_SendByte(I2C_ENUM_TYPE i2c, uint8 byte) {
    // Assuming a proper implementation of I2c_Write
    uint8 buffer[1];
    buffer[0] = byte;


    status = I2c__Write(i2c, 0xA6, buffer, 1);

    }

    So in logic analyzer I am getting ack from device and also its showing writing random data in some random address but if we try to read memory using the st nfc app nothing is there  .So i am sharing some logic analyzers pic with you guys if you can suggest about what can be the problem it will be helpful--

    PoolBear_0-1703252968588.png

    PoolBear_1-1703253042136.png

     

     

    ST Employee
    December 22, 2023

    Hello, 

    Sorry, but the logic analyzer traces don't help as we can't see the I2C frame at bits or even Byte level: "write to 0x02 ack data:0x12". What does it mean ? Do you write to I2C slave address 0x02? This is not ST25DV64K address...

    Nevertheless, I found something that looks wrong in your code:
    "params.deviceAddress = 0xA6
    uint8 deviceAddress = (params->deviceAddress << 1) | 0; // Set LSB to 0 for write"

    As said in my previous post: "be aware that this (0xA6) includes the R/W bit, so do not append the R/W bit to this address".

    0xA6 already includes the write bit. In your code, you end up with deviceAddress=0x4C when it must be 0xA6.
    You must either set params.deviceAddress = 0x53 if you want to shift it and happen the Write bit, or keep 0xA6 and do deviceAddress = params->deviceAddress & 0xFE.

    Did you try to read back from I2C what you have written? I would do this first, since reading from RF is just introducing a new unknown in the equation.

    Best regards.

    ST Employee
    January 8, 2024

    Hi PoolBear,

    You were mentioning in you first post that you received an ACK at each write, but in you screenshot it seems to be an error response (not easy to read the answer). Does this response error is due to Debugger stop or sent when in run mode too.

    If you could capture with the logic analyzer a single write sequence and zoom in to see the SDA/SCL bits to see in more detail what is happening.

    Another test could be to write some data with ST25 NFC Tap App (to ease operation it could be at address 0x000C) and try to read it through I²C.

    Kind Regards.

     

    PoolBearAuthor
    Graduate II
    January 18, 2024

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL 

    hey guys I have been able to write on the tag successfully now if it is possible can you guys provide any information how can I lock this tag so that no one can write on the tag using nfc only reading of the tag will be possible using NFC app.

    ST Employee
    January 19, 2024
    PoolBearAuthor
    Graduate II
    January 19, 2024

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL 

    Hey thank you for your speedy response I have been able to stop writting on the tag by writting on RFA1SS=05h.Now can you please share details on how to change  password 1 which is by default 00h .

    ST Employee
    January 19, 2024

    Hello, 

    Glad that you have been to protect the tag.

    To change the password value:
    - first present the current password to open the security session. This is done using the "Present password" command. Parameters are the password number you want to change and the current password value (which is all 00 by default).
    - then you can change the password. This is done using the "Write password" command. Parameters are the password number (same as the one used in the Present password command) and the new password value. Change is immediate. Do not remove the RF field between the two commands or the security session will be closed and you will have to present the password again.

    Two things to note:
    - the password number parameter: this should be the password you want to change, which is probably the password you are using to protect your memory access.
    - when writing the new password, be sure that the RF field is stable (reader close to the tag, no moving). In fact, if the RF field is removed during write password, the new password can be corrupted and there is no way to recover it.

    Best regards.

     

    PoolBearAuthor
    Graduate II
    January 19, 2024

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL 

    I will write on the tag using I2c only so like can please provide the register number and like how to do it using i2c 

    ST Employee
    January 19, 2024

    Hi, 

    Not sure to understand what you want to do.
    Do you want to change password from I2C interface? Be aware that RF password can only be presented and changed from the RF interface, and I2C password can only be presented and changed from the I2C interface. There is no bridge between I2C and RF regarding passwords.

    Best regards.

    PoolBearAuthor
    Graduate II
    January 19, 2024

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL

    so as I have locked the RFA1SS(0004h) now when I am going to write on area 1 its asking for passwords which is by default zero so any one can write on area 1  using this st app so I want to change this RFA1SS passwords to write but don't want to use RF as medium to write only want send data through i2c from my controller to tag to change this passwords .

    ST Employee
    January 19, 2024

    Hi, 

    Ok. Unfortunately, as I said in my previous post, you cannot change any RF password from the I2C interface. The only way is using the RF command Write Password.

    Best reagrds.

    PoolBearAuthor
    Graduate II
    January 19, 2024

    Hello @Rene Lenerve  @JL. Lebon  @Brian TIDAL

    did you guys have any other tag where we can do that

    JL. LebonAnswer
    ST Employee
    February 14, 2024

    Hello, 

    Sorry for my late answer, I missed your question.
    We do have the M24SR in which RF passwords can be modified from I2C interface. The M24SR is an NFC type 4 (ISO14443), so quite different from the ST25DV though.

    Best regards.