cravenhaven
Senior Member
This is driving me crazy, I've spent hours on it and cant figure out whats wrong.
I have simplified the program to just focus on what the problem is and inserted it below (I think?).
I have also copied in the circuit and the output from the program.
This section of the program is to write the correct time to the clock.
The root of the problem seems to be that when I setup the variables to write out to the RTC, the DataByte variable seems to get changed and I cant see why.
Hopefully someone can point out the error of my ways!.
Output from circuit when running the above code
View attachment OW_troubles.dsn
I have simplified the program to just focus on what the problem is and inserted it below (I think?).
I have also copied in the circuit and the output from the program.
This section of the program is to write the correct time to the clock.
The root of the problem seems to be that when I setup the variables to write out to the RTC, the DataByte variable seems to get changed and I cant see why.
Hopefully someone can point out the error of my ways!.
Code:
#PICAXE 20X2
;
;EEPROM messages. 20 bytes per message
EEPROM 1, ("DS1994 NOT found")
EEPROM 20,("Time out of range")
EEPROM 40,("Write Time wrong")
EEPROM 60,("Byte sent <> recv'd")
EEPROM 80,("Date conv. Wrong")
;
;Constants
;
SYMBOL OW_ReadRom =$33
SYMBOL OW_SkipRom =$CC
SYMBOL OW_SearchRom =$F0
SYMBOL OW_ReadMem =$F0
SYMBOL OW_Writescr =$0F
SYMBOL OW_Readscr =$AA
SYMBOL OW_Copyscr =$55
SYMBOL OW_Startclock =$50 ;Osc on, Stop counter
SYMBOL OW_lo_ctrl_buf =$01 ;Control register lo_byte
SYMBOL OW_lo_rtc_buf =$03 ;RTC Register lo_byte
SYMBOL OW_hi_tkr_buf =$02 ;Time Keeping Registers hi_byte
SYMBOL OW_Net =B.0
;
;Variables
;
SYMBOL errors =b2
SYMBOL errormsg =b3
SYMBOL message =b4
SYMBOL errormsgno =b5
SYMBOL DataByte =b5
SYMBOL OW_TA1 =b7 ; Target address low byte to be issued to the 1-Wire DS1994
SYMBOL OW_TA2 =b8 ; Target address high byte to be issued to the 1-Wire DS1994
SYMBOL OW_ES =b9 ; Target ending address status register for the 1-Wire DS1994
SYMBOL index =b10 ; general index used with FOR...NEXT blocks
SYMBOL Time1 = w11 ;Holds latest date&time
SYMBOL Time1_1 = b22
SYMBOL Time1_2 = b23
SYMBOL Time2 = w12 ;Holds latest date&time
SYMBOL Time2_1 = b24
SYMBOL Time2_2 = b25
SYMBOL hundr =b26
SYMBOL tens =b27
SYMBOL units =b28
;Temporary variables
SYMBOL Temp1 = b40
SYMBOL Temp2 = b41
SYMBOL Temp3 = b42
SYMBOL Lookup_result=w23
SYMBOL TempW0 = w24
SYMBOL TempW0_1 = b48
SYMBOL TempW0_2 = b49
SYMBOL TempW1 = w25
SYMBOL TempW1_1 = b50
SYMBOL TempW1_2 = b51
SYMBOL TempW2 = w26
SYMBOL TempW2_1 = b52
SYMBOL TempW2_2 = b53
SYMBOL TempW3 = w27
SYMBOL TempW3_1 = b54
SYMBOL TempW3_2 = b55
;
; -----( Start Program )--------------------------------------------------
;
main:
PAUSE 10000
Time2=$4E2E ;Date/Time in seconds
Time1=$916A ;Date/Time=26/07/2011 10:05:30 referenced to 1/1/1970 00:00:00
GOSUB OW_Time_init
GOSUB Check_Time_Registers
PAUSE 10000
Time2=$BA9B ;Date/Time in seconds
Time1=$B80B ;Date/Time=15/03/2006 17:21:17 referenced to 1/1/1970 00:00:00
GOSUB OW_Time_init
GOSUB Check_Time_Registers
GOTO main
END
OW_Time_init: ;Set the time (in seconds) on the DS1994
SERTXD(CR,LF,"Time_init",CR,LF)
OW_TA2=OW_hi_tkr_buf
SERTXD(CR,LF,CR,LF,"Time_Init loop, Writing Time2_2")
OW_TA1=OW_lo_ctrl_buf+3
DataByte=Time2_2
SERTXD(CR,LF,"Time2_2=",#Time2_2," DataByte=",#DataByte)
GOSUB OW_WriteByte
SERTXD(CR,LF,"Time_Init loop, Address and status registers. OW_TA2= ",#OW_TA2," OW_TA1= ",#OW_TA1," E/S= ",#OW_ES)
SERTXD(CR,LF,CR,LF,"Time_Init loop, Writing Time2_1")
OW_TA1=OW_lo_ctrl_buf+2
DataByte=Time2_1
SERTXD(CR,LF,"Time2_1=",#Time2_1," DataByte=",#DataByte)
GOSUB OW_WriteByte
SERTXD(CR,LF,"Time_Init loop, Address and status registers. OW_TA2= ",#OW_TA2," OW_TA1= ",#OW_TA1," E/S= ",#OW_ES)
SERTXD(CR,LF,CR,LF,"Time_Init loop, Writing Time1_2")
OW_TA1=OW_lo_ctrl_buf+1
DataByte=Time1_2
SERTXD(CR,LF,"Time1_2=",#Time1_2," DataByte=",#DataByte)
GOSUB OW_WriteByte
SERTXD(CR,LF,"Time_Init loop, Address and status registers. OW_TA2= ",#OW_TA2," OW_TA1= ",#OW_TA1," E/S= ",#OW_ES)
SERTXD(CR,LF,CR,LF,"Time_Init loop, Writing Time1_1")
OW_TA1=OW_lo_ctrl_buf
DataByte=Time1_1
SERTXD(CR,LF,"Time1_1=",#Time1_1," DataByte=",#DataByte)
GOSUB OW_WriteByte
SERTXD(CR,LF,"Time_Init loop, Address and status registers. OW_TA2= ",#OW_TA2," OW_TA1= ",#OW_TA1," E/S= ",#OW_ES)
SERTXD(CR,LF,"*******Time_init EOS ********",CR,LF)
RETURN
OW_WriteByte: ;Called with target address hi & lo bytes in OW_TA2 & OW_TA1 and the subject byte
OWOUT OW_Net,owresetbefore,(OW_SkipRom,OW_Writescr,OW_TA1,OW_TA2,DataByte) ;now start the clock running
OWOUT OW_Net,ownoreset,(OW_SkipRom,OW_Readscr) ;Tell the device to read the scratch register back
OWIN OW_Net,owresetafter,(TempW0_1,TempW0_2,OW_ES,TempW1_1) ;read scratch address vectors
errors=0
IF TempW0_1=OW_TA1 AND TempW0_2=OW_TA2 THEN ;If the scratch registers are wrong then dont write the data
IF TempW1_1=DataByte THEN
OWOUT OW_Net,owresetboth,(OW_SkipRom,OW_Copyscr,TempW0_1,TempW0_2,OW_ES) ;copy scratch to RTC registers (inlude authorisation codes)
ELSE LET errors=1
ENDIF
ELSE LET errors=1
ENDIF
SERTXD(CR,LF,"---------------------------TempW0_1=OW_TA1: ",#TempW0_1,"=",#OW_TA1," TempW0_2=OW_TA2: ",#TempW0_2,"=",#OW_TA2," TempW1_1=DataByte: ",#TempW1_1,"=",#DataByte," OW_ES: ",#OW_ES,CR,LF)
RETURN
OW_Read_Byte: ; call with OW_TA1,OW_TA2 set to lo&hi address registers
OWOUT OW_Net,owresetbefore,(OW_SkipRom,OW_ReadMem,OW_TA1,OW_TA2)
OWIN OW_Net,owresetafter,(DataByte)
RETURN
Check_Time_Registers:
SERTXD(CR,LF,"Main loop, Time registers from RTC")
OW_TA2=OW_hi_tkr_buf
FOR OW_TA1=0 to 6
GOSUB OW_Read_Byte
Temp2=DataByte
GOSUB Display_Reg
NEXT OW_TA1
RETURN
Display_Reg: ;Display a register value. Modifies Temp1, Called with register in Temp2
Temp1=Temp2 AND $F0 /$10 + $30
IF Temp1 > $39 THEN LET Temp1=Temp1+7
ENDIF
SERTXD(" $",Temp1)
Temp1=Temp2 AND $0F + $30
IF Temp1 > $39 THEN LET Temp1=Temp1+7
ENDIF
SERTXD(Temp1)
RETURN
Output from circuit when running the above code
Code:
Time_init
Time_Init loop, Writing Time2_2
Time2_2=78 DataByte=78
---------------------------TempW0_1=OW_TA1: 4=4 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 76=78 OW_ES: 4
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 4 E/S= 4
Time_Init loop, Writing Time2_1
Time2_1=46 DataByte=46
---------------------------TempW0_1=OW_TA1: 3=3 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 44=46 OW_ES: 3
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 3 E/S= 3
Time_Init loop, Writing Time1_2
Time1_2=145 DataByte=145
---------------------------TempW0_1=OW_TA1: 2=2 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 145=145 OW_ES: 2
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 2 E/S= 2
Time_Init loop, Writing Time1_1
Time1_1=106 DataByte=106
---------------------------TempW0_1=OW_TA1: 1=1 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 104=106 OW_ES: 1
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 1 E/S= 1
*******Time_init EOS ********
Main loop, Time registers from RTC $F8 $50 $54 $FC $4D $31 $4C
Time_init
Time_Init loop, Writing Time2_2
Time2_2=186 DataByte=186
---------------------------TempW0_1=OW_TA1: 4=4 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 184=186 OW_ES: 4
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 4 E/S= 4
Time_Init loop, Writing Time2_1
Time2_1=155 DataByte=155
---------------------------TempW0_1=OW_TA1: 3=3 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 153=155 OW_ES: 3
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 3 E/S= 3
Time_Init loop, Writing Time1_2
Time1_2=184 DataByte=184
---------------------------TempW0_1=OW_TA1: 2=2 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 184=184 OW_ES: 2
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 2 E/S= 2
Time_Init loop, Writing Time1_1
Time1_1=11 DataByte=11
---------------------------TempW0_1=OW_TA1: 1=1 TempW0_2=OW_TA2: 2=2 TempW1_1=DataByte: 9=11 OW_ES: 1
Time_Init loop, Address and status registers. OW_TA2= 2 OW_TA1= 1 E/S= 1
*******Time_init EOS ********
Main loop, Time registers from RTC $F8 $50 $7C $08 $50 $31 $4C