Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 00:27 12 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : DS1307 RTC RAM access

Author Message
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 290
Posted: 10:03am 29 Sep 2018
Copy link to clipboard 
Print this post

I understand that the DS1307 clock chip has 56 bytes of useable RAM which is battery-backed and therefore remains non-volatile when power is removed. The advantage being that, unlike the inbuilt EEPROM storage on the Micromite, the RAM never wears out and therefore is ideally suited to holding rapidly-changing variables that need to be retained between power-downs.

Does anyone have any code that drops variables into these 56 bytes and subsequently retrieves them?

It would seem to be an ideal routine for a C-Function. Something along the lines of "Let RTCRAM = USERVAR" and "Let USERVAR = RTCRAM" or similar.

Can anyone help with this?

 
twofingers

Guru

Joined: 02/06/2014
Location: Germany
Posts: 1671
Posted: 11:36am 29 Sep 2018
Copy link to clipboard 
Print this post

Hi,

I would think RTC SETREG reg, value (resp. RTC GETREG reg, var) should do the job. (see MMManual)

The RAM registers are located in address locations 08h to
3Fh.
(DS1307 Manual).

Kind regards
Michael

Edited by twofingers 2018-09-30
causality ≠ correlation ≠ coincidence
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 12:27pm 29 Sep 2018
Copy link to clipboard 
Print this post

Twofingers is absolutely correct as above, this would be the best way to get your data stored as GETREG etc. allows you to talk to any register in the chip, so getting to your RAM is simply a matter of specifying a register in the correct range.

for storing INTEGERs: MMBasic integers are 64 bits (8 bytes) long so if you store the entire variable you will use up your memory quite quickly - 64 bits is a real luxury but often overkill.

For FLOATs, you'll need to store 4 bytes - it will be very difficult for you to pare this down because they aren't in a conventional n-byte-run format like normal binaries (integers) and string.

For STRINGs, all bets are off. you'll need to store the string length +1 if you want to faithfully translate the string back and forth unless you do fixed length. Your memory will be gone very quickly with even small words.

Make up a couple of functions to store and retrieve your variables wisely. Think about storing only as much as you need e.g. if you need to store a number between 0 and 30, a single byte will do, etc. For storing strings, try to come up with a token based system - using a single letter of the alphabet and the digits 0-9 will give you 62 string sentances (if case sensitive) which might be enough for your application. I came up with a highly compact logging method for cramming as much log into the 2K flash on a MM, check this to see the tokenization idea - I got date/time and string in six bytes! http://www.fruitoftheshed.com/MMBasic.Ultra-Compact-Logging-with-Flash-Storage-on-small-MicroMites.ashx

hth

hEdited by CaptainBoing 2018-09-30
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 290
Posted: 01:19pm 29 Sep 2018
Copy link to clipboard 
Print this post

How immensely helpful - thank you both. Right there in front of me all the time! Already tried it out and it works perfectly; couldn't be easier.

 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9753
Posted: 06:46am 30 Sep 2018
Copy link to clipboard 
Print this post

The MM is good like that.
Smoke makes things work. When the smoke gets out, it stops!
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 290
Posted: 10:40am 30 Sep 2018
Copy link to clipboard 
Print this post

Not just good, excellent!

I am a refugee from PICAXE - or perhaps I should say I have graduated from PICAXE to Micromite. I followed the coat tails of Peter Mather, having just caught his now controversial posting on the PICAXE forum announcing his departure before it was removed. I still use PICAXE for many minor projects but its limitations became increasingly challenging until I followed Peter's slipstream over to Geoff's incredible system.

I find Micromite to be an astonishing system; I started with the MX150, then the MX170s, Explore 64s and the UBW32s with Maximite firmware. I LOVE the microbridges and now have a ARMMITE sitting on my desk as well.

I am ever indebted to Geoff for his positively philanthropic approach to making the product of his expertise open-source. Also to Peter Mather for his expansion of the system in various ways.

It is great to be here!
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3308
Posted: 12:23pm 30 Sep 2018
Copy link to clipboard 
Print this post

Thanks for the kind words.

On the subject of storing INTEGERS and carrying on from what CaptainBoing was saying. The PIC32 stores integers as "little endian" which means that the least significant byte is stored first in memory and the most significant byte is stored last.

This is very handy because (say) an integer variable can have a range in values of 0 to 100. This means that the range of values is within one byte and therefore we only need to look at the first byte of the memory allocated to the variable to store its value (the other 7 bytes can be ignored).

So, to store the value in a DS1307 you could do something like this:

DIM INTEGER Val
Val = 78
RTC SETREG &H08, Val

and to get the value back in a different program:
DIM INTEGER NewVal
RTC GETREG &H08, NewVal
PRINT NewVal


Similarity, if the range of numbers can be held in two bytes you would only need to access the two lower bytes of the integer and ignore the other six (this gets more complicated but can be done using PEEK and POKE).

Normally MMBasic hides this sort of stuff but it can be important if you are trying to save variables to external memory that is structured as a sequence of bytes.

Geoff


Geoff Graham - http://geoffg.net
 
circuit
Senior Member

Joined: 10/01/2016
Location: United Kingdom
Posts: 290
Posted: 01:15pm 30 Sep 2018
Copy link to clipboard 
Print this post

Geoff,

Many thanks indeed - that is a most useful additional insight and very helpful as I progress.

For my immediate application I really just need to keep one or two status flags current so that the program knows where it left off when power is restored after any interruption in operation. Because these flags will be changing very frequently I thought that the battery-backed RAM was the best place to keep them updated - as it is proving to be.

As for the "kind words", I could not reiterate sufficiently my appreciation of your work. It is the scale of the concept, the documentation, the comprehensive range of capabilities and the overall versatility that I find quite mind-boggling. Add to that your magnanimous approach to its distribution and support and I feel that you really have created an extraordinary and impressive piece of intellectual property. I am privileged to be a recipient!
 
mikeb

Senior Member

Joined: 10/04/2016
Location: Australia
Posts: 177
Posted: 11:24pm 04 Oct 2018
Copy link to clipboard 
Print this post

+1
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9753
Posted: 10:20pm 05 Oct 2018
Copy link to clipboard 
Print this post

[Quote=circuit]I am a refugee from PICAXE - or perhaps I should say I have graduated from PICAXE to Micromite. I followed the coat tails of Peter Mather, having just caught his now controversial posting on the PICAXE forum announcing his departure before it was removed.[/Quote]

You tell an almost identical story to me. I first started on PICAXE, and it was(and remains) an amazing little chip, but things have moved on from there, and - unfortunately - RevEd have not decided to release any new chips and so the poor old PICAXE tends to get left behind to some extent now. Sad but true.

I would have liked to have read Peter's departure message, but as I hardly go to the PICAXE forum any more, I missed it. What did he say that got the post removed? Perhaps Peter himself will elaborate.

[Quote=circuit]I still use PICAXE for many minor projects but its limitations became increasingly challenging until I followed Peter's slipstream over to Geoff's incredible system.[/Quote]

Yes, this is me again - exactly. Being 8-bit, they are great for simple stuff, and that was all that was really on offer till the MM came on the scene. (EDIT: Arduino is not counted here, as you don't program it in BASIC) The problem with them being 8-bit though, is just that: 8-bit. They can't EASILY handle large numbers or 16-bit or 32-bit words. You can make words out of two bytes in PICAXE BASIC, but I found that to be a bit messy. It worked fine, but I found the MM easier to work with on this kind of stuff - speaking as someone who used to use PICAXE for everything.

I still find uses for the PICAXE-08M, and I still use this for a few different things such as 'Dumb' RF receivers, where the PICAXE acts extremely well as a data filter. This chip works very well in this kind of situation, and in fact, one of my larger systems uses this very PICAXE chip to filter and format messages that are then forwarded to the main system(based on a MM+), which then buffers the messages from the PICAXE in it's sexy background UART buffer for processing.

[Quote=circuit]I find Micromite to be an astonishing system; I started with the MX150, then the MX170s, Explore 64s and the UBW32s with Maximite firmware. I LOVE the microbridges and now have a ARMMITE sitting on my desk as well.

I am ever indebted to Geoff for his positively philanthropic approach to making the product of his expertise open-source. Also to Peter Mather for his expansion of the system in various ways.

It is great to be here![/Quote]

Yet again, almost word-for-word the same as me!


[Quote=circuit]As for the "kind words", I could not reiterate sufficiently my appreciation of your work. It is the scale of the concept, the documentation, the comprehensive range of capabilities and the overall versatility that I find quite mind-boggling. Add to that your magnanimous approach to its distribution and support and I feel that you really have created an extraordinary and impressive piece of intellectual property. I am privileged to be a recipient![/Quote]

As am I.
+1.Edited by Grogster 2018-10-07
Smoke makes things work. When the smoke gets out, it stops!
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 01:33am 06 Oct 2018
Copy link to clipboard 
Print this post

Grogster, circuit, and everyone else here...

I can not agree with you more. The Umite since the 150 has been the best thing I have EVER come across. The timing couldn't have been better. I literally have created a new hobby based on Geoff's work and the forum's dedication to helping. I have never had so many successful projects simply work before discovering the uMite. I can not thank Geoff and this forum enough for the last four years of playing with this, and I haven't even scratched the surface. I recently got a 64 pinnner and with Matherp's and Geoff's efforts, I can not even image what the possibilities are...

I am blabbling, but sincerely, if you could see what my spare room has turned into in the last four years, starting with the uMite, you would think I'm certifiable, at least my wife thinks so....
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025