Issues with Writing to BR24G512-3A EEPROM using nrf_drv_twi_xfer

Hello,

I'm currently working with a BR24G512-3A external EEPROM and attempting to write and read data using the nrf_drv_twi_xfer function on my nRF52 series board. Although the logic analyzer shows an ACK for both write and read operations, the data read back is not what was written.

Here's what the logic analyzer confirms:
- Write operation: ACK received
- Read operation: ACK received

Expected read data (hex):
41 42 43 44 45 00 00 00

Actual read data (hex):
00 00 00 00 00 00 00 00
00 FF FF FF FF FF FF FF

Below is the code snippet I'm using for the write and read operations. I use nrf_delay_ms(100) after writing to ensure the write cycle time is respected. Despite this, the read operation does not yield the expected results.

void write_record(void)
{
    ret_code_t err_code;
    static uint8_t address[2] = {0x00, 0x05}; // 2-byte write address for the data destination

    // Create the transfer description for sending the address
    nrf_drv_twi_xfer_desc_t xfer_address = {
        .type = NRF_DRV_TWI_XFER_TXTX,     // Operation type: Transmission
        .address = MEM_DEVICE_ADDRESS,     // Device address
        .primary_length = sizeof(address), // Address buffer size
        .p_primary_buf = address,          // Address buffer
        .p_secondary_buf = txbuffer,
        .secondary_length = 5};

    // Start the address transfer
    m_xfer_done = false;
    err_code = nrf_drv_twi_xfer(&m_twi, &xfer_address, 0);

    while (!m_xfer_done)
        ; // Wait for the address transfer completion

    nrf_delay_ms(100);

    nrf_drv_twi_xfer_desc_t xfer2 = {
        .type = NRF_DRV_TWI_XFER_TXRX,     // Operation type: Transmission
        .address = MEM_DEVICE_ADDRESS,     // Device address
        .primary_length = sizeof(address), // Address buffer size
        .p_primary_buf = address,          // Address buffer
        .p_secondary_buf = rxbuffer,
        .secondary_length = 32};

    // Start the address transfer
    m_xfer_done = false;
    err_code = nrf_drv_twi_xfer(&m_twi, &xfer2, 0);

    while (!m_xfer_done)
        ;

    NRF_LOG_HEXDUMP_INFO(rxbuffer, 32);
}

Questions:
1. Is there a specific sequence or timing I need to follow when using nrf_drv_twi_xfer for EEPROM operations that I might be missing?
2. Could there be a need for additional delay between the write and read operations, or is there a buffer or cache that needs to be cleared?
3. Does the BR24G512-3A require any special considerations or commands prior to writing or reading that are unique from other EEPROMs?

The data sheet for the external memory: BR24G512-3A Series: Serial EEPROM (rohm.com)

Any insights or suggestions would be greatly appreciated as I am unsure why the written data is not being read back correctly.

Thank you!

  • Hello,

    A few things I would have checked. 

    1. Compare on a logic analyzer the actual i2c commands for write/read/erase and compare with the datasheet.

    2. Make sure that the write protect pin is not enabled.

    3. It may be a good idea to erase before writing, typically you can write '0' but not '1', so if you want to write a byte, make sure that the area you are writing to is is all FFFF... before writen a value.

    Kenneth

Related