Skip to main content
Associate III
December 3, 2024
Question

EEPROM_I2c

  • December 3, 2024
  • 2 replies
  • 937 views

I am using M24C04 chip and downloaded the software package EEPRAM2.

if(EEPRMA2_M24_Init(EEPRMA2_M24C02_0) == BSP_ERROR_NONE)
 {
	 chip_ok=1;
	 // DOUBLEFLASH();
 }
 else
 {
	 chip_ok=0;
 } 

 if I used this instance it says chip ok=1 but the  read and write not working .As using M24C04 ,I also tried the instance as

if(EEPRMA2_M24_Init(EEPRMA2_M24xx) == BSP_ERROR_NONE)
 {
	 chip_ok=1;
	 // DOUBLEFLASH();
 }
 else
 {
	 chip_ok=0;
 }

it says the chip is not working

 

2 replies

gbm
Principal
December 3, 2024

You forgot to show your code, so it's hard to help you.

Use HAL_I2C_MewWrite and MemRead family functions. They are described in HAL Reference.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
meenaAuthor
Associate III
December 3, 2024
void testEEPROM()
{



 // Write data to EEPROM
 if (HAL_I2C_Mem_Write(&hi2c1, 0x50, memAddress, I2C_MEMADD_SIZE_8BIT, dataToWrite, 2, 1000)== HAL_OK) {
 // Handle Write Error
 i2c_write=1;
 return;
 }

 // Read data from EEPROM
 if (HAL_I2C_Mem_Read(&hi2c1, 0x50, memAddress, I2C_MEMADD_SIZE_8BIT, dataRead, 2, 1000)== HAL_OK) {

 	i2c_read=1;
 return;
 }

 // Check if the written data matches the read data
 if (dataRead[0] == dataToWrite[0] && dataRead[1] == dataToWrite[1]) {
 i2c_test=1;
 } else {
 	 i2c_test=0;
 }
}

Hi I tried this to but i dont know why its not working

 

gbm
Principal
December 3, 2024

The EEPROM address should be shifted - 0xa0 instead of 0x50.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Andrew Neil
Super User
December 3, 2024

@meena wrote:

 the drivers not working for me.


What "driver"?

Hardware details?

Please see the Posting Tips:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.