Skip to main content
fabocode
Associate II
September 10, 2020
Question

Can't get expected results working with external memory with I2C

  • September 10, 2020
  • 1 reply
  • 889 views

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);
 }
 }
This topic has been closed for replies.

1 reply

TDK
September 10, 2020

/**
 * @brief Write an amount of data in blocking mode to a specific memory address
 * @param hi2c Pointer to a I2C_HandleTypeDef structure that contains
 * the configuration information for the specified I2C.
 * @param DevAddress Target device address: The device 7 bits address value
 * in datasheet must be shifted to the left before calling the interface
 * @param MemAddress Internal memory address
 * @param MemAddSize Size of internal memory address
 * @param pData Pointer to data buffer
 * @param Size Amount of data to be sent
 * @param Timeout Timeout duration
 * @retval HAL status
 */
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{

Your 4th parameter is incorrect. The device wants a 16 bit address. So send MemAddress=I2C_MEMADD_SIZE_16BIT.

You don't need to pass 0xA1 to write. The software will add the trailing bit for you. You can just pass 0x40.

"If you feel a post has answered your question, please click ""Accept as Solution""."