Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 02:54 29 Nov 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 : Brickwall for RTC on Micromite

     Page 1 of 2    
Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 06:55pm 16 Feb 2014
Copy link to clipboard 
Print this post

Hope someone can see the error of my ways. I am trying to set and read the RTC on a I2C 1307 module with the Micromite.



The module and original code supplied by Jman in 2011 works perfectly on the CGMMSTICK1 and the Olimex Diunomite Mini both running MMBASIC version 4 but I cannot get the result from the Micromite running Version 4.5 beta.



Hope someone on the forum can shed some light on my problem.
(Sorry for the pun)
Graeme
 
MOBI
Guru

Joined: 02/12/2012
Location: Australia
Posts: 819
Posted: 07:42pm 16 Feb 2014
Copy link to clipboard 
Print this post

Hi Graeme,

My i2c functions seem to be doing "funny" things since I loaded up the latest beta. I have been using external i2c RTC, hex keypad and LCD. Everything appeared to be working ok on the previous beta version.

I am in Adelaide at the moment and won't be home till tomorrow evening where I can do a few reversion tests. Is it possible that the DS1307 and the "uM inbuilt" RTC command are in conflict - the addresses of both chips may be the same but the registers not? Just wondering as I don't have the data with me.
David M.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6101
Posted: 08:03pm 16 Feb 2014
Copy link to clipboard 
Print this post

Graeme,
Can you post the code you are using.

I am using a PCF8563 and the inbuilt chock commands but I do have a DS1307 (somewhere) that I can test your code with.

I am not having any difficulties with other I2C devices on the MicroMite 4.5b6

Jim

VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 08:28pm 16 Feb 2014
Copy link to clipboard 
Print this post

  TassyJim said   Graeme,
Can you post the code you are using.

I am using a PCF8563 and the inbuilt chock commands but I do have a DS1307 (somewhere) that I can test your code with.

I am not having any difficulties with other I2C devices on the MicroMite 4.5b6

Jim


Jim, I think this is the link:
2011-07-19_174444_RTC.zip
All the best
Graeme
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 08:39pm 16 Feb 2014
Copy link to clipboard 
Print this post

Post the code in a CODE BOX:

Copy your code using either mouse(to left-click-hold and drag then right-click and COPY) or CTRL-A then CTRL-C with your code file open in something like Notepad.

Click the CODE button above the editing window

Place the cursor in-between the two CODE html tags(enclosed inside square brackets), and press CTRL-V to post your code.

Submit the new post - then your code should show up in a nice cute code box that everyone can read and examine.

This is an example of a code box.
Edited by Grogster 2014-02-18
Smoke makes things work. When the smoke gets out, it stops!
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 09:32pm 16 Feb 2014
Copy link to clipboard 
Print this post


The above link was the original article that Jman posted on TBS.

The code I am using is:
' Original Program for getting time and date from external RTC
' Presented by Jman 07/2011 on TBS altered for the Micromite V4.5beta3
600 ' Get time from time$ and date$
610 tempdec = Val(Left$(Time$, 2))
615 GoSub 1100
617 hours = hex
620 tempdec = Val(Mid$(Time$, 4, 2))
625 GoSub 1100
627 minutes = hex
630 tempdec = Val(Right$(Time$, 2))
635 GoSub 1100
637 seconds = hex
640 tempdec = Val(Left$(Date$, 2))
645 GoSub 1100
647 day = hex
650 tempdec = Val(Mid$(Date$, 4, 2))
655 GoSub 1100
657 month = hex
660 tempdec = (Val(Right$(Date$, 4)) - 2000)
665 GoSub 1100
667 year = hex
670 rtcctrl = &h10
680 rtcwday= &h1
690 ' Write Time to RTC
700 i2caddr = &h68 ' DS1307 I2C address
710 I2C open 100,100 ' Enable I2C
725 I2C write i2caddr, 0, 9, &h0, seconds, minutes, hours, rtcwday, day, month,
730 I2C close
770 Print "0=ok 1=nack 2=timeout"; MM.I2C
775 Print "RTC has been set to ";Time$;" ";Date$
780 End
1100 ' Convert to Hex
1110 hex = Fix(tempdec / 10) * 16
1120 hex = hex Or ((tempdec / 10) - (Fix(tempdec / 10))) * 10
1140 Return

Hope I got it all

I have tried pullup resistors from 4K7-20K with no change.
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:42pm 16 Feb 2014
Copy link to clipboard 
Print this post

Hi
Updated code for the MicroMite
Tested and working with a DS1307




ReadTime:
' I2C RTC based On DS1307 Secs,Mins,Hours,Day,Date,Month,Year,Control
Dim RTCbuff(8)
i2caddr = &h68 ' DS1307 I2C address
I2C open 100,100 ' Enable I2C
I2C write i2caddr, 0, 1, &h0
I2C Read i2caddr, 0, 8, RTCbuff(0)
I2C Close

sec$ = Str$(decimal)
BCDTEMP = RTCBuff(1)
BCDtoDec BCDTEMP

min$ = Str$(decimal)
BCDTEMP = RTCBuff(2)
BCDtoDec BCDTEMP

hours$ = Str$(decimal)
BCDTEMP = RTCBuff(4)
BCDtoDec BCDTEMP

day$ = Str$(decimal)
BCDTEMP = RTCBuff(5)
BCDtoDec BCDTEMP

month$ = Str$(decimal)
bcdtemp = rtcbuff(6)
BCDtoDec BCDTEMP

year$ = Str$(decimal + 2000 )
t$ = hours$+":"+min$+":"+sec$
D$ = day$+"/"+month$+"/"+year$
Time$ = T$
Date$ = D$
Return


'Convert to Decimal
Sub BCDtoDec (BCDTEMP)
Decimal = Fix(BCDTemp / 16) * 10
Decimal = Decimal + (BCDTEMP And &hF)
End Sub


Regards
Jman
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:44pm 16 Feb 2014
Copy link to clipboard 
Print this post

And in case you want to set it

SetDS1307:

' Get time from time$ and date$
tempdec = val(left$(time$, 2))
DECtoBCD tempdec
hours = hex

tempdec = val(mid$(time$, 4, 2))
DECtoBCD tempdec
minutes = hex

tempdec = val(right$(time$, 2))
DECtoBCD tempdec
seconds = hex

tempdec = val(left$(date$, 2))
DECtoBCD tempdec
day = hex

tempdec = val(mid$(date$, 4, 2))
DECtoBCD tempdec
month = hex

tempdec = (val(right$(date$, 4)) - 2000)
DECtoBCD tempdec
year = hex
rtcctrl = &h10
rtcwday= &h1

' Write Time to RTC
i2caddr = &h68 ' DS1307 I2C address
i2c open 100,100 ' Enable I2C
i2c Write i2caddr, 0, 9, &h0, seconds, minutes, hours, rtcwday, day, month, year, rtcctrl
i2c Close

? "0=ok 1=nack 2=timeout"; mm.i2c
? "RTC has been set to ";time$;" ";date$
end

' Convert to Hex
Sub DECtoBCD (tempdec)
hex = fix(tempdec / 10) * 16
hex = hex OR ((tempdec / 10) - (fix(tempdec / 10))) * 10
End Sub


And a little Picture of it going



Regards
JmanEdited by jman 2014-02-18
 
Ray B
Senior Member

Joined: 16/02/2007
Location: Australia
Posts: 219
Posted: 02:17am 17 Feb 2014
Copy link to clipboard 
Print this post

As an example of how a RTC can be set & read back to a serial port here is an example of how it is done in the basic form of "C" used in Arduino for those persons interested. Not really too difficult for persons familiar in programming in Basic.

C Programming does not get complicated until you delve into C++ & that's where I give up....

Example below is taken direct from examples that come with Arduino.

Note the neat structure of the code being:
*Declaration of libraries which you don't need to understand internally
* Loop of code used to setup program first time it is run - in this case enables serial port & sets time/date into RTC
* Program then runs in "loop"

// ************************************************************ *

#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>

void setup()
{
Serial.begin(9600);

RTC.stop();
RTC.set(DS1307_SEC,1); //set the seconds
RTC.set(DS1307_MIN,23); //set the minutes
RTC.set(DS1307_HR,12); //set the hours
RTC.set(DS1307_DOW,4); //set the day of the week
RTC.set(DS1307_DATE,5); //set the date
RTC.set(DS1307_MTH,3); //set the month
RTC.set(DS1307_YR,9); //set the year
RTC.start();

}

void loop()
{

Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
Serial.print(":");
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
Serial.print(":");
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
Serial.print(" "); // some space for a more happy life
Serial.print(RTC.get(DS1307_DATE,false));//read date
Serial.print("/");
Serial.print(RTC.get(DS1307_MTH,false));//read month
Serial.print("/");
Serial.print(RTC.get(DS1307_YR,false)); //read year
Serial.println();

delay(1000);

}



RayB from Perth WA
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 02:19am 17 Feb 2014
Copy link to clipboard 
Print this post

hey Jman...

What kind of display are you using there..? Is it an IIC device also..? How do you talk to it..?

Thanks for any info..!

 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 08:19am 17 Feb 2014
Copy link to clipboard 
Print this post

  Zonker said   hey Jman...

What kind of display are you using there..? Is it an IIC device also..? How do you talk to it..?

Thanks for any info..!



Hi
The display is a Nokia 5110 LCD. They are pretty cheap from Ebay
Nokia 5110
they display has an SPI interface so pretty easy to talk to
these display's are 84x84 pixels with NO built in fonts. The cool thing
is you can make custom graphics real easy (Like my degree symbol)
I can post my code if you are interested ?

Regards
Jman

BTW
Hope we are not hijacking this thread If so Glen please could you move it

 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 09:38am 17 Feb 2014
Copy link to clipboard 
Print this post

Nokia Display from 2-4€ eBay...

https://www.sparkfun.com/products/10168

please show us your code, jman ;-)
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 09:43am 17 Feb 2014
Copy link to clipboard 
Print this post

Link to a bascom (Basic for atmega) code from a russian site,

Looks simple.

http://bascom.at.ua/publ/chasy_na_mege8_ds1307_i_displee_nok ia1100/1-1-0-71
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 10:56am 17 Feb 2014
Copy link to clipboard 
Print this post

  jman said   Hi
Updated code for the MicroMite
Tested and working with a DS1307


ReadTime:
' I2C RTC based On DS1307 Secs,Mins,Hours,Day,Date,Month,Year,Control
Dim RTCbuff(8)
i2caddr = &h68 ' DS1307 I2C address
I2C open 100,100 ' Enable I2C
I2C write i2caddr, 0, 1, &h0
I2C Read i2caddr, 0, 8, RTCbuff(0)
I2C Close

sec$ = Str$(decimal)
BCDTEMP = RTCBuff(1)
BCDtoDec BCDTEMP

min$ = Str$(decimal)
BCDTEMP = RTCBuff(2)
BCDtoDec BCDTEMP

hours$ = Str$(decimal)
BCDTEMP = RTCBuff(4)
BCDtoDec BCDTEMP

day$ = Str$(decimal)
BCDTEMP = RTCBuff(5)
BCDtoDec BCDTEMP

month$ = Str$(decimal)
bcdtemp = rtcbuff(6)
BCDtoDec BCDTEMP

year$ = Str$(decimal + 2000 )
t$ = hours$+":"+min$+":"+sec$
D$ = day$+"/"+month$+"/"+year$
Time$ = T$
Date$ = D$
Return


'Convert to Decimal
Sub BCDtoDec (BCDTEMP)
Decimal = Fix(BCDTemp / 16) * 10
Decimal = Decimal + (BCDTEMP And &hF)
End Sub


Regards
Jman


Jman are you using beta 3?
This code still returns MM.I2C=1
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:09am 17 Feb 2014
Copy link to clipboard 
Print this post

Hi Graeme

I am using Beta 6
That error suggests a hardware error

Regards
Jman
 
jman

Guru

Joined: 12/06/2011
Location: New Zealand
Posts: 711
Posted: 11:12am 17 Feb 2014
Copy link to clipboard 
Print this post

  atmega8 said   Link to a bascom (Basic for atmega) code from a russian site,

Looks simple.

http://bascom.at.ua/publ/chasy_na_mege8_ds1307_i_displee_nok ia1100/1-1-0-71


I will post my connections when I get home
It is real simple no pullup resistors 3.3V supply just 1 resistor
for the backlight

Regards
JmanEdited by jman 2014-02-18
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6101
Posted: 11:47am 17 Feb 2014
Copy link to clipboard 
Print this post

  Graeme Meager said  

Jman are you using beta 3?
This code still returns MM.I2C=1


What voltage are you running the DS1307 on?

It needs 5V.

Jim
VK7JH
MMedit   MMBasic Help
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 926
Posted: 12:08pm 17 Feb 2014
Copy link to clipboard 
Print this post

  TassyJim said  
  Graeme Meager said  

Jman are you using beta 3?
This code still returns MM.I2C=1


What voltage are you running the DS1307 on?

It needs 5V.

Jim


Jim, you cracked it. The extra 1.7v made all the difference.
Thanks for your assistance and the other Shedders for their help.
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 12:20pm 17 Feb 2014
Copy link to clipboard 
Print this post

Ahhhhh - 1307 running on 3v3 uM voltage then? Live and learn, and thanks for posting back that you found it.

Would anyone even need the internal uM RTC, if you are using an external one anyway?

My point being, that if you are going to use an external RTC with battery, why not just poll it whenever you need date and/or time, and not bother with the uM RTC at all?

I am a little at a loss to actually understand why the uM has a RTC in it, if it is not battery-backed up and in the native design for the uM by default. With the plethora of RTC modules available complete with on-board battery, you can drop pretty much all the code examples posted by members above, and just read/write the RTC module directly on the I2C, whenever you need that info.

Perhaps I am not thinking of something, but while we are on the RTC thread, I better ask that of the forums now...Edited by Grogster 2014-02-18
Smoke makes things work. When the smoke gets out, it stops!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6101
Posted: 12:38pm 17 Feb 2014
Copy link to clipboard 
Print this post

Graeme,
Glad that it's sorted and the exercise will help others.
The 8563 can run happily on 3V so it is good for battery operated systems.
The 8563 also has a timer/alarm function which can be used to wake the uMite up.

That's 2 good reasons for changing to the 8563 for the uMite.

Grogster,
Before I coupled the RTC to the uMite, I had my SETTICK interrupt tweaked to give timer drift as good as the typical RTC - a few seconds per day.

If you want minimum parts count, the internal clock is very useful.

Jim


VK7JH
MMedit   MMBasic Help
 
     Page 1 of 2    
Print this page
© JAQ Software 2024