cancel
Showing results for 
Search instead for 
Did you mean: 

24C16RP EEPROM INTERFACING WITH STM32G070CBT6

RChou.1
Associate III

Hello all,

I am trying to interface 24C16RP EEPROM with my MCU soldered on breakout board and  it seems like the EEPROM is behaving very weird when i am trying to write and read. first of all it starts to write from position 1 not from zero of an array that i have created to store the data and i tried a lot to figure out the cause but i couldn't and the weird part is that after writing to a specific page if am trying to read any other page of the entire page address it returns the same date i have written to it. As i know this EEPROM has 16 byte of page size and 128 pages correct me if i am wrong. With that said i am attaching the cube mx code and the ioc file and some screen short for your better understanding. Please help me if you find something error in my code.

Thanks

 

 

uint8_t data_Read[16];
uint8_t data_Write[16]="1234567898765432";

int main(void)
{
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_I2C1_Init();
  MX_USART1_UART_Init();

  HAL_I2C_Mem_Write(&hi2c1, 0XA0, 1, 2, data_Write, 16, 1000);
  HAL_Delay(5);
  HAL_I2C_Mem_Read(&hi2c1, 0XA0, 9, 2, data_Read, 16, 1000);
  while (1)
  {
  HAL_UART_Transmit(&huart1, data_Read, 16, 1000);
  HAL_Delay(1000);
  }
}

 

 

 

11 REPLIES 11
Pavel A.
Evangelist III

> HAL_I2C_Mem_Write(&hi2c1, 0XA0, 1, 2, data_Write, 16, 1000)

As you've mentioned above the page size of this EEPROM is 16 bytes.

What do you think will do the above code line? (write 16 bytes, from index 1) ? Is this intentional (you want to test how the wrap-around works?)

 

 

MHoll.2
Associate III

I don't understand what you try to do, but reading the datsheet of the 24C16RP, You will see that this device has only a 1 Byte Address length, so the 4. parameter has to be 1. With 2 the device will write the low part of Your address to the EEPROM!

/**
  * @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)

Martin

i want to know why it starts writing from index 1 and the data which should be written on 15th place is getting written on 0th place and if i am trying to read the data of any other page it returns me the same data.

Did You read my response?

This Eeprom has only 1 Byte of Address, to access the full 2K array you have to put the 3 high Bit's in DevAddress ( 0xA0, will give You the first 256 Byte, 0xA2 the next 256 Byte etc.)

Please read the datasheet.

Martin

I have gone through your response and  as you said i made that changes to the I2C MEM Write function but in your second response what you said is completely out of my mind so, can you please give me a short example code that will give me a clear vision.

 

uint8_t Buffer[16];
HAL_I2C_Mem_Write(&hi2c1, 0xA0, 0, 1, Buffer, 16, 100);  // write 16 Byte to first 16 Byte of EEprom
HAL_I2C_Mem_Write(&hi2c1, 0xA2, 0, 1, Buffer, 16, 100);  // write 16 Byte starting from Byte 256 of EEprom
HAL_I2C_Mem_Read(&hi2c1, 0xA0, 0, 1, Buffer, 16, 100);  // read first 16 byte from eeprom
HAL_I2C_Mem_Read(&hi2c1, 0xA2, 0, 1, Buffer, 16, 100);  // read 16 Byte starting with Byte 256 from eeprom

It means i can only access 64 pages(1024/16=64) with 0xA0 address and for the next 64 pages i have to use 0xA2 address. Please correct me if i am wrong. 

No The MemAddress is only 1 Byte, so You can access only 256 Byte with the same DevAddress  (256/16 = 16 pages).

uint8_t data_Read[16];

uint8_t data_Write[16]="hello James...!!";

HAL_I2C_Mem_Write(&hi2c1, 0xA0, 0, 1, data_Write, 16, 100);

HAL_I2C_Mem_Read(&hi2c1, 0xA0, 6, 1, data_Read, 16, 100);

It returns me the same data i saved in 0th page. When i can access 256 byte it means 16th page can be read with the same address, then why the 6th page is returning me the same data saved on 0th page.