Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:52 19 May 2024 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 : Maximite and RTC ds1307

     Page 1 of 2    
Author Message
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 01:54am 15 Jan 2014
Copy link to clipboard 
Print this post

Hello people,
does anyone know if there is a way to access the DS1307 real time clock?
i'm really interestewd to access register 03h the one that keep track of "day of the week"
i'm writing a sub to keep track of day of the week but it take memory and have to be setted up the first day of year, that's a useless waste of time and memory because DS1307 already have it..

Juri
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1329
Posted: 02:45am 15 Jan 2014
Copy link to clipboard 
Print this post

There's been discussion about this before Juri - this is probably quite relevant for you: RTC-MMBasic Particularly, see Geoff's response 19th Oct 2013, 9:24am.

Greg
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 08:24am 15 Jan 2014
Copy link to clipboard 
Print this post

Hi Juri

I assume you talking about the DS1307 on a colour Maximite ?
If that's the case I don't think you can access the DS1307

You could always rewire the DS1307 to use the normal I2C pins that will give you
full access to the DS1307

Regards
Jman
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 01:30pm 16 Jan 2014
Copy link to clipboard 
Print this post

hello jman,
yes i'm talking about ds1307 on a colour maximite.
should i have to cut the original connection? or can i leave it connected to both i2c pins? so maximite can access it at bootup and then i can access it when i want..
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 02:08pm 16 Jan 2014
Copy link to clipboard 
Print this post

Juri, instead of cutting tracks etc., why not get one of these and just connect it to the standard I2C bus of the Maximite. If it bothers you that you have two RTCs why not just use the new one as a master and every time you access it also issue an MMBasic time set command TIME$ = “HH:MM:SS” which will set the inbuilt clock to the same as the new one.

Just be careful of the cost. These eBay RTC modules are very expensive.

edit: I just noticed that some of them come with EEPROM storage also.Edited by BobD 2014-01-18
 
2001cpx

Regular Member

Joined: 03/10/2013
Location: Canada
Posts: 59
Posted: 02:28pm 16 Jan 2014
Copy link to clipboard 
Print this post

i will check this week end,

with logical chip like 74Hc to switch on another port on request,seem to be simple

just to cut track and rewire.

do you really need this?


Edited by 2001cpx 2014-01-18
"Color Maximite,(Duinomite-Mega,Mini),CGmmStick,GCmicroboard2b,Micromite + explore 64,100,LCD backpack,Lcd Backpack V2,TFT Backpack,Micromite Extreme,Armmite L,F,H,CMM2"
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 05:19pm 16 Jan 2014
Copy link to clipboard 
Print this post

In theory it would be no problem to connect the I2C that is available from MMBasic to the internal I2C one that is hardwired to the RTC.
I2C is a bus so it is designed to have multiple chips (or peripherals) connected.
Just two wires soldered is all that is needed.
Nothing bad can happen.


Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 05:49pm 16 Jan 2014
Copy link to clipboard 
Print this post

  Juri74 said   Hello people,
does anyone know if there is a way to access the DS1307 real time clock?
i'm really interestewd to access register 03h the one that keep track of "day of the week"
i'm writing a sub to keep track of day of the week but it take memory and have to be setted up the first day of year, that's a useless waste of time and memory because DS1307 already have it..

Juri


Unless you specifically need access to the general purpose bytes in the 1307, I can't see why you can't do what you want with a simple routine that uses MID$ and DATE$ to manupliate the days data however you want.

Perhaps you could elaborate a little more on specifically why it is too hard or memory intensive to do it with the built-in RTC - adding another RTC so you can read register 03h seems like the hard way of doing it to me as you'll still have to have code to get the data from that register - will probably end up about the same....

If all you want to know, is what the day is by number, then you can do that easy-peasy like this:

D=VAL(MID$(DATE$,1,2))

That will give you a numeric representation of the date, or you can have the date as a string a little more simply:

D$=MID$(DATE$,1,2)

This could be executed anytime you need to know the date, then play around with D or D$ however you like.

...perhaps I am missing something?

EDIT: I am. I just checked the 1307 datasheet for myself, and 03h is the day of the week register, which is a value of 1 to 7. So, reading the date in my example above, probably won't help you, if I now understand things correctly. Yes, getting access to that specific register will probably require you to use another RTC module, as suggested by other members here. You could hack the PCB as TZA has suggested, but I would be inclined to use another RTC module - they are cheap as chips anyway on ebay.Edited by Grogster 2014-01-18
Smoke makes things work. When the smoke gets out, it stops!
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 06:05pm 16 Jan 2014
Copy link to clipboard 
Print this post

Grogster, you are providing Day of the Month. The register 03 is all about Day of the Week. I used to have an algorithm in MMBasic that would give the day of week number from any date. It was only about 5 lines. I actually used it to generate the DotW from the date to set this register in an RTC. I wonder if I can find it.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 06:11pm 16 Jan 2014
Copy link to clipboard 
Print this post

Yes, I spotted that about the same time as you.

eBay have 1307 RTC modules with a EEPROM chip aswell for US$1.51 - pretty hard to beat that price!

$1.51 RTC module

Might be perfect for the purposes and the price...Edited by Grogster 2014-01-18
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:21pm 16 Jan 2014
Copy link to clipboard 
Print this post

This one cost nothing and does not need any hardware additions/modifications. :)
Returns numbers between 0 and 6 (0=Sun, 1=Mon, etc)
[code]
function DayOfWeek(year, month, day)
a = int((14-month)/12)
m = month + 12*a - 2
y = year - a
DayOfWeek = (day + y + int(y/4)-int(y/100)+int(y/400)+int(31*m/12)) mod 7
end function
[/code]
It is probably less code then a routine to access the RTC chip.

Edited by TZAdvantage 2014-01-18
Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 06:29pm 16 Jan 2014
Copy link to clipboard 
Print this post

Whose a clever boy then, TZA?

Very nice.

I might have to steal this for my RTC in my menu program, if you don't mind that is...Edited by Grogster 2014-01-18
Smoke makes things work. When the smoke gets out, it stops!
 
BobD

Guru

Joined: 07/12/2011
Location: Australia
Posts: 935
Posted: 06:39pm 16 Jan 2014
Copy link to clipboard 
Print this post

TZA, you beat me to it. I'll use your one in the future. I did finally find mine but it was not expressed so nicely. Mine was before MMBasic functions.

Grogster, you may be interested in this Day of the Week calculations.

Bob
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 06:41pm 16 Jan 2014
Copy link to clipboard 
Print this post

Thanks, Bob - will check it out.
The maths in calculating it look pretty intense to me!

EDIT: Yep, will have to read that link above a few more times to understand the mathematics!Edited by Grogster 2014-01-18
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:48pm 16 Jan 2014
Copy link to clipboard 
Print this post

I am clever only sometimes.
In this case i just looked around on my disk full of sourcecode.
I probably copied it from somewhere before.

Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 08:59pm 16 Jan 2014
Copy link to clipboard 
Print this post

Using that code to play with, I was able to determine that I was born on a Thursday. Drat. I was hoping it would be Friday - I have always liked Friday.

I have taken TZA's code, and added a little to it, so that it produces the name of the day of the week based on the RTC in the MM:

[code]
dim DOW$(6) length 9
DOW$(0)="Sunday":DOW$(1)="Monday":DOW$(2)="Tuesday":DOW$(3)= "Wednesday"
DOW$(4)="Thursday":DOW$(5)="Friday":DOW$(6)="Saturday"

Year=VAL(MID$(DATE$,7,4)):Month=VAL(MID$(DATE$,4,2)):Day=VAL (MID$(DATE$,1,2))
print DOW$(DayOfWeek(Year, Month, Day))


end


function DayOfWeek(year, month, day)
a = int((14-month)/12)
m = month + 12*a - 2
y = year - a
DayOfWeek = (day + y + int(y/4)-int(y/100)+int(y/400)+int(31*m/12)) mod 7
end function
[/code]
Edited by Grogster 2014-01-18
Smoke makes things work. When the smoke gets out, it stops!
 
Juri74

Senior Member

Joined: 06/02/2012
Location: Italy
Posts: 162
Posted: 02:59am 17 Jan 2014
Copy link to clipboard 
Print this post

Hello all,
thank you for your suggestion, i discarded the use of 2nd ds1307 (there is already one, why use another one?) my initial question was if it was possible to retrieve the content of register 03h of the ds1307 onboard..

@tza
your little routine is stunning! one little question (i was lost on dayoftheweek=.. line) does it keep track of 29 days february every 4 years?

@grogster
your improvment of tza's routine is very useful

thank you so much to all for help!Edited by Juri74 2014-01-18
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 03:18am 17 Jan 2014
Copy link to clipboard 
Print this post

TZ, your algorithm is neat. It is like a mind puzzle figuring out how it work.

It even includes leap year compensation to 2400 and beyond. I don't think that any of us will be alive then !!

Geoff
Geoff Graham - http://geoffg.net
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 03:47am 17 Jan 2014
Copy link to clipboard 
Print this post

@Juri,

Yes it takes care of leap years.
The Gregorian calendar is based on a 400 year cycle. Every year is 365.2425 days.
To compensate every 4 year is a leap year unless if you can divide it by 100 then it is a normal year. The exception is when you can divide it by 400 then it is a leap year again. Depending in what country you use it it is valid from the 15th or 17th century as not all countries switched over to the Gregorian calendar.
It all started to get the day right for Easter.

The trickiest line is actually
a = int((14-month)/12)
because that replaces about 4-5 lines of code.

Another good thing to read about is the "Golden Number".
I always find it fascinating how things that we take for granted were figured out, and the reasons why.





Microblocks. Build with logic.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9083
Posted: 01:44pm 17 Jan 2014
Copy link to clipboard 
Print this post

  Juri74 said  (i was lost on dayoftheweek=.. line)


You and me both!!!!

That is some serious mathematics going on there...

I put a timer on this function of TZA's for interest's sake, and it crunches all that maths in 3ms - wow - impressive. It will take me 3 DAYS just to get my head around what the hell it is all doing!!!

@ TZA - You description post above is very helpful in understanding the maths a bit more.
Smoke makes things work. When the smoke gets out, it stops!
 
     Page 1 of 2    
Print this page
© JAQ Software 2024