Working example from set internal RTC

Please do not post requests
Post Reply
john.carter3
Posts: 1
Joined: Tue Sep 06, 2016 1:03 pm

Working example from set internal RTC

Post by john.carter3 » Tue Nov 01, 2016 6:13 pm

Simple example to set and get date and time from ST32F1 RTC, with help of the Time lib by PaulStoffregen.
https://github.com/PaulStoffregen/Time

Ps: Soryy for my english.
Attachments
Set_RTC_STM32.ino
(2.75 KiB) Downloaded 337 times

unuldinei
Posts: 11
Joined: Tue Jul 21, 2015 8:32 pm
Location: Bucuresti RO
Contact:

Re: Working example from set internal RTC

Post by unuldinei » Thu Mar 30, 2017 8:04 am

I'm sorry but this example is not compile for any STM32f103 board.Any ideea? Thanks for sharing !

Code: Select all

 
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp: In member function 'void RTClock::setTime(tm*)':
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp:88:31: error: 'mktime' was not declared in this scope
   rtc_set_count(mktime (tm_ptr));
                               ^
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp: In member function 'tm* RTClock::getTime(tm*)':
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp:97:23: error: 'gmtime' was not declared in this scope
   tm_ptr = gmtime(&res); //why not gmtime? 
                       ^
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp: In member function 'void RTClock::createAlarm(voidFuncPtr, tm*)':
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp:115:33: error: 'mktime' was not declared in this scope
   time_t alarm = mktime(alarm_tm);//convert to time_t
                                 ^
 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp: In member function 'void RTClock::setAlarmTime(tm*)':

 \Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\libraries\RTClock\src\RTClock.cpp:121:30: error: 'mktime' was not declared in this scope
   time_t time = mktime(tm_ptr);//convert to time_t

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: Working example from set internal RTC

Post by zoomx » Thu Mar 30, 2017 9:51 am

Got the same error. I believe that it is due to the wrong time.h used by the compiler.
Here a similar error
https://forum.arduino.cc/index.php?topi ... msg3134941
so
Unfortunately the libraries are not compatible since, TimeLib contains a Time.h file and RTCZero.h depends on the POSIX time.h header. Since Windows has a case insensitive filesystem, Timelib's time.h conflicts.
but instead of RTCZero.h we have RTClock.h
I renamed PaulStoffregen Time.h but got the same error.

User avatar
Pito
Posts: 1627
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Working example from set internal RTC

Post by Pito » Thu Mar 30, 2017 10:11 am

Try

Code: Select all

//#include <Time.h>
#include <TimeLib.h>
Pukao Hats Cleaning Services Ltd.

User avatar
zoomx
Posts: 541
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: Working example from set internal RTC

Post by zoomx » Thu Mar 30, 2017 1:25 pm

time.h is included in RTClock.h

I made a mistake, renaming Time.h in TimePaul.h in PaulStoffregen library, fix the error.

I made a mistake in the main sketch because the include was between <> instead of "", because I put the modified library in the same folder of the main sketch.

There is an issue in the PaulStoffregen repository about renaming Time.h, Paul renamed it but leaved a Time.h file for backwards compatibility. This file interfere with others time.h in Windows, because Linux is case sensitive so Time.h and time.h are different files.

You can also remove Time.h in the Stoffregen library since inside there is only an #include "TimeLib.h"

unuldinei
Posts: 11
Joined: Tue Jul 21, 2015 8:32 pm
Location: Bucuresti RO
Contact:

Re: Working example from set internal RTC

Post by unuldinei » Thu Apr 20, 2017 9:12 am

I remove Time.h and Time.cpp from folder ...\Documents\Arduino\libraries\Time-master and the example work fine:

Code: Select all

#include <RTClock.h>
#include <TimeLib.h>
//this is where we will store the unix time
uint32_t tt = 0;
 

// initialise the RTC library. 
// NOTE: 'RTCSEL_LSE' assumes you have a 32.768Mhz crystal setup physically attached to the appropriate pins 
// on the microcontroller. Pins PC15 and PC14 are the RTC crystal pins.
RTClock rtc (RTCSEL_LSE); 

void setup() {
  Serial4.begin(9600); //i work with STM32F103RET (64K RAM 512K Flash, it have 4 Serial ports)

  //setTime(17, 13, 33, 19, 4, 2017);
 //rtc.setTime(1492596295);
  //you can also SET the rtc time with rtc.setTime(unixTimestamp) where unixTimestamp is a unix timestamp
}

void loop() {
  //get the RTC time (returns unix time, a 32bit integer representing seconds elapsed from Jan 01, 1970)
  tt = rtc.getTime();
  breakTime(tt); 
  delay(1000);//or whatever
}

void breakTime(uint32_t timeInput){
  Serial4.print(year(tt));Serial4.print("/");
  Serial4.print(month(tt));Serial4.print("/");
  Serial4.print(day(tt));Serial4.print("/");
  Serial4.print(weekday(tt));Serial4.print("// ");
  Serial4.print(hour(tt));Serial4.print(":");
  Serial4.print(minute(tt));Serial4.print(":"); 
  Serial4.print(second(tt));Serial4.print(" ");
  Serial4.println();
}

Post Reply