Tuesday, January 31, 2012

MKHBC-8-R1 and RTC DS-1685 or interfacing mux-bus intel architecture chip to 6502.

I still can not overcome my laziness and start to assemble my messy bread board creation on some prototyping boards. Instead, I wanted a real time clock interfaced to my home brew computer so I could have some new hardware to write driver software for. Some time ago I bought this RTC chip from Maxim: DS1685. I didn't think at the time of any particular use for it. Just wanted to have such chip for my 8051 projects in case I needed one, in my drawer. This particular chip has bus interface compatible with multiplexed address/data bus, just like Intel/8051 architecture.  This fact posed a little bit of an issue with this project, because I wanted to connect this chip to my buffered I/O bus of MKHBC-8-R1, a separate address/data lines bus (non-multiplexed). After several failed schematics drawings, which involved using latches and sequential logic to generate appropriate signals with proper timing to strobe ALE pin and latch the address/data from 6502 non-multiplexed bus in a manner that could be understood by DS1685, I decided that there must be some easier way. Short session with Google and I came across Maxim's application note 326 for chips DS-2141A, DS-2143 and such. It presented the interface so simple, I could not believe it. It required some extra programming effort, since addressing the registers of the chip with this solution would require sending registers addresses as a regular data to I/O port. Nevertheless, it was much simpler, than doing full blown transparent hardware interface. It was too good to be true, though. It did not work. Intel-like chips do not suffer 6502 bus in some cases. I got the circuit assembled on a bread board (of course :-)) next to my LCD interface and got some test program done quickly to see if this would work. Unfortunately I could not get any data in or out of the chip. After thorough analysis of my code I decided it was OK, it must have been the hardware. My guess was, the timing was not right for reads and writes, although simple 3-nand gate glue logic worked OK for generating strobe signal for ALE pin of DS1685. After hours of tinkering, slowing down CPU clock, assembling ad hoc glue logic variants it "suddenly" hit me: it was Intel vs. 6502 bus - it did not like Phi2 synchronized signals! You see, I had my /WE and /OE Phi2 synchronized signals connected to /WR and /RD signals of DS1685. This did not work. Data were not there at the time the read/write signals were toggled. I quickly modified my circuit to use 6502's R/W signal directly for /WR of DS1685 and negated for /RD and it worked! Here is the modified interface:


Figure 1: Interfacing 6502/MKHBC-8-R1 buffered I/O bus to multiplexed bus type chip DS1685. Signal IO4 is an active low chip select signal from my I/O address decoder.

Glue logic can be done with just one 74LS00. My messy board uses extra inverter from 74LS04 because one 7400 gate is already taken by LCD interface on the same bread board (inverting of /CS signal, LCD has E-pin active HI).
With above solution, accessing registers of the RTC is done in two steps:
1) Sending register address (8-bit value) to I/O 4 port (odd address bytes).
2) Sending or reading data to/from I/O 4 port (even address bytes).

Example:

IOBase = $c000
IO4 = IOBase+4*256


DSCALADDR    =    IO4+1
DSCALDATA    =    IO4

;-------------------------------------------------------------------------------
; Write DS1685 address (Acc).
;-------------------------------------------------------------------------------


WrRTCAddr:
    sta DSCALADDR
    rts




;-------------------------------------------------------------------------------
; Write DS1685 data (Acc).
;-------------------------------------------------------------------------------


WrRTCData:
    sta DSCALDATA
    rts


;-------------------------------------------------------------------------------
; Read DS1685 data (-> Acc).
;-------------------------------------------------------------------------------


RdRTCData:
    lda DSCALDATA
    rts


;-------------------------------------------------------------------------------
; Write DS1685 Acc = Addr, X = Data
;-------------------------------------------------------------------------------


WrRTC:
    jsr WrRTCAddr
    txa
    jsr WrRTCData
    rts


;-------------------------------------------------------------------------------
; Read DS1685 Acc = Addr -> A = Data
;-------------------------------------------------------------------------------


RdRTC:
    jsr WrRTCAddr
    jsr RdRTCData
    rts

Some pictures of prototype:


Figure 2: RTC and LCD interfaces on bread board connected to buffered I/O bus. Program runs displaying seconds, minutes and hours read from RTC (hexadecimal for now) in endless loop.

Figure 3: Main board (left), buffered I/O (center) and UART (right).


I admit, I am not religious about quality of my connections. I should be more neat, even with prototyping. I get pretty anxious to get things done quickly when I get some idea and this is where the mess happens :-) . I am surprised this thing even works. It is enough to touch the wires in the wrong area to have all sorts of issues with serial communication. This thing is very sensitive. Currently I supply power to the boards from my old ATX power supply and the 7805 with big heat sink you see on the screen is not in use. It was getting awfully hot while working. I believe this is normal since the whole computer does not consume more than half amp., probably less (I need to take a measure when the thing is built on boards). But for now I just do not want any fire resulting from my hobby.

That's it for today. I have CF card interface in mind now. Just after I finish driver for this calendar/clock chip and have some chips assembled on real boards hopefully soon.



No comments:

Post a Comment

Reset And Panic Buttons, Buttons Debouncing

Reset And Panic Buttons, Buttons Debouncing The monitor program in my home brew computer has a nice debug feature. The NMI (Non-Maskab...