DS1307 I2C RTC and NVM

When we added RTC integration logic in the firmware, the  firmware v03.02.23 for hw rev 2.2.2 board and firmware v03.03.20 for hw rev 2.3.x introduced a DST bug.
Sorry about that.  We now released fix for it for anyone using the DST feature:

For hardware rev 2.2.2 board, please update with this firmware
http://www.cainetworks.com/support/download/wc8plc030224-update.zip

Code:
for hardware rev 2.3.x board, this is the new version:
http://www.cainetworks.com/support/download/wc8plc030321-update.zip
 
We are sorry about this.  Please update to the latest firmware to avoid DST change causing clock off.  If your current firmware is 3.02.22  for hw 2.2.2 or 3.03.19 for hw 2.3.x or earlier, there is not DST bug, you do not have to update.
 
WC32 board now can also update to the new 04.02.09 firmware to get DS1307 RTC support over its I2C bus.
Code:
for wc32 board, this is the new version:
http://www.cainetworks.com/support/download/wc32update040209.zip
 
We have heard people talking about modifying the tiny RTC module sold on market, by removing R4, R6 and D1, then use CR2302 battery instead of rechargeable LIR2032 battery.  We have experienced bad LIR2032 battery during our testing.  When RTC module is disconnected for a long time, the battery drained too low few times then dead.  Maxim IC said that DS1307 using a standard CR2032 battery could last 10 years.  But I think if you run a critical service, remove R4, R6, and D1, then wiring a DL123A battery instead of a coin CR2032 may worth the trouble.
 
So I plugged DS1307 to my W8 board and tried to use the NVM.  I'm curious what's the best way to use it for storing data?  I'd like feedback on my code below and on better ways to do it.
 
START
    
LOOP:
 SET VAR1 T1       # Read temperature
 SET VAR2 CTS    # Next 6 lines Calculate slope
 DELAY 5000        #  slow things down so it's easier to follow web status
 SET VAR3 T1  
 SET VAR4 CTS  
 SUB VAR3 VAR1 VAR5 
 SUB VAR4 VAR2 VAR6 
 DIV VAR5 VAR6 VAR7 
 
 SET RAM8 VAR1    #assign Temperature value to RAM8
 CALLSUB WROM1 #Write RAM8 to NV RAM
 CALLSUB RROM1  #Read NV RAM and write it to RAM8
 SET VAR8 RAM8    #Write contents of RAM8 to VAR8 to display on web status page
 DELAY 5000           #slow things down so it's easier to follow web status
 GOTO LOOP   
END    
 
AROM1:                   #set address location of the first byte
 I2CWRITE 1 0 160 
 I2CWRITE 0 0 0 
 I2CWRITE 0 0 16 
RET    
 
WROM1:                  #Write 4 bytes of RAM8 to NVRAM
 CALLSUB AROM1   
 I2CWRITE 0 0 RAM80 
 I2CWRITE 0 0 RAM81 
 I2CWRITE 0 0 RAM82 
 I2CWRITE 0 1 RAM83 
RET    
 
RROM1:                 #Read 4 bytes from NVRAM to RAM8 
 CALLSUB AROM1   
 I2CWRITE 1 0 161 
 I2CREAD 0 0 RAM80 
 I2CREAD 0 0 RAM81 
 I2CREAD 0 0 RAM82 
 I2CREAD 1 1 RAM83 
RET    
 
 
 
 
We will need to test before giving more feedback. Basically, if you have certain data did not want to lose, or even want to expand the storage, the extra storage on that chip is a good way to store it. You will need to decide the size and location for each information you want to store, so that you can write to it and read it back.
 
I am wondering how the WC8 firmware handling RTC1307 controls. I am driving i2c LCD display  and i2c real time clock1307. There is no problem with time synchronization upon booting/restarting.  
However, I was not able to synchronize the time after sending commands to the LCD display. 
I am sending my last I2CWRITE command with STOP, and then waiting for a time update from RTC1307.
The idea behind it is to be able to update time daily or weekly with the connected LCD display.
 
WC8 :firmware 03.02.30 hw: 2.2.2
 
There is an I2C bus lock for one device to use the bus at a time. That lock is started by the START bit, and unlock by STOP bit. If your I2C command did not have chance to yield the bus for clock to use, or the bus never released, then RTC has no chance to get updated.
 
Back
Top