Atmel AT24C32 on DS3231 RTC board. Can read / write clock but not EEPROM.
I bought a DS3231 RTC with on board Atmel AT24C32 EEPROM to learn I2C communication.
My processor is PIC18F4550 and I'm using RS232 to display data on a PC terminal screen.
I have no problem reading and writing to the DS3231 but cannot read or write to the EEPROM. I have looked at lots of example code but it is mainly for arduino and everything is hidden in their library. I have found very little for PIC micros.
One thing I will note is that the Atmel data sheet says there is internal circuitry to pull A2, A1 and A0 low if they are not connected. However looking at my board which has no resistors on these three lines it looks like they are set up for pull down not pull up. Using a DVM the pins show logic high so I assume the data sheet is wrong and my address is 0x57 not 0x50 (using the "shift left 1 bit and append R/W bit" address function). Either way I have tried both addresses and neither gives sensible results.
I have stripped my program right down and made it a one file project so that I can attach it here. Note that most of it is for printing out the time from the DS3231 so that I can prove I2C is working.
The program has a loop i = 0 to 7 which tries to write i squared to the EEPROM.
A second loop tries to read the values back and print the values on the screen. The read back values appear to be the memory address values, 0 to 7, rather than the desired data values.
Finally if I add " while (ACKSTAT); " to the i2c_Wait routine then chip address 0x57 finishes whereas 0x50 stops at the first line so I assume this means 0x57 is the correct address.
If someone would kindly look over my code and tell me what I am doing wrong (just the EEPROM parts :-)) it would be much appreciated.