pdf-icon

Arduino Quick Start

Core2 RTC

RTC Class: Rtc

begin()

Description:

Initializes the RTC (Real-Time Clock).

Syntax:

void begin(void);
Note:
1. If you do not want to use M5.begin() to initialize the RTC clock, please call this function before using the RTC.

Example Usage:

cpp
1 2 3 4 5 6 7 8
#include <M5Core2.h>
void setup() {
M5.Rtc.begin(); // Initialize the RTC clock
}
void loop() {
}

SetTime()

Description:

Sets the Real-Time Clock time.

Syntax:

void SetTime(RTC_TimeTypeDef* RTC_TimeStruct);

Example Usage:

cpp
1 2 3 4 5 6 7 8 9 10 11 12
#include <M5Core2.h>
RTC_TimeTypeDef TimeStruct;
void setup() {
M5.begin();
TimeStruct.Hours = 18; // Set the specific time in the RTC structure
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct); // Write the set time to the RTC
}
void loop(){}

GetTime()

Description:

Retrieves the Real-Time Clock time.

Syntax:

void GetTime(RTC_TimeTypeDef* RTC_TimeStruct);

Example Usage:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <M5Core2.h>
RTC_TimeTypeDef TimeStruct;
void setup() {
M5.begin();
M5.Lcd.println("RTC Time TEST");
TimeStruct.Hours = 18;
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct);
}
void loop() {
M5.Rtc.GetTime(&TimeStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
delay(500);
}

SetData()

Description:

Sets the Real-Time Clock date.

Syntax:

void SetData(RTC_TimeTypeDef* RTC_DateStruct);

Example Usage:

cpp
1 2 3 4 5 6 7 8 9 10 11 12
#include <M5Core2.h>
RTC_DateTypeDef DateStruct;
void setup() {
M5.begin();
DateStruct.WeekDay = 3;
DateStruct.Month = 3;
DateStruct.Date = 22;
DateStruct.Year = 2019;
M5.Rtc.SetData(&DateStruct);
}
void loop(){}

GetData()

Description:

Retrieves the Real-Time Clock date.

Syntax:

void GetData(RTC_TimeTypeDef* RTC_DateStruct);

Example Usage:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <M5Core2.h>
RTC_DateTypeDef DateStruct;
void setup() {
M5.begin();
M5.Lcd.println("RTC Date TEST");
DateStruct.WeekDay = 5;
DateStruct.Month = 7;
DateStruct.Date = 23;
DateStruct.Year = 2021;
M5.Rtc.SetDate(&DateStruct);
}
void loop() {
M5.Rtc.GetDate(&DateStruct); // Retrieve the date from the RTC
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Data: %04d-%02d-%02d/n",DateStruct.Year, DateStruct.Month,DateStruct.Date); // Display the current RTC date on the screen
M5.Lcd.printf("Week: %d/n",DateStruct.WeekDay);
delay(500);
}

clearIRQ()

function:

Clear interrupt request

Syntax:

void clearIRQ();

disableIRQ()

function:

Close interrupt request

Syntax:

void disableIRQ();

SetAlarmIRQ()

function:

Set interrupt clock

Syntax:

int SetAlarmIRQ(int afterSeconds);
int SetAlarmIRQ( const RTC_TimeTypeDef &RTC_TimeStruct);
int SetAlarmIRQ( const RTC_DateTypeDef &RTC_DateStruct, const RTC_TimeTypeDef &RTC_TimeStruct);

EXAMPLES:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include <M5Core2.h>
RTC_TimeTypeDef TimeStruct;
void setup() {
M5.begin();
M5.Lcd.println("RTC SetAlarmIQR");
TimeStruct.Hours = 18;
TimeStruct.Minutes = 56;
TimeStruct.Seconds = 10;
M5.Rtc.SetTime(&TimeStruct);
}
void loop() {
M5.update();
M5.Rtc.GetTime(&TimeStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
if(M5.BtnA.wasPressed()){
M5.Lcd.println("M5Core2 Will Close, Restore After 5 seconds ");
delay(2000);
M5.Rtc.clearIRQ();
M5.Rtc.SetAlarmIRQ(5);
delay(10);
M5.Axp.PowerOff();
}
}
On This Page