Hello Jason Blackston:
Please revise the code in the project shared with the next document:
KSDK I2C EEPROM Example
The project was for an old KSDK version but the use of the APIs should be the same.
Specifically about your code:
For ReadEEPROM():
- EEPROM I2C slave address is not required as part of the buffer. The slave I2C address is handled by the API if it is correctly specified in the device structure (i2c_device_t).
- Your both calls to _MasterReceiveData are redundant, you just need one call. Something like this:
tempBuffer[0] = HIBYTE(address);
tempBuffer[1] = LOBYTE(address);
i2c_ret2 = I2C_DRV_MasterReceiveData(I2C_EEPROM_DEVICE, &slave, tempBuffer, 2, (uint8_t*)bufferPtr, length);
or
i2c_ret2 = I2C_DRV_MasterReceiveDataBlocking(I2C_EEPROM_DEVICE, &slave, tempBuffer, 2, (uint8_t*)bufferPtr, length, 200);
If using the blocking API just pay attention to use enough timeout parameter to receive all data.
For WriteEEEPROM():
- I think the _MasterSendData calls are also redundant. One call should be enough to send EEPROM internal address and data buffer to write:
i2c_ret1 = I2C_DRV_MasterSendDataBlocking(I2C_EEPROM_DEVICE, &slave, tempBuffer, 2, bufferPtr, writeCount, 200);
- I do not see any delays. Usually EEPROM memories require some delays waiting for the write cycle to finish.
I hope this helps you to move forward.
Best Regards!
Jorge Gonzalez
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------