cancel
Showing results for 
Search instead for 
Did you mean: 

EEPROM Reads only last Write Value

PMOHO.1
Associate II

Im working on stm32l4 series ,using external eeprom , eeprom writes four variables in 4 EEPROM addresses succesfully,but while reading EEPROM it only reads last (4th) variable on all 4 EEPROM address,Im try all methods adjusting delay ,EEPROM addresses,Device address of I2C but same problem occurs ,Please help me & Thanks in Advance for your suggetions

4 REPLIES 4
Piranha
Chief II

Probably you are actually writing and reading a single variable...

PMOHO.1
Associate II

No I'm writing & reading on 4 different variable

PMOHO.1
Associate II

Here is my code,

while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

//EEPROM Write code

 uint8_t ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 10, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &shift_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, shift_flag);

 printf("%x\r\n", I2C1_EEPROM_ADDR);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 20, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &onoff_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, onoff_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 30, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream1_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, Stream1_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 40, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream2_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, Stream2_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 50, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &fire_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, fire_flag);

 HAL_Delay(2000);

 shift_flag = 0;

 onoff_flag = 0;

 Stream1_flag = 0;

 Stream2_flag = 0;

 fire_flag = 0;

//Reading EEPROM code :

 uint8_t g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 10, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &shift_flag, 2, 0xFF);

 printf("%d %d\r\n", g, shift_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 20, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &onoff_flag, 2, 0xFF);

 printf("%d %d\r\n", g, onoff_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 30, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream1_flag, 2, 0xFF);

 printf("%d %d\r\n", g, Stream1_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 40, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream2_flag, 4, 0xFF);

 printf("%d %d\r\n", g, Stream2_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 50, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &fire_flag, 4, 0xFF);

 printf("%d %d\r\n", g, fire_flag);

 HAL_Delay(10);

Here is Print Values:

Scanning I2C bus:

...............................................................................0x500x510x520x530x540x550x560x57........................................

0 10

0 20

0 30

0 40

0 50

//below are EEPROM Read Values

0 50

0 50

0 50

0 50

0 50

// EEPROM only reads last(5th) values in all EEPROM addressses,Please give me any suggetions

No I'm writing & reading on 5 different variable

Here is my code,

while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

//EEPROM Write code

 uint8_t ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 10, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &shift_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, shift_flag);

 printf("%x\r\n", I2C1_EEPROM_ADDR);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 20, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &onoff_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, onoff_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 30, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream1_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, Stream1_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 40, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream2_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, Stream2_flag);

 HAL_Delay(10);

 ret = HAL_I2C_Mem_Write(&hi2c1, I2C1_EEPROM_ADDR, 50, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &fire_flag, 4, 0xFF);

 printf("%d %d\r\n", ret, fire_flag);

 HAL_Delay(2000);

 shift_flag = 0;

 onoff_flag = 0;

 Stream1_flag = 0;

 Stream2_flag = 0;

 fire_flag = 0;

//Reading EEPROM code :

 uint8_t g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 10, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &shift_flag, 2, 0xFF);

 printf("%d %d\r\n", g, shift_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 20, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &onoff_flag, 2, 0xFF);

 printf("%d %d\r\n", g, onoff_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 30, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream1_flag, 2, 0xFF);

 printf("%d %d\r\n", g, Stream1_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 40, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &Stream2_flag, 4, 0xFF);

 printf("%d %d\r\n", g, Stream2_flag);

 HAL_Delay(10);

 g = HAL_I2C_Mem_Read(&hi2c1, I2C1_EEPROM_ADDR, 50, I2C_MEMADD_SIZE_16BIT,(uint8_t *) &fire_flag, 4, 0xFF);

 printf("%d %d\r\n", g, fire_flag);

 HAL_Delay(10);

Here is Print Values:

Scanning I2C bus:

...............................................................................0x500x510x520x530x540x550x560x57........................................

0 10

0 20

0 30

0 40

0 50

//below are EEPROM Read Values

0 50

0 50

0 50

0 50

0 50

// EEPROM only reads last(5th) values in all EEPROM addressses,Please give me any suggetions