[wxsig] Another DS1904 question
John Vause jdv at iglou.comSat Oct 13 03:05:53 UTC 2012
- Previous message: [wxsig] Another DS1904 question
- Next message: [wxsig] Another DS1904 question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Will, I've searched the timelog.asm code that comes with the 1.16.1R source code on your website and I can find no routine that searches for the 0x24 family code. Is it possible you compiled the new routine into the 1.16.1R s19 file but left it out of the 1.16.1R source code? Just an FYI; I'm running the original T238 but that shouldn't matter in this case. Also, I am altering and re-compiling your source code to support the Bitson barometer sensor I've added to my weather station. Attached is the timelog.asm source code from 1.16.1R that I downloaded from your website. On 10/11/2012 10:53 PM, William Beals wrote: > John: > > Sorry for a delayed response. > > I dug into my code and found what I was looking for. In timelog.asm I look > for family IDs of both 0x04 (DS1994) and 0x24 (DS1904). The T238+ should > work with both. > > If not, let me know. > > will > > -----Original Message----- > From:wxsig-bounces at tapr.org [mailto:wxsig-bounces at tapr.org] On Behalf Of > Michael Seibel > Sent: Tuesday, October 02, 2012 4:56 PM > To: 'TAPR Weather Station SIG Mailing List' > Subject: Re: [wxsig] Another DS1904 question > > John - I am heavily involved with the county for the next 48 hours - I will > respond when I get back. I do not want to give wrong information, need my > notes. > Mike Seibel > > -----Original Message----- > From:wxsig-bounces at tapr.org [mailto:wxsig-bounces at tapr.org] On Behalf Of > John Vause > Sent: Tuesday, October 02, 2012 12:42 PM > To: TAPR Weather Station SIG Mailing List > Subject: [wxsig] Another DS1904 question > > Sorry if this has been asked before but as my DS1994 has "expired" does the > 1.16.1R firmware support the DS1904 "Time in a can" iButton? > > Looking at the "timelog.asm" code I can see where it searches for the > DS1994 family code "$04" (04 hex) > but according to Maxim's datasheet on the DS1904: > http://datasheets.maximintegrated.com/en/ds/DS1904.pdf > the DS1904 family code is 24h (24hex). > > Do I need to "fix" the family code and re-compile to support the DS1904? > > > ----- > No virus found in this message. > Checked by AVG -www.avg.com > Version: 2012.0.2221 / Virus Database: 2441/5304 - Release Date: 10/02/12 > > > _______________________________________________ > wxsig mailing list > wxsig at tapr.org > https://www.tapr.org/cgi-bin/mailman/listinfo/wxsig > > > _______________________________________________ > wxsig mailing list > wxsig at tapr.org > https://www.tapr.org/cgi-bin/mailman/listinfo/wxsig > > > > _______________________________________________ > wxsig mailing list > wxsig at tapr.org > https://www.tapr.org/cgi-bin/mailman/listinfo/wxsig > > > ----- > No virus found in this message. > Checked by AVG -www.avg.com > Version: 2012.0.2221 / Virus Database: 2441/5324 - Release Date: 10/11/12 > > -- * My favorite law: The Law of Unintended Consequences * * -- John Vause * * "Environmentalism as a metaphysical ideology and as a * * worldview has absolutely nothing to do with natural * * sciences or with the climate. * * -- Czech Pres. Vaclav Klaus * * You can fool yourself if you want, and you can fool * * as many as will follow for as long as you can get * * away with it. But you can't fool reality. * * - James P. Hogan in "Kicking The Sacred Cow" * * * * Si vis pacem, para bellum - If you wish for peace, * * prepare for war. * -------------- next part -------------- page ****************************************************** ** Copyright 2009 CMI Productions. ** ** Lots of rights reserved. ** ** Free for personal use as long as this copyright ** ** message is maintained in the source and the LCD ** ** copyright message is also preserved. Commercial ** ** use prohibited without CMIs written concent. ** ****************************************************** ; ----------------------------------------------------------------------------- ; File: timelog.asm ; Function: Time access routines (for DS1994) ; Routines: ck1994: Set time if DS1994 is present and clock running. ; sub32s: 32-bit Compare-before-subtract ; rdpage: Read a page from the DS1994 ; ----------------------------------------------------------------------------- ; ----------------------------------------------------------------------------- ; Routine: ck1994 ; Called By: rstrtn ; Calls: isrch: finds a 1-wire ID given family code ; sndadr: Sends a 1-wire address ; crcini: initializes CRC registers ; i_writ: writes a 1-wire byte ; i_read: reads a 1-wire byte ; sub32s: 32-bit compare-before subtract ; mthmax: figgers days in a month ; Gazintas: None ; Gazoutas: year, month, day, hrs, mins, secs if DS1994 present and running ; Function: See if a DS1994 is present on the bus and read the control ; register. If the clock is running (a sanity check), go ahead ; and read the time and program the local clock with the results. ; What makes this non-trivial is that the DS1994 uses "unix time" ; for its RTC which is the number of seconds since midnight ; 1/1/70. ; ----------------------------------------------------------------------------- ck1994: clr flg12 ; start off predictably lda #$04 ; Family ID for DS1994 jsr isrch ; go see if one exists out there tst mndray ; check family code bne ck94rd ; if non-zero, we found something jmp ck94er ; if zero, no DS1994 found, exit with "error" ck94rd: ldhx #mndray ; address for DS1994 jsr sndadr ; send it off jsr crcini ; reset the 16-bit CRC here lda #$f0 ; read memory+counter command jsr i_writ ; send it lda #$00 ; $200 memory address LSB jsr i_writ ; send it lda #$02 ; $200 memory address MSB jsr i_writ ; send it jsr i_read ; read status register ($200) sta msg+6 ; store it jsr i_read ; read control register ($201) sta msg+5 ; store it jsr i_read ; Read time frac secs ($202) sta msg+4 ; store it jsr i_read ; Read time byte 0 (lsb) ($203) sta msg+3 ; store it jsr i_read ; Read time byte 1 ($204) sta msg+2 ; store it jsr i_read ; Read time byte 2 ($205) sta msg+1 ; store it jsr i_read ; Read time byte 3 (msb) ($206) sta msg ; store it ; At this point: ; msg is the 4-byte second count (MSB first) ; msg+4 is the fractional seconds ; msg+5 is the control register ; msg+6 is the status register lda msg+5 ; get the control register and #$10 ; look only at osc enable bit beq ck94ex ; if 0 osc disabled, exit with Z set ; To get here the DS1994 is installed and the clock is running, this is ; necessary and sufficient for me to declare the time in the DS1994 most ; likely valid. We have the time data, go convert to local time. ; The time in the DS1994 is "unix time", meaning it is the number of ; seconds since midnight Jan 1, 1970. To save a bit of effort I first ; do one big subtraction to make the reference 1/1/00. If that underflows, ; the time was bad. After that I go through loops where I successivly ; subtract the seconds in a year, month, day, and hour. Remainder is ; seconds. Years get complicated because of leap years and months get ; complicated because they are all different lengths. ; First clear the local counters to starting postions: clr year ; 2000 mov #1,month ; January mov #1,day ; 1st clr hrs ; 00 hours (midnight) clr mins ; 0 minutes clr secs ; 0 seconds ldhx #s_y2k ; Unix time is since 1/1/70, adjust to 1/1/00 jsr sub32s ; do it bcs ck94er ; if not possible, error! ck94dy: ldhx #s_y365 ; assume 365-day year lda year ; get the starting year and #$03 ; see if multiple of four bne ck94gy ; if so, got right constant ldhx #s_y366 ; otherwise get leap-year seconds ck94gy: jsr sub32s ; see if a year has passed bcs ck94dm ; if too big, on to months inc year ; otherwise increment year bra ck94dy ; go try and do another year ; Months get tricky. I call the mthmax routine (see warning at mthmax header) ; with the current year and month and get the number of days. To get the ; seconds in that month (starting at January), I take the days in the month, ; subtract 28 (0-3), multiply by four (0,4,8,12), and add the s_d28 base ; address to get the offset to the seconds in that month. Theoretically I ; can't overflow. ck94dm: jsr mthmax ; get days in this month (jan=1st) sub #28 ; get 0-3 offset asla ; times two asla ; times four add #s_m28%256 ; add to 28-day address LSB tax ; save result lda #s_m28\256 ; get 28-day address MSB adc #0 ; add carry if any psha ; push on stack pulh ; get MSB in H jsr sub32s ; see if that many seconds left bcs ck94dd ; if too big, on to days inc month ; otherwise increment to next month bra ck94dm ; and try it ck94dd: ldhx #s_day ; # of seconds in a day jsr sub32s ; see if that many seconds left bcs ck94dh ; if too big, on to hours inc day ; otherwise increment to next day bra ck94dd ; and try it ck94dh: ldhx #s_hour ; # of seconds in an hour jsr sub32s ; see if that many seconds left bcs ck94dn ; if too big, on to minutes inc hrs ; otherwise increment to next hour bra ck94dh ; and try it ck94dn: ldhx #s_min ; # of seconds in a minute jsr sub32s ; see if that many seconds left bcs ck94ds ; if too big, on to seconds inc mins ; otherwise increment to next minute bra ck94dn ; and try it ck94ds: lda msg+3 ; all that is left is seconds sta secs ; store them lda #1 ; not 0 tsta ; clear z bra ck94ex ; exit ck94er: clra ; A=0 and Z set ck94ex: rts ; all done sampling page ; ----------------------------------------------------------------------------- ; Routine: sub32s ; Called By: ck1994 ; Calls: None. ; Gazintas: msg: 32-bit subtractee ; (hx) 32-bit value to subtract ; Gazoutas: C bit set if subtractor greater than subtractee. No subtraction ; C bit clear if able to subtract w/o underflow, subtraction done ; Function: We first check to see if the subtractor is greater than the ; subtractee. If it is greater, we just set the C bit and exit ; without doing anything. If the subtractee is less than the ; subtractor, we do the subtraction and clear the C bit. ; The idea here is that we are subtracting away years, months, ; days, etc until none more can be subtracted. ; ----------------------------------------------------------------------------- sub32s: lda msg ; get subtractee MSB cmp ,x ; compare to subtractor MSB blo sub32n ; if greater, exit with minus flag set bhi sub32d ; if less, OK to subtract lda msg+1 ; get subtractee next byte cmp 1,x ; compare to subtractor next byte blo sub32n ; if greater, exit with minus flag set bhi sub32d ; if less, OK to subtract lda msg+2 ; get subtractee next byte cmp 2,x ; compare to subtractor next byte blo sub32n ; if greater, exit with minus flag set bhi sub32d ; if less, OK to subtract lda msg+3 ; get subtractee LSB cmp 3,x ; compare to subtractor next byte blo sub32n ; if greater, exit with minus flag set sub32d: lda msg+3 ; get subtractee LSB sub 3,x ; subtract subtractor LSB sta msg+3 ; save result in msg lda msg+2 ; get subtractee sbc 2,x ; subtract subtractor sta msg+2 ; save result in msg lda msg+1 ; get subtractee sbc 1,x ; subtract subtractor sta msg+1 ; save result in msg lda msg ; get subtractee MSB sbc ,x ; subtract subtractor MSB sta msg ; save result in msg sub32n: rts ; return with carry flag clear or set, depending ;============================================================================== ; DS1994 File routines ;============================================================================== ; ----------------------------------------------------------------------------- ; Routine: rd94pg ; Called By: ; Calls: sndadr: Sends a 1-wire address ; crcini: initializes CRC registers ; i_writ: writes a 1-wire byte ; i_read: reads a 1-wire byte ; Gazintas: ds94pg: the page to read (0-16) ; Gazoutas: (msg) 32-byte page of data from the DS1994 ; Function: This function reads a page or data from the DS1994 and places ; it in the msg buffer. ; ----------------------------------------------------------------------------- rd94pg: ldhx #mndray ; address for DS1994 jsr sndadr ; send it off jsr crcini ; reset the 16-bit CRC here lda #$f0 ; read memory+counter command jsr i_writ ; send it lda ds94pg ; get page nsa ; swap nybbls (x16) lsla ; shift left for x2 (x32) and #$e0 ; get rid of unwanted bits jsr i_writ ; send address LSB lda ds94pg ; get page # again (assume x256) lsra ; /2 (x128) lsra ; /2 (x64) lsra ; /2 (x32) jsr i_writ ; send address MSB ; We've sent the page address, now go get 32 bytes of data ldhx #msg ; point to the start of the message ds94rp: pshh ; save H on the stack pshx ; save X jsr i_read ; get a byte of data (and do CRC) pulx ; get x pulh ; get h sta ,x ; save the byte aix #1 ; increment pointer cphx #msg+32 ; see if we are done bne ds94rp ; if not, go get another byte rts ; read data, all done ; ----------------------------------------------------------------------------- ; Routine: wr94pg ; Called By: ; Calls: sndadr: Sends a 1-wire address ; crcini: initializes CRC registers ; i_writ: writes a 1-wire byte ; i_read: reads a 1-wire byte ; Gazintas: ds94pg: the page to write (0-16) ; (msg) 32-byte page of data for the DS1994 ; Function: This function writes a page of data in the (msg) buffer to the ; DS1994. The process is to write the data to the ; scratchpad RAM area, read scratchpad area back, then issue the ; command to write the scratchpad to final RAM ; ----------------------------------------------------------------------------- wr94pg: ldhx #mndray ; address for DS1994 jsr sndadr ; send it off jsr crcini ; reset the 16-bit CRC here lda #$0f ; write scratchpad command jsr i_writ ; send it lda ds94pg ; get page nsa ; swap nybbls (x16) lsla ; shift left for x2 (x32) and #$e0 ; get rid of unwanted bits jsr i_writ ; send address LSB lda ds94pg ; get page # again (assume x256) lsra ; /2 (x128) lsra ; /2 (x64) lsra ; /2 (x32) jsr i_writ ; send address MSB ; We've sent the page address, now send the 32 bytes of data ldhx #msg ; point to the start of the message ds94wp: lda ,x ; get a byte pshh ; save H on the stack pshx ; save X jsr i_writ ; send a byte of data (and do CRC) pulx ; get x pulh ; get h aix #1 ; increment pointer cphx #msg+32 ; see if we are done bne ds94wp ; if not, go get another byte ; Data is now in scratchpad. Verify it... ldhx #mndray ; address for DS1994 jsr sndadr ; send it off jsr crcini ; reset the 16-bit CRC here lda #$aa ; read scratchpad command jsr i_writ ; send it jsr i_read ; get the TA1 byte sta divsor ; save it for a bit lda ds94pg ; get page nsa ; swap nybbls (x16) lsla ; shift left for x2 (x32) and #$e0 ; get rid of unwanted bits cmp divsor ; compare to expected value bne wr94er ; if problems, handle them. jsr i_read ; get the TA2 byte sta divsor ; save it for a bit lda ds94pg ; get page # again (assume x256) lsra ; /2 (x128) lsra ; /2 (x64) lsra ; /2 (x32) cmp divsor ; compare to expected value bne wr94er ; if problems, handle them. jsr i_read ; get the E/S byte cmp #$1f ; expected value (no errors, 31 bytes written) bne wr94er ; if problems, handle them. ; We've verified the page address, now check the 32 bytes of data ldhx #msg ; point to the start of the message ds94cp: pshh ; save H on the stack pshx ; save X jsr i_read ; get a byte of data (and do CRC) pulx ; get x pulh ; get h cmp ,x ; check the byte bne wr94er ; if error abort out aix #1 ; increment pointer cphx #msg+32 ; see if we are done bne ds94cp ; if not, go get another byte ; We now have verified address and data in the scratchpad RAM. ; Transfer it to permenent RAM. ldhx #mndray ; address for DS1994 jsr sndadr ; send it off jsr crcini ; reset the 16-bit CRC here lda #$55 ; copy scratchpad command jsr i_writ ; send it lda ds94pg ; get page nsa ; swap nybbls (x16) lsla ; shift left for x2 (x32) and #$e0 ; get rid of unwanted bits jsr i_writ ; send address LSB lda ds94pg ; get page # again (assume x256) lsra ; /2 (x128) lsra ; /2 (x64) lsra ; /2 (x32) jsr i_writ ; send address MSB lda #$1f ; E/S byte jsr i_writ ; send it wr94er: -------------- next part -------------- ----- No virus found in this message. Checked by AVG - www.avg.com Version: 2012.0.2221 / Virus Database: 2441/5327 - Release Date: 10/12/12
- Previous message: [wxsig] Another DS1904 question
- Next message: [wxsig] Another DS1904 question
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the wxsig mailing list
