sadat007
Full Member level 4
Hi,
I tried to simulate DS1338 with following simple codes. The same code worked fine with DS1307 but with DS1338 the internal registers will not update or change. That is the seconds print keep printing fixed value of the seconds which loaded at startup from system clock. Note that the main time and date registers are same for the both.
Thanks
Sadat007
$baud = 9600
$crystal = 22118400
$regfile = "8052.DAT"
$large
Const Ds1307w = &HD0
' Write
Const Ds1307r = &HD1
' Read
Const Sec_addmap = &H00
Const Min_addmap = &H01
Const Hour_addmap = &H02
Const Control_addmap = &H07
Dim Reg_sec As Byte
Dim Reg_min As Byte
Dim Reg_hour As Byte
Dim Tempb As Byte
Config Sda = P1.6
Config Scl = P1.5
Clock_init:
' double key stroke
Reg_sec = 33
Tempb = Reg_sec And &B01111111
' start Oscillator Enable bit 7 of seconds put 0
I2cstart
I2cwbyte Ds1307w
I2cwbyte Sec_addmap
I2cwbyte Tempb
I2cstop
' Generate Stop
Loop1:
I2cstart
' Generate start
I2cwbyte Ds1307w
' Slave adsress
I2cwbyte Sec_addmap
' Address of SECONDS REG
I2cstop
' Generate Stop
I2cstart
' Repeated start
I2cwbyte Ds1307r
' Slave address (read)
I2crbyte Reg_sec , Ack
I2crbyte Reg_min , Ack
I2crbyte Reg_hour , Nack
I2cstop
'Reg_hour = Reg_hour And &B00011111
' remove 12/24 set and am/pm bits
' set numeric variables
'Num_hour = Makedec(reg_hour)
'Num_min = Makedec(reg_min)
'Num_sec = Makedec(reg_sec)
Print Reg_sec
Wait 1
Goto Loop1
I tried to simulate DS1338 with following simple codes. The same code worked fine with DS1307 but with DS1338 the internal registers will not update or change. That is the seconds print keep printing fixed value of the seconds which loaded at startup from system clock. Note that the main time and date registers are same for the both.
Thanks
Sadat007
$baud = 9600
$crystal = 22118400
$regfile = "8052.DAT"
$large
Const Ds1307w = &HD0
' Write
Const Ds1307r = &HD1
' Read
Const Sec_addmap = &H00
Const Min_addmap = &H01
Const Hour_addmap = &H02
Const Control_addmap = &H07
Dim Reg_sec As Byte
Dim Reg_min As Byte
Dim Reg_hour As Byte
Dim Tempb As Byte
Config Sda = P1.6
Config Scl = P1.5
Clock_init:
' double key stroke
Reg_sec = 33
Tempb = Reg_sec And &B01111111
' start Oscillator Enable bit 7 of seconds put 0
I2cstart
I2cwbyte Ds1307w
I2cwbyte Sec_addmap
I2cwbyte Tempb
I2cstop
' Generate Stop
Loop1:
I2cstart
' Generate start
I2cwbyte Ds1307w
' Slave adsress
I2cwbyte Sec_addmap
' Address of SECONDS REG
I2cstop
' Generate Stop
I2cstart
' Repeated start
I2cwbyte Ds1307r
' Slave address (read)
I2crbyte Reg_sec , Ack
I2crbyte Reg_min , Ack
I2crbyte Reg_hour , Nack
I2cstop
'Reg_hour = Reg_hour And &B00011111
' remove 12/24 set and am/pm bits
' set numeric variables
'Num_hour = Makedec(reg_hour)
'Num_min = Makedec(reg_min)
'Num_sec = Makedec(reg_sec)
Print Reg_sec
Wait 1
Goto Loop1