cancel
Showing results for 
Search instead for 
Did you mean: 

Communication between STM32C011 and EEPROM M24C0

HauDO
Associate II

Chào bạn,

Tôi đã thiết lập kết nối theo sơ đồ và tôi đã tải mã trong tệp đính kèm nhưng tôi không thể đọc dữ liệu từ EEPROM. Địa chỉ M24C02 của tôi được đặt thành 0xA0.

Ai đó có thể giúp tôi xác định vấn đề? Cảm ơn rất nhiều.

 

HauDO_1-1718248224550.png

 

6 REPLIES 6
Peter BENSCH
ST Employee

Firstly, please increase R1 and R2 to 3.3k-4.7k and connect them to VDD (+3.3V).

Regards
/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Dear Peter,

I have already replaced the resistors R1 and R2 with values of 4.6K, but it still doesn't work. I think the issue might be with the software. I am using the "HAL_I2C_Mem_Write" and "HAL_I2C_Mem_Read" functions from the HAL library.

My code looks like this, but I still can't communicate with the M24C02HauDO_0-1718266257022.png

 

 


 

Peter BENSCH
ST Employee

Please check again whether you have also connected R2 to VDD, as it is still connected to GND in your schematics.

After a quick look at your main.c, I noticed that you consistently ignore the return values of the HAL calls. Please bear in mind that unforeseen things can happen when controlling external devices, especially EEPROMs, e.g. a write process that takes a long time.

Perhaps a look at X-CUBE-EEPRMA1 is helpful, where you can see how this is implemented.

Regards
/Peter

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Techn
Senior

Check the i2c status

while(HAL_I2C_IsDeviceReady(&hi2c1, EEPROM_ADDR,10, HAL_MAX_DELAY));

set the i2c frequency as 100khz

Please note that the page size is only 16 bytes, so when you want to write 100 bytes, the page changes.... after each page write, you have to give the write delay or poll the status.

So first you can try to do a byte write and read with 0x55 and see how it happens. it takes 5 ms to write complete

btw, Why do you have different EEPROM address  as CALIB_EEPROM_WR and RD?

you can try this snippet and see if you get back what is written into location zero..

while(HAL_I2C_IsDeviceReady(&hi2c1, EEPROM_ADDR,10, HAL_MAX_DELAY));
uint8_t Wvalue = 25;
HAL_I2C_Mem_Write(&hi2c1, EEPROM_ADDR, 0, 1,&Wvalue , 1, 1000);
HAL_Delay(10);
while(HAL_I2C_IsDeviceReady(&hi2c1, EEPROM_ADDR,10, HAL_MAX_DELAY));
uint8_t Rvalue = 0;
HAL_I2C_Mem_Read(&hi2c1, EEPROM_ADDR, 0, 1,&Rvalue , 1, 1000);

Karl Yamashita
Lead II

You say the slave address is 0xA0. But how are CALIB_EEPROM_WR and CALIB_EEPROM_RD defined?

 

You should only have one define. The HAL driver will automatically set the read bit, but it does require the slave address be shifted left by 1 like so...

#define CALIB_EEPROM (0xA0 << 1)

HAL_I2C_Mem_Write(&hi2c1, CALIB_EEPROM, 100, 4, dataWrite, 4, 1000);