Searching \ for '[PIC]: Talking to DS1616: Help!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=pic
Search entire site for: 'Talking to DS1616: Help!'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: Talking to DS1616: Help!'
2002\01\15@111455 by Michael Vinson

picon face
Hi everyone! I have recently been working with the DS1616, a very
cool chip that logs temperature and up to 3 additional ADC inputs,
storing everything in user-configurable NV memory, including
computing a histogram on the fly! It has upper and lower alarm
limits, an RTC, configurable interrupt, etc. etc. Very cool. I am
using it to make a little portable weather station. For now my
scaled-down version will only record temperature and light level,
later humidity, barometric pressure, precipitation, wind direction
and speed, etc. I'm using a 16F877 to talk to it via the 3-wire
(reset, clock, data) synchronous protocol. I also have a 2 x 16
LCD and 16-key keypad connected for user interaction. This is a
one-off hobby project.

My problem: I seem to be able to talk *to* the DS1616 with no
problem, by manually putting data on the i/o (data) pin and
pulling the clock up and back down (being careful of r/m/w
issues by using a shadow register on the PIC), but something weird
happens when I try to get data *from* the DS1616.

Here is what happens: If I write, say, 0x0FF to one of the NV
user registers, when I read it back I get 0x0FE. *Even* numbers
*always* read back correctly, but *odd* ones *never* do. Here are some
more examples so you can see the pattern:

0x0FF comes back as 0x0FE [in binary, 1111 1111 becomes 1111 1110]
0x025 comes back as 0x092 [in binary, 0010 0101 becomes 1001 0010]
0x01  comes back as 0x080 [in binary, 0000 0001 becomes 1000 0000]
0x03  comes back as 0x0C0 [in binary, 0000 0011 becomes 1100 0000]
0x011 comes back as 0x088 [in binary, 0001 0001 becomes 1000 1000]
0x055 comes back as 0x0AA [in binary, 0101 0101 becomes 1010 1010]
0x05  comes back as 0x082 [in binary, 0000 0101 becomes 1000 0010]
0x71  comes back as 0x0B8 [in binary, 0111 0001 becomes 1011 1000]

Do you see the pattern? Looks like it cuts off any lowest-significance
1s, until it gets to the first 0, then reads in correctly, filling in
at the end (i.e. the most significant bits) with as many 1s as were
truncated at the low-significance end. I should mention that the
DS1616 reads and sends 8-bit bytes with the lowest-signficance
bit (bit 0) first.

(One other thing to mention, which may be relevant with regard to
the shifted-in high-order bits, is that the "read page" command will
continue to send data from the DS1616 as long as the reset pin is
held high and clocks are presented to the clock line, taking data
from successive memory locations. Oddly, though, the "extra" bits
that are shifted in (equal in number to the number of low-order 1s
that were skipped) are always 1, even if the following memory location
should have 0 in it. I think.)

What is going on? Here is a piece of my "read byte" code:

-----------------------------------------------------------
updateA macro              ; Macro to update port A from
       movf    shportA,w  ;  shadow register, shportA
       movwf   PORTA
       endm

;***** Bit definitions
; Port A:
#define sclk  0
#define rst   1
#define io    5

[...]

;********************** Read byte from DS1616 **********************
; Uses "Read Page" command, $33. Address in dsAddr, dsAddrH, data
;  ends up in dsData
dsRead
       clrf    shportA     ; Make sure all pins low except rst
       bsf     shportA,rst ; Pull rst high to start command
       updateA
       movlw   0x033     ; read page command is $33
       call    sendW     ; send command to ds1616
       movf    dsAddrH,w ; $33 command wants 16-bit address
       call    sendW     ; High-order byte first
       movf    dsAddr,w  ; Now low-order byte
       call    sendW

       bsf     STATUS,RP0  ; select bank 1 for TRIS register
       bsf     TRISA,io    ; make io pin an input
       bcf     STATUS,RP0  ; back to bank 0
       clrf    dsData      ; set data byte initially to 0
;
; The last communication with the DS1616 was sending the low-order byte
;  of the address for the "send page" command. The last thing it did
;  was cycle the sclk (clock) line high and then low. According to
;  the DS1616 data sheet, the next action of the DS1616 is to put the
;  first bit (bit 0) of the data to be read on the i/o pin.
;
       btfsc   PORTA,io     ; bit 0 should be waiting for us
       bsf     dsData,0     ; Bit 0 = 1? If so, set it
       bsf     shportA,sclk ; Now cycle the clock high
       updateA
       bcf     shportA,sclk ; Bring clock back low
       updateA
       nop                  ; Just to be sure

; Done with bit 0. Now read bit 1. Someday I'll make this a loop.

       btfsc   PORTA,io     ; Now check if bit 1 is high?
       bsf     dsData,1     ; Yes, so set it
       bsf     shportA,sclk ; Now cycle the clock high
       updateA
       bcf     shportA,sclk ; Bring clock back low
       updateA
       nop                  ; Just to be sure

[ Code continues to shift the bits in one-by-one by
 repeating the previous 7 lines (with successive
 bits of dsData being set as needed) 5 more times. Then:]

; Read last bit:
       btfsc   PORTA,io
       bsf     dsData,7
       nop

; All done, now clean up and get out:

       bsf     STATUS,RP0  ; select bank 1 for TRIS register
       bcf     TRISA,io    ; set io line back to 0 (output)
       bcf     STATUS,RP0  ; back to bank 0

       bcf    shportA,io     ; just to make sure
       bcf    shportA,rst    ; at end of command, pull rst back low
       updateA
       return

-----------------------------------------------------------

So, any ideas? The "sendW" subroutine just shifts out the
bits in the W register one-by-one to the i/o pin, cycling the
clock as it goes (via the shadow register), without touching
the rst line. I know sendW works because I can send data
reliably *to* the DS1616 (I can test it by having it flash
some external LEDs or setting or clearing the interrupt pin
on the DS1616).

I just can't figure this one out. I feel like I've solved much
harder problems on my own before, but this one has got me
stumped. Especially the weird shifting it does on odd numbers.

Thank in advance for any help!!!!!!!!

Michael V

Thank you for reading my little posting.




_________________________________________________________________
Join the world s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2002\01\16@014743 by Heinz Czychun

flavicon
face
Hi Michael,



At 8:05 AM -0800 1/15/02, Michael Vinson wrote:

...<snip>...

>
>What is going on? Here is a piece of my "read byte" code:

....<more snipped>...

>; The last communication with the DS1616 was sending the low-order byte
>;  of the address for the "send page" command. The last thing it did
>;  was cycle the sclk (clock) line high and then low. According to
>;  the DS1616 data sheet, the next action of the DS1616 is to put the
>;  first bit (bit 0) of the data to be read on the i/o pin.

       I think this may be part of the problem.....

       If the DS1616 is like the DS1620 then bit 0 isn't waiting but
must be clocked out. sclk must be high when entering the read
routine, and then  brought low. The io bit can then be read into the
PIC. I think your out of sync by one clock.

{Quote hidden}

Also, if I may be so bold, here are my* read and write routines in
the form of a loop......

* Note: This is converted from a 12c509 fan controller done by Peter
Lynch in August 1998

;_____________________________________________
;       DS1620 Routines
;
; Basic write routine to output 8 bits
; to the DS1620
; the byte to send is in the txByte register
;_____________________________________________
;
DS1620wrt
;
       movlw   0x08            ;
       movwf   bitCount        ;setup transmit count for 8 bits
;
; write loop
;
DSwrtLoop
       bcf     DS1620_CLK      ; clock low
       bcf     DS1620_DQ       ; data bit lead low
       btfsc   txByte, 0       ; check if bit to be transmitted is low
       bsf     DS1620_DQ       ; no, then data bit lead high
                               ; yes, leave lead low
       nop                     ; short wait
       bsf     DS1620_CLK      ; clock bit into DS1620 on rising edge

       rrf     txByte, F       ; right shift transmit bit
       decfsz  bitCount, F     ; decrement bit count
       goto    DSwrtLoop       ; do it again, if bit count not zero
                               ; continue on bit count = zero
       return
;_____________________________________________
;
; Basic read routine, reads 8 bits of data from DS1620
; First the read command in txByte has already been sent
; Leaves data in the rxByte register
;_____________________________________________
;
DS1620rd
;
; Use rMask to set the DQ bit to an
; input to receive the next 8 bits
;
       movlw   rMask           ; set the DQ pin as input
       tris    portB
;
; receive 8 bits
;
       movlw   0x08            ; setup transmit counter for 8 bits
       movwf   bitCount
;
DSrdLoop
       rrf     rxByte, F       ; right shift rxByte register
       bcf     rxByte, 7       ; clear msb
       bcf     DS1620_CLK      ; lower clock lead
       nop                     ; short wait
       btfsc   DS1620_DQ       ; check DS1620 Data lead
       bsf     rxByte, 7       ; no, then set msb
       bsf     DS1620_CLK      ; raise clock lead
       decfsz  bitCount, F     ; dec bit count, and check for zero
       goto    DSrdLoop        ; not zero, go around again
                               ; if zero last bit received
;
       bcf     DS1620_RST      ; deselect DS1620
       movlw   wMask           ; reset 0x00 as output
       tris    portB
       return
;------------------------------------------------------------

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\01\16@040037 by Vasile Surducan

flavicon
face
DS1620, 0.5C resolution mode library for jal ( assembler and jal ) at:
www.geocities.com/vsurducan/electro/PIC/lib.html
regards, Vasile



On Wed, 16 Jan 2002, Heinz Czychun wrote:

{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam.....mitvma.mit.edu


2002\01\16@092910 by Michael Vinson

picon face
Heinz Czychun wrote (in part):
>[Responding to my [MV's] question about reading from DS1616]
>        I think this may be part of the problem.....
>If the DS1616 is like the DS1620 then bit 0 isn't waiting but
>must be clocked out. sclk must be high when entering the read
>routine, and then  brought low. The io bit can then be read into the
>PIC. I think your out of sync by one clock.

I think you are right, Heinz. After hearing nothing from the PIClist
yesterday, I was messing around in the evening, and one of the things
I tried was to omit the final "clock low" from the sendW routine,
and instead pull it low after setting TRIS and just before reading
the i/o pin. And it worked!! I can now talk in both directions to
this thing!! I'm psyched!!

>Also, if I may be so bold, here are my* read and write routines in
>the form of a loop......

Thank you Heinz! I'll save this code, but I probably won't use it
because of my personal quirk that I almost never use someone else's
code. I know it's stupid to constantly reinvent the wheel, but
maybe that's why I'm a scientist and not an engineer.

Thanks again!

Michael V

Thank you for reading my little posting.


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu


2002\01\19@112356 by akbar patil

flavicon
face
where can i get datasheet of this chip
ds1616
akbar patil
----- Original Message -----
From: "Michael Vinson" <mjvinsonspamspam_OUTHOTMAIL.COM>
To: <@spam@PICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, January 15, 2002 9:35 PM
Subject: [PIC]: Talking to DS1616: Help!


{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\19@112656 by akbar patil

flavicon
face
hi mr Heinz
where can i get data of
ds1616
akbarpatil
----- Original Message -----
From: "Heinz Czychun" <RemoveMEhczychunTakeThisOuTspamBLVL.IGS.NET>
To: <spamBeGonePICLISTspamBeGonespamMITVMA.MIT.EDU>
Sent: Wednesday, January 16, 2002 10:30 AM
Subject: Re: [PIC]: Talking to DS1616: Help!


{Quote hidden}

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


2002\01\19@135315 by Dale Botkin

flavicon
face
On Sat, 19 Jan 2002, akbar patil wrote:

> where can i get datasheet of this chip
> ds1616

http://dbserv.maxim-ic.com/quick_view2.cfm?qv_pk=2734

Dale

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.


More... (looser matching)
- Last day of these posts
- In 2002 , 2003 only
- Today
- New search...