Adding a Real-Time Clock with I2C

We saw in the previous section how to interface a Real-Time Clock (RTC) to a microprocessor using a SPI interface. Now let’s look at how we’d do the same using the I2C interface. For this example, we’ll use the tiny Philips PCF8583. It also has 240 bytes of RAM, which, like the DS1305’s, may be used for parameter storage. Unlike the DS1305, the PCF8583 does not have an integrated battery-backup system. So, you would need to provide an external battery-backup circuit. Many other I2C RTCs are available, and some do incorporate battery-fail protection. I’ve chosen to look at this one because it makes for a very simple example of an I2C interface.

The PCF8583 has two pins (OSCI and OSCO) for connecting a 32.768kHz watch crystal. This crystal pulses an internal circuit that performs the timekeeping functions. The address pin, A0, determines the address of the device on the I2C bus. Most I2C chips provide several address pins, allowing a range of possible addresses to be wired. The PCF8583 has only one, to reduce the pin count of the chip. Six of its address bits are hardwired internally. Only the least significant, A0, is available to the system designer. The address configuration of the PCF8583 is shown in Figure 9-27. Note how the transfer direction (read or write) is incorporated into the address field.

PCF8583 addresses

Figure 9-27. PCF8583 addresses

Connecting ...

Get Designing Embedded Hardware now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.