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: ItalyPosts: 162 |
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: AustraliaPosts: 1329 |
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 ZealandPosts: 711 |
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: ItalyPosts: 162 |
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: AustraliaPosts: 935 |
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. |
||||
2001cpx Regular Member Joined: 03/10/2013 Location: CanadaPosts: 59 |
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? "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: ThailandPosts: 2209 |
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 ZealandPosts: 9308 |
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. Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
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 ZealandPosts: 9308 |
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... Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
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... Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
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 ZealandPosts: 9308 |
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! Smoke makes things work. When the smoke gets out, it stops! |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
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 ZealandPosts: 9308 |
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] Smoke makes things work. When the smoke gets out, it stops! |
||||
Juri74 Senior Member Joined: 06/02/2012 Location: ItalyPosts: 162 |
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! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
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: ThailandPosts: 2209 |
@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 ZealandPosts: 9308 |
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 |