cancel
Showing results for 
Search instead for 
Did you mean: 

24C02 with STM32CubeMX

Gustavo  Adono
Associate
Posted on August 25, 2017 at 13:11

Hello,I'm trying to use this code to write/read a EEPROM 24C02,but it's not working,what i'm doing wrong?

Could someone post a example please?

uint8_t eedget[1],eedata[1];

void main()

{

eedata[0] = 0x01;

eedata[1] = 0x02;

while(1)

{

HAL_I2C_Mem_Write(&hi2c1,0x00A0,0x0000,0x0008,eedata,1,1000);

HAL_I2C_Mem_Read(&hi2c1,0x00A1,0x0000,0x0008,eedget,1,1000);

}

}

2 REPLIES 2
S.Ma
Principal
Posted on August 25, 2017 at 20:14

If sending 8 bytes, make the array exist for the 8 bytes...

uint8_t eedget[8],eedata[8];

who said the memory locations after the reserved one for the array exist in the SRAM?

Check the input parameter of the function, to write from location 0x00 the value 0x01 you need to write S.A0a.00a.01a.P (wait 10 msec) S.A0a.00a.S.A1.a.xx.n.P where xx is expected to be 0x01.

Try to to use a fixed value as if it works once and fail the next, you won't detect it. 

Read the byte, XOR 0xFF then write the value back. Everytime you run the code, you will be able to make sure, even if you power off the application.... 

Imen.D
ST Employee
Posted on September 07, 2017 at 11:50

Hello,

Have a look to the

https://community.st.com/0D50X00009XkW1qSAF

,

it may be helpful.

You have a full set of running

I2C EEPROM

examples within the STM32Cube firmware package.

BestRegards

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen