5 rtc read operation, 6 rtc date and time update – Rainbow Electronics AT73C246 User Manual
Page 133

133
11050A–PMAAC–07-Apr-10
AT73C246
TWI_WRITE DATA2 @RTC_DATA2
TWI_WRITE DATA3 @RTC_DATA3
// Set RTC_WRITE = 1 (write) and RTC_SEL = 1
TWI_WRITE 0x06 @ RTC_CTRL
// Pulse RTC_EN
TWI_WRITE 0x07 @ RTC_CTRL
TWI_WRITE 0x06 @ RTC_CTRL
// Disable RTC access
TWI_WRITE 0x00 @ RTC_CTRL
14.1.5
RTC Read Operation
The following example makes a generic 32-bit read operation into the RTC macro. The 32-bit
RTC data is split into 4 bytes, that are successively read over the TWI.
// Select RTC_ADDR = ADDR. ADDR is the RTC macro register to read,
TWI_WRITE ADDR @RTC_ADDR
// Set RTC_WRITE = 0 (read) and RTC_SEL = 1
TWI_WRITE 0x02 @ RTC_CTRL
// Pulse RTC_EN
TWI_WRITE 0x03 @ RTC_CTRL
TWI_WRITE 0x02 @ RTC_CTRL
// Read RTC_DATA0 to RTC_DATA4 registers.
TWI_READ @RTC_DATA0
// LSBs
TWI_READ @RTC_DATA1
TWI_READ @RTC_DATA2
TWI_READ @RTC_DATA3
// MSBs
// Disable RTC access
TWI_WRITE 0x00 @ RTC_CTRL
14.1.6
RTC Date and Time Update
In the following example, the RTC date and time is set to “12 October 2004, 08h 49min 59s”.
The WRITE_RTC and READ_RTC functions operate as described in the previous sections.
// Disable RTC interrupt MASK
TWI_WRITE 0xFE @PMU_MASK
// Enable RTC ACKUPD IT
@RTC_IER (RTC_ADDR 0x20).
WRITE_RTC 0x00000001 @RTC_IER
// Set UPDTIME and UPDCAL @RTC_CR (RTC_ADDR 0x00).
WRITE_RTC 0x00000003 @RTC_CR
// Wait ITB low. This ensures that the RTC is ready to be updated.
// Reset IT by read operation, result is 0x01.
TWI_READ @PMU_IT
// Read in RTC_SR that ACKUPD = 1 (RTC_ADDR = 0x18)
READ_RTC @RTC_SR
// Disable ACKUPD IT @RTC_IDR (RTC_ADDR = 0x24)
WRITE_RTC 0x00000001 @RTC_IDR
// Write Date @RTC_CALR (RTC_ADDR = 0x0C) (12 October 2004)
WRITE_RTC 0x12300420 @RTC_CALR