;
; utility routine to talk to an ADC1034
; - asumptions - CS/OE are wired together to P1.0
; - Cclk/Sclk is wired to P1.1
; - DO is wired to P1.2
; - DI is wired to P1.3
;
; P1.0 must be high when not in use, P1.1-P1.3 are available when P1.0 is high
; and it is only ever pulled low while in this routine so they are free at all
; other times to be used by other devices that can be put into quiescent modes
; while this one is active
;
; calling conventions:
; always clear carry on return
; a, r1, r2 are available
; r0 lsbs contains adc index
; result is returned in r1:r0 (2 msbs in R1, 8 LSBs in R0)
;
; This is highly unoptimised - and could run twice as fast if transactions were pipelined
; but then the programming interface would be much more difficult
;
; Current time spent in here is ~300uS/conversion so you can get ~3000 samples/sec
; probably more than enough for a rocketry related datalogger - or even maybe
; for engine monitoring
;
;
get_1034:
mov a, r0 ; make it <1><0><0><0><0>
rl a
orl a, #1 ; set big-endian mode
anl a, #0xf
swap a
push acc
acall talk_1034 ; once to send the address
pop acc
talk_1034: ; and a second time to get good data
setb p1.2 ; listen here
clr p1.1 ; clock to 0
mov r2, #6
clr p1.0 ; oe/cs enabled - start transaction
loop1: rlc a ; loop sending 6 bits of data (inc 2 bits of 0)
mov p1.3, c ; send data bit
setb p1.1 ; clock it
clr p1.1
djnz r2, loop1
setb p1.3 ; turn it off
mov r2, #2 ; read 2 MSBs into r0
clr a
loop2: mov c, p1.2 ; sample it
setb p1.1 ; clock it
rlc a ; shift it
clr p1.1
djnz r2, loop2
mov r1, a
mov r2, #8 ; and the next 8 into r1
loop3: mov c, p1.2
setb p1.1 ; clock it
rlc a
clr p1.1
djnz r2, loop3
mov r0, a
setb p1.0 ; oe/cs disabled
mov r2, #(41-8)/4+1
loop4: ; and allow the next conversion to complete
setb p1.1 ; clock it
clr p1.1
setb p1.1 ; clock it
clr p1.1
setb p1.1 ; clock it
clr p1.1
setb p1.1 ; clock it
clr p1.1
djnz r2, loop4
setb p1.1 ; clock to 0
clr c
ret