AnsweredAssumed Answered

Using I2C_MasterTransferBlocking in fsl_i2c driver to read and write to eeprom

Question asked by D M on Jan 7, 2020
Latest reply on Mar 23, 2020 by Sabina Bruce

I am having some issues using the fsl_i2c driver for the kl03z sdk. I am trying to use the function I2C_MasterTransferBlocking from the fsl_i2c driver. I want to write data to an eeprom and then retrieve that same data later. However, I am having issues with reading the proper data back out.  In short, how do I control the exact register location that I write and read data from.
this is the code snippet that I am using.

 

 

uint8_t buf[16]; /* This buffer is populated with a string that is 16 characters*/

uint8_t  Rbuf[16];

uint8_t deviceAddress = 0x01U;
i2c_master_transfer_t xfer;
memset(&xfer, 0, sizeof(xfer));

 

/* Write Data*/
xfer.flags=kI2C_TransferDefaultFlag; 
xfer.slaveAddress= EEPROM_I2C_ADDRESS >> 1;
xfer.direction= kI2C_Write;
xfer.subaddress=(uint32_t)deviceAddress; 
xfer.subaddressSize=1; 
xfer.data=buf; 
xfer.dataSize=16;
I2C_MasterTransferBlocking(NTAG_I2C_MASTER_BASEADDR, &xfer);

 


/*Read Back the same data*/

 

 

xfer.flags=kI2C_TransferDefaultFlag; 
xfer.slaveAddress= EEPROM_I2C_ADDRESS >> 1 ;
xfer.direction= kI2C_Read; 
xfer.subaddress=(uint32_t)deviceAddress; 
xfer.subaddressSize=1; 
xfer.data=Rbuf; 
xfer.dataSize=16; 
I2C_MasterTransferBlocking(NTAG_I2C_MASTER_BASEADDR, &xfer);

Outcomes