<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Resetting RTC flag]]></title><description><![CDATA[<p dir="auto">I cannot get the RTC flag on my M5paper to work correctly. Using the example RTC_WakeUp the screen always reads "Power on by: RTC timer" however the device was started. Even if I press the reset button first and then the on button, the screen still says  "Power on by: RTC timer". I seems the   <em>if ((data &amp; 0b00000100) == 0b00000100)</em> statement is always true. How can I reset it?</p>
<pre><code class="language-cpp">#include &lt;M5EPD.h&gt;

M5EPD_Canvas canvas(&amp;M5.EPD);

void setup() {
  //  Check power on reason before calling M5.begin()
  //  which calls RTC.begin() which clears the timer flag.
  Wire.begin(21, 22);                  
  uint8_t data = M5.RTC.readReg(0x01);     
   
  M5.begin();

  bool flagRTC = false;
  
  // Check timer flag
  if ((data &amp; 0b00000100) == 0b00000100) {
    flagRTC = true;
    Serial.println("Power on by: RTC timer");
  }
  else {
    Serial.println("Power on by: PWR Btn");
  }
     
  M5.EPD.SetRotation(90);
  M5.TP.SetRotation(90);
  M5.EPD.Clear(true);
  M5.RTC.begin();
  
  canvas.createCanvas(540, 960);  
  canvas.setTextSize(3);
  if (flagRTC)
    canvas.drawString("Power on by: RTC timer", 25, 250); // &lt;= this one we should when waking up from sleep
  else  
    canvas.drawString("Power on by: PWR Btn", 25, 250);
    
  canvas.drawString("Press PWR Btn for sleep!", 45, 350);
  canvas.drawString("after 5 sec wakeup!", 70, 450);
  canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
}

void loop() {
  if (M5.BtnP.wasPressed()) {    
    canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550);
    canvas.pushCanvas(0, 0, UPDATE_MODE_DU4);
    delay(1000);
    M5.shutdown(5); // shut donw now and wake up after 5 seconds
  }
  M5.update();
  delay(100);
}

</code></pre>
]]></description><link>https://community.m5stack.com/topic/5830/resetting-rtc-flag</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 06:38:04 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/5830.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 20 Nov 2023 12:48:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Resetting RTC flag on Tue, 21 Nov 2023 11:20:01 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/steve1" aria-label="Profile: Steve1">@<bdi>Steve1</bdi></a></p>
<p dir="auto">well, there is an alternative method you could use. The power button also acts as regular button. So you could check if the power button was still pressed when M5Paper starts running. Something like this at the beginning of  <code>setup()</code>:</p>
<pre><code>  M5.begin(true, false, true, true, true);
  M5.RTC.begin();

  M5.update();
  bool pwrBtnStart = M5.BtnP.isPressed(); // true if started by PWR button
</code></pre>
<p dir="auto">Note: for it to work you'll need to press and hold the power button long enough for the code to reach the statement checking the button. In my tests I need to hold the power button for about 5 seconds.</p>
<p dir="auto">Note: a disadvantage of the power button check method is that when M5Paper is powered on by USB it thinks it was an RTC start.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/22844</link><guid isPermaLink="true">https://community.m5stack.com/post/22844</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Tue, 21 Nov 2023 11:20:01 GMT</pubDate></item><item><title><![CDATA[Reply to Resetting RTC flag on Tue, 21 Nov 2023 08:46:44 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for the insights folks. However I am still confused as to how have an RTC restart do one thing and a power button restart do another.</p>
<p dir="auto">My practical goal is to have the M5Paper go online and retrieve the NTP time data on a button power on but, in order to save battery charge to simply use the RTC for time data on an RTC restart.</p>
]]></description><link>https://community.m5stack.com/post/22841</link><guid isPermaLink="true">https://community.m5stack.com/post/22841</guid><dc:creator><![CDATA[Steve1]]></dc:creator><pubDate>Tue, 21 Nov 2023 08:46:44 GMT</pubDate></item><item><title><![CDATA[Reply to Resetting RTC flag on Mon, 20 Nov 2023 16:55:03 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/cognitive5525" aria-label="Profile: Cognitive5525">@<bdi>Cognitive5525</bdi></a></p>
<p dir="auto">they are overwritten (and cleared) by calling <code>M5.RTC.begin();</code>.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/22836</link><guid isPermaLink="true">https://community.m5stack.com/post/22836</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Mon, 20 Nov 2023 16:55:03 GMT</pubDate></item><item><title><![CDATA[Reply to Resetting RTC flag on Mon, 20 Nov 2023 16:41:52 GMT]]></title><description><![CDATA[<p dir="auto">I don't think this is a reliable way of checking whether the boot was caused by the RTC or the some other reason. From the <a href="https://www.nxp.com/docs/en/data-sheet/PCF8563.pdf" target="_blank" rel="noopener noreferrer nofollow ugc">BM8563 datasheet</a> (my highlighting):</p>
<blockquote>
<p dir="auto">8.3.2.1 Interrupt output<br />
Bits TF and AF: When an alarm occurs, AF is set to logic 1. Similarly, at the end of a<br />
timer countdown, TF is set to logic 1. <strong>These bits maintain their value until overwritten<br />
using the interface.</strong> If both timer and alarm interrupts are required in the application, the<br />
source of the interrupt can be determined by reading these bits. To prevent one flag being<br />
overwritten while clearing another, a logic AND is performed during a write access.</p>
</blockquote>
]]></description><link>https://community.m5stack.com/post/22835</link><guid isPermaLink="true">https://community.m5stack.com/post/22835</guid><dc:creator><![CDATA[Cognitive5525]]></dc:creator><pubDate>Mon, 20 Nov 2023 16:41:52 GMT</pubDate></item><item><title><![CDATA[Reply to Resetting RTC flag on Mon, 20 Nov 2023 15:20:39 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/steve1" aria-label="Profile: Steve1">@<bdi>Steve1</bdi></a></p>
<p dir="auto">try to check the timer interrupt enable bit as well, like this:</p>
<pre><code>if ((data &amp; 0b00000101) == 0b00000101) 
</code></pre>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/22832</link><guid isPermaLink="true">https://community.m5stack.com/post/22832</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Mon, 20 Nov 2023 15:20:39 GMT</pubDate></item></channel></rss>