With a little tinkering i was able to move the BQ32000 I2C RTC to Port.C. And that's working beautifully; with hardware I2C!
The Texas Instruments BQ32000 is very nice to work with. It's largely compatible to the well-known DS1307, but runs of 3.0-3.6V. Furthermore it has a nice correction feature so one can adjust timekeeping from -63 .. +126ppm. It basically skips or adds counts once-in-a-while. It also has a 1Hz or 512Hz output. The 1Hz is affected by the timekeeping adjustment, so it's accurate and can be used well for generating interrupts. The 512Hz option is not adjusted. It can therefore be routed to a frequency counter to determine what the correction should be.
Also it can be backed by a primary- or rechargeable battery or a super capacitor. It has switching an charging circuitry on board.
It's only available as a SMD SOIC-8. (But SOICs are very easy to solder by hand..)
Only one tip: With the XMEGA, do indeed make sure to use 'I2Crepstart' where applicable.
Here's a little sample code. It reads the RTC to variables.
[code:1:095ca6f3b7]Read_RTC:
'Reads time and date from I2C and copy it to system RTC
I2cstart ' Generate start code
I2cwbyte RTCw ' send address
I2cwbyte 0 ' start address in BQ32000
I2crepstart ' Generate start code
I2cwbyte RTCr ' send address
I2crbyte tempb3 , Ack 'seconds
RTC_stop = tempb3 AND &B10000000 'Just D7
RTC_sec = tempb3 AND &B01111111
RTC_sec = Makedec(RTC_sec)
I2crbyte tempb3 , Ack ' minutes
RTC_osc_fail = tempb3 AND &B01111111 'Just D7
RTC_min = tempb3 and &B01111111
RTC_min = Makedec(RTC_min)
I2crbyte tempb3 , Ack ' Hours
RTC_Cent_EN = tempb3 AND &B10000000
RTC_Cent = tempb3 AND &B01000000
RTC_hour = tempb3 AND &B00111111
RTC_hour = Makedec(RTC_hour)
I2crbyte tempb3 , Ack ' Day of Week
RTC_Weekday = tempb3 AND &B00000111 'D7-D3 are and should always remain zero BCD convertion not needed; already binary
I2crbyte tempb3 , Ack ' Day of Month
RTC_day = tempb3 AND &B00111111 'D7-D6 reserved and should remain zero
RTC_day = Makedec(RTC_day)
I2crbyte tempb3 , Ack ' Month of Year
RTC_month = tempb3 AND &B00011111 'D7-D5 reserved and should remain zero
RTC_month = Makedec(RTC_month)
I2crbyte tempb3 , Ack ' Year
RTC_year = Makedec(tempb3)
I2crbyte RTC_CAL_CFG1 , NACK 'Subsequent reading of trickle charge registers is skipped. CAL_CFG1 sets 1Hz/512Hz output and ppm correction
I2cstop
return
[/code:1:095ca6f3b7]
↧