Can't get expected results working with external memory with I2C
Hello people from ST community,
I'm here today talking about I2C, starting to working on it and wanted to see if I could fix an issue telling you my experience with an external EERAM memory, the 47L16 EERAM from Microchip. My board is a Nucleo F411RE
I am currently able to talk to the device according to my code output and previous testing. But I am trying to doing a write a byte to the SRAM (0x22) and then read it back from the same memory address but and I am unable to get to work properly, I always get 0xFF as response in my UART output prints...
in HAL_I2C_Mem_Read() function, is the 5th parameter (pData, pointer to the data buffer) the data buffer that will hold the response from the slave devices (EERAM memory)? What should I do in order to do this process?
I think I am missing something important to get this properly working. Thank you so much in advance for any incoming ideas.
// EERAM Tasks
// write to the 0x10 register
uint8_t buf[15] = {0}; // buffer to print data at the end
uint8_t pdata[1] = {0x22}; // write in the SRAM
uint8_t output[1] = {0}; // store value read from SRAM
const uint16_t ADDR_WRITE = 0xA0; // device slave address to write
const uint16_t ADDR_MEMORY = 0x10; // memory address to write to
// write 0x22 to the SRAM
ret = HAL_I2C_Mem_Write(&hi2c1, ADDR_WRITE, ADDR_MEMORY, 1, pdata, 1, HAL_MAX_DELAY);
if(ret != HAL_OK) {
DebugStringOut(&huart2, "Error Tx 1\r\n");
}
else {
// read 0x22 from SRAM
const uint16_t ADDR_READ = 0xA1; // device slave address to read
ret = HAL_I2C_Mem_Read(&hi2c1, ADDR_READ, ADDR_MEMORY, 1, output, 1, HAL_MAX_DELAY);
if(ret != HAL_OK) {
DebugStringOut(&huart2, "Error Rx\r\n");
}
else {
sprintf((char*)buf, "rx->%d\r\n", output[0]);
DebugStringOut(&huart2, (char*)buf);
}
}