2014-01-08 17:05 UTC
After completing the DAC I/O board an RTC chip caught my attention. I've had a DS1685 RTC laying around for many years without really finding a good place for it. Putting it on my MC3 expansion bus sounded like fun.
The problem with the DS1685 is that is it not made for the Motorola bus. It's got a multiplexed Intel-like bus. The usual RD, WR and CS signals are there but there is also an ALE signal. The ALE serves as an address strobe input. A falling edge on the ALE causes the DS1685 to latch an 8-bit address from the data lines. Keeping the ALE high while reading and writing changes the data at the selected address.
My idea was to map the DS1685 on to two addresses. One for data access (read/write) and one for address access (write only). It sounded easy but getting the timing right was a painstaking process. Most examples on the web uses a PIA and bit-bangs the signals. I did not want to go down that route. It would mean another level of complexity and more chips than I had room for on this particular I/O card. After a lot of trial and error I got an interface that was stable. There is no complete schematic I'm afraid as this was really an on-the-fly construction with only quick notes. The main part is drawn below with my MC3 Motorola bus on the left and the DS1685 on the right. Other pins on the DS1685 was connected as described in the datasheet (crystal and battery).
The solution is a bit unconventional. ALE is only triggered when A0 is high. Reading and writing when A0 is low does not trigger ALE. The interface is a bit crude bit I like the fact that only one chip is used. I suspect the timings are a bit off and not living up to the charts in the datasheet but it works.
Not much room left on this small board.
As seen on the back of the card I was not as lucky as with the DAC and the data pins on the DS1685 did not align to my bus which resulted in many crossed wires.
To verify that all was working properly I wrote a quick test code for setting the clock and reading back the time once a second. Care must be taken to not access the clock while it is updating its contents. That will make the poor DS1685 confused and writing back strange things.
source - Program for setting time in the RTC
source - Program for displaying time in the RTC