Home  |  Contents 

Microcontroller and PC projects
  Forum Index : Microcontroller and PC projects         Section
Subject Topic: DS1307 RTC RAM access Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
circuit
Regular Member
Regular Member


Joined: 10 January 2016
Location: United Kingdom
Online Status: Offline
Posts: 40
Posted: 29 September 2018 at 8:03pm | IP Logged Quote circuit

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?




Back to Top View circuit's Profile Search for other posts by circuit
 
twofingers
Guru
Guru


Joined: 02 June 2014
Location: Germany
Online Status: Offline
Posts: 595
Posted: 29 September 2018 at 9:36pm | IP Logged Quote twofingers

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 on 29 September 2018 at 9:37pm
Back to Top View twofingers's Profile Search for other posts by twofingers
 
CaptainBoing
Guru
Guru
Avatar

Joined: 07 September 2016
Location: United Kingdom
Online Status: Offline
Posts: 626
Posted: 29 September 2018 at 10:27pm | IP Logged Quote CaptainBoing

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

h

Edited by CaptainBoing on 29 September 2018 at 10:31pm
Back to Top View CaptainBoing's Profile Search for other posts by CaptainBoing
 
circuit
Regular Member
Regular Member


Joined: 10 January 2016
Location: United Kingdom
Online Status: Offline
Posts: 40
Posted: 29 September 2018 at 11:19pm | IP Logged Quote circuit

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.

Back to Top View circuit's Profile Search for other posts by circuit
 
Grogster
Guru
Guru
Avatar

Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 6128
Posted: 30 September 2018 at 4:46pm | IP Logged Quote Grogster

The MM is good like that.

__________________
Smoke makes things work. When the smoke gets out, it stops!
Back to Top View Grogster's Profile Search for other posts by Grogster Visit Grogster's Homepage
 
circuit
Regular Member
Regular Member


Joined: 10 January 2016
Location: United Kingdom
Online Status: Offline
Posts: 40
Posted: 30 September 2018 at 8:40pm | IP Logged Quote circuit

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!
Back to Top View circuit's Profile Search for other posts by circuit
 
Geoffg
Guru
Guru
Avatar

Joined: 06 June 2011
Location: Australia
Online Status: Offline
Posts: 2402
Posted: 30 September 2018 at 10:23pm | IP Logged Quote Geoffg

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

Back to Top View Geoffg's Profile Search for other posts by Geoffg Visit Geoffg's Homepage
 
circuit
Regular Member
Regular Member


Joined: 10 January 2016
Location: United Kingdom
Online Status: Offline
Posts: 40
Posted: 30 September 2018 at 11:15pm | IP Logged Quote circuit

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!
Back to Top View circuit's Profile Search for other posts by circuit
 
mikeb
Senior Member
Senior Member
Avatar

Joined: 10 April 2016
Location: Australia
Online Status: Offline
Posts: 141
Posted: 05 October 2018 at 9:24am | IP Logged Quote mikeb

+1

__________________
There are 10 kinds of people in the world.
Those that understand binary and those that don't.
Back to Top View mikeb's Profile Search for other posts by mikeb
 
Grogster
Guru
Guru
Avatar

Joined: 31 December 2012
Location: New Zealand
Online Status: Offline
Posts: 6128
Posted: 06 October 2018 at 8:20am | IP Logged Quote Grogster

circuit wrote:
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.


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.

circuit wrote:
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.


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.

circuit wrote:
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!


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


circuit wrote:
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!


As am I.
+1.

Edited by Grogster on 06 October 2018 at 8:28am


__________________
Smoke makes things work. When the smoke gets out, it stops!
Back to Top View Grogster's Profile Search for other posts by Grogster Visit Grogster's Homepage
 
viscomjim
Guru
Guru


Joined: 08 January 2014
Location: United States
Online Status: Offline
Posts: 830
Posted: 06 October 2018 at 11:33am | IP Logged Quote viscomjim

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....
Back to Top View viscomjim's Profile Search for other posts by viscomjim
 


If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Search the forums using Google.
In the news...
 
Post ReplyPost New Topic
Printable version Printable version
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum

Powered by Web Wiz Forums version 7.8
Copyright ©2001-2004 Web Wiz Guide

This page was generated in 0.1719 seconds.
Privacy Policy     Process times : 0, 0.02, 0, 0.16