Vibrant2020
Newbie level 6
Hi all,
I am facing trouble in reading AT24C32 EEPROM from PIC MCU over I2C.
EEPROM : AT24C32
PIC MCU: PIC16F1938
I2C Module Interface
IDE: MPLAB V8.60
COMPILER : HI TECH C
The code is as follows:
If I run this code, I am able to get only up to 170 bytes from EEPROM. If I replace the "k" with "j" in the for loop, i am able to read entire bytes (288 bytes) in pagewise. That is, put break point in debugging mode at the line "j = 0", the data read per page and displayed correctly.
What could be the problem? Am I missing anything in the code?
Advance thanks
Vibrant2020
Added,: There are 300 bytes available in the EEPROM.
I am facing trouble in reading AT24C32 EEPROM from PIC MCU over I2C.
EEPROM : AT24C32
PIC MCU: PIC16F1938
I2C Module Interface
IDE: MPLAB V8.60
COMPILER : HI TECH C
The code is as follows:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 unsigned char EEPROM_ADDR; unsigned long chrData[300]; void ReadXTEEPROM(void){ unsigned long k = 0; for(int i = 0; i < 9; i++){ EEPROM_ADDR = i * 32; I2C_Master_Start(); I2C_Master_Write(0xA0); I2C_Master_Write((EEPROM_ADDR >> 8) & 0xFF); I2C_Master_Write((EEPROM_ADDR) & 0xFF); I2C_Master_RepeatedStart(); I2C_Master_Write(0xA1); long j; for(j = 0; j < 32; j++){ // 32 bytes / page chrData[k] = I2C_Master_Read(0); // ACK k++; } chrData[k] = I2C_Master_Read(1); //NACK j = 0; I2C_Master_Stop(); __delay_ms(10); } k = 0; }
If I run this code, I am able to get only up to 170 bytes from EEPROM. If I replace the "k" with "j" in the for loop, i am able to read entire bytes (288 bytes) in pagewise. That is, put break point in debugging mode at the line "j = 0", the data read per page and displayed correctly.
What could be the problem? Am I missing anything in the code?
Advance thanks
Vibrant2020
--- Updated ---
Added,: There are 300 bytes available in the EEPROM.