2024-06-12 08:11 PM - edited 2024-06-17 08:27 PM
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.
2024-06-13 12:00 AM
Firstly, please increase R1 and R2 to 3.3k-4.7k and connect them to VDD (+3.3V).
Regards
/Peter
2024-06-13 01:11 AM - edited 2024-06-13 01:11 AM
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.
2024-06-13 01:35 AM
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
2024-06-14 06:16 AM - edited 2024-06-14 06:45 AM
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?
2024-06-14 08:48 AM
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);
2024-06-14 02:24 PM
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);