• AVR Freaks

Hot!Atmel AT24C32 on DS3231 RTC board. Can read / write clock but not EEPROM.

Author
Archie_99
New Member
  • Total Posts : 2
  • Reward points : 0
  • Joined: 2016/11/27 11:14:57
  • Location: 0
  • Status: offline
2020/03/29 12:33:58 (permalink)
0

Atmel AT24C32 on DS3231 RTC board. Can read / write clock but not EEPROM.

Hi,
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.
Thank you.
#1

2 Replies Related Threads

    ric
    Super Member
    • Total Posts : 27115
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Atmel AT24C32 on DS3231 RTC board. Can read / write clock but not EEPROM. 2020/03/30 14:28:09 (permalink)
    0
    Archie_99
    ...
    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.

    I'm not sure what your main problem is, but this statement implies you have made the same mistake about ACKSTAT that everyone does when they first implement I2C.
    NEVER wait on ACKSTAT.
    After sending a byte to the slave, wait until the transfer completes (which you are doing), then read ACKSTAT once.
    If it's low, you got an ACK, and can proceed.
    If it's high, you got a NAK, which means there is no-one listening. Abort the transaction, send a STOP, and report an error to the user (i.e. you), so you can check what's wrong.
    I agree, it sounds like 0x57 is the active address.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #2
    Archie_99
    New Member
    • Total Posts : 2
    • Reward points : 0
    • Joined: 2016/11/27 11:14:57
    • Location: 0
    • Status: offline
    Re: Atmel AT24C32 on DS3231 RTC board. Can read / write clock but not EEPROM. 2020/03/31 04:02:05 (permalink)
    0
    Hi Ric,
    Thanks for having a look.
    #3
    Jump to:
    © 2020 APG vNext Commercial Version 4.5