Volatile RAM. Thinking DS1307 without battery.


Author Message
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 2375
Posted: 11:05pm 21 Jan 2025      

From DS1307 datasheet.
  Quote  56-Byte, Battery-Backed, General-Purpose RAM with Unlimited Writes

So with no battery and Flag% stored there that should ensure the flag is only erased on power fail and not Reset.
  DS1307 datasheet said  RTC AND RAM ADDRESS MAP
Table 2 shows the address map for the DS1307 RTC and RAM registers. The RTC registers are located in address
locations 00h to 07h. The RAM registers are located in address locations 08h to 3Fh. During a multibyte access, when the address pointer reaches 3Fh, the end of RAM space, it wraps around to location 00h, the beginning of the clock space.


n%=54321
> SAVE PERSISTENT n%
Error : Expected a string
> SAVE PERSISTENT "n%"
Error : Expected a string
> ? mm.info(PERSISTENT)
Error : Syntax
>
> option list
PicoMiteVGA MMBasic RP2350A Edition V6.00.02b1


Another option if the Flag doesn't get updated too often.
RTC GetTime

If Val(Right$(Date$,4)) > 2024 Then
  VAR RESTORE
 Else
  Flag% = 0
EndIf

RTC SetTime ....2025

'.....
If InfrequentCondition Then
  VAR SAVE Flag%
EndIf

Edited 2025-01-22 10:18 by phil99

Footnote added 2025-01-22 21:59 by phil99
Late entry
Beta2 has now been released with SAVE PERSISTENT added and as noted by @btwolf a few posts below this, some form of error test may be needed. He suggests a checksum. If that is 8 bits you still have 56 to play with. Though if the number saved is always less than say 32 bits a simple IF MM.INFO(PERSISTENT) < 2^32 Then ... or whatever will do.
SAVE PERSISTENT 54321
> ? MM.INFO(PERSISTENT)
54321
> cpu restart
> ? MM.INFO(PERSISTENT)
54321
PicoMiteVGA MMBasic RP2350A Edition V6.00.02b2 'reset button
Copyright 2011-2024 Geoff Graham
Copyright 2016-2024 Peter Mather

> ? MM.INFO(PERSISTENT)
8695604412579392460   'random data after reset
PicoMiteVGA MMBasic RP2350A Edition V6.00.02b2 'reset button
Copyright 2011-2024 Geoff Graham
Copyright 2016-2024 Peter Mather

> ? MM.INFO(PERSISTENT)
4081666594875190157
>