User Tools

Site Tools


en-us_commands:reference:irtcset

This is an old revision of the document!


IrtcSet()

IrtcSet() sets the RTC date and time.

IrtcSet command operation flow

bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
bool IrtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t dayOfWeek, uint8_t hour, uint8_t minute, uint8_t second)

Commands

Command Arguments Return Value Operation
IrtcSet(year, month, day, hour, minute, second) uint16_t year2000~2099
uint8_t month1~12
uint8_t day — Valid day of the specified month
uint8_t hour0~23
uint8_t minute0~59
uint8_t second0~59
bool Sets the RTC date and time.

Example

void setup() {
  Serial.begin(115200);
 
  if (!IrtcBegin()) {
    Serial.println(F("DS3231 connection failed"));
    return;
  }
 
  // Run once initially, then comment out.
  // IrtcSet(2026, 8, 10, 14, 30, 0);
}
 
void loop() {
  IrtcDateTime now;
  if (IrtcRead(now)) {
    Serial.print(now.year);
    Serial.print('/');
    Serial.print(now.month);
    Serial.print('/');
    Serial.print(now.day);
    Serial.print(' ');
    Serial.print(now.hour);
    Serial.print(':');
    Serial.print(now.minute);
    Serial.print(':');
    Serial.println(now.second);
  }
  delay(1000);
}

Precautions

Run each device's corresponding Begin command first. Check I²C addresses and pin sharing; if the bool return value is false, inspect wiring and power.

← Built-in Command List

en-us_commands/reference/irtcset.1788785568.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki