RTC

Please use M5.begin() to initialize the RTC-related functions before use.

RTC_Time & RTC_Date Structures

typedef struct RTC_Time {
    int8_t hour;
    int8_t min;
    int8_t sec;
    RTC_Time() : hour(), min(), sec() {}
    RTC_Time(int8_t h, int8_t m, int8_t s) : hour(h), min(m), sec(s) {}
} rtc_time_t;

typedef struct RTC_Date {
    int8_t week;
    int8_t mon;
    int8_t day;
    int16_t year;
    RTC_Date() : week(), mon(), day(), year() {}
    RTC_Date(int8_t w, int8_t m, int8_t d, int16_t y)
        : week(w), mon(m), day(d), year(y) {}
} rtc_date_t;

Begin()

Function:

Initialize RTC

Please use M5.RTC.begin() to initialize RTC related functions before using

Syntax:

void begin()

setTime()

Function:

Set structure variable time

Syntax:

void setTime(const rtc_time_t *time)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_time_t RTCtime;

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCtime.hour = 00;
    RTCtime.min  = 00;
    RTCtime.sec  = 00;
    M5.RTC.setTime(&RTCtime);
}

void loop() {}

getTime()

Function:

Get structure time

Syntax:

void getTime(rtc_time_t *time)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

rtc_time_t RTCtime;
char timeStrbuff[64];

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCtime.hour = 00;
    RTCtime.min  = 00;
    RTCtime.sec  = 00;
    M5.RTC.setTime(&RTCtime);
}

void loop() {
    M5.RTC.getTime(&RTCtime);
    sprintf(timeStrbuff, "%02d:%02d:%02d", RTCtime.hour, RTCtime.min,
            RTCtime.sec);
    canvas.drawString(timeStrbuff, 0, 0);
    canvas.pushCanvas(200, 200, UPDATE_MODE_DU4);
    delay(2000);
}

setDate()

Function:

Set structure variable date

Syntax:

void setDate(const rtc_date_t *date)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_date_t RTCDate;

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCDate.year = 2020;
    RTCDate.mon  = 11;
    RTCDate.day  = 27;
    M5.RTC.setDate(&RTCDate);
}

void loop() {}

getDate()

Function:

Get structure variable date

Syntax:

void getDate(rtc_date_t *date)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);
rtc_date_t RTCDate;
char timeStrbuff[64];

void setup() {
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(500, 300);
    canvas.setTextSize(3);

    RTCDate.year = 2020;
    RTCDate.mon  = 11;
    RTCDate.day  = 27;
    M5.RTC.setDate(&RTCDate);
}

void loop() {
    M5.RTC.getDate(&RTCDate);
    sprintf(timeStrbuff, "%02d:%02d:%02d", RTCDate.year, RTCDate.mon,
            RTCDate.day);
    canvas.drawString(timeStrbuff, 0, 0);
    canvas.pushCanvas(150, 200, UPDATE_MODE_DU4);
    delay(10000);
}

SetAlarmIRQ()

Function:

Set interrupt clock

Syntax:

int SetAlarmIRQ(int afterSeconds)

int setAlarmIRQ(const rtc_time_t &time)

int setAlarmIRQ(const rtc_date_t &date, const rtc_time_t &time)

Example:

#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();
  }
}

clearIRQ()

Function:

Clear interrupt request

Syntax:

void clearIRQ()

disableIRQ()

Function:

Close interrupt request

Syntax:

void disableIRQ()

On This Page