Skip to content

Commit c23e95e

Browse files
authoredDec 5, 2024··
Merge pull request #2298 from arduino/hannes7eicher/GIGA-RTC-M4
[PXCT-17] add RTC RPC example
2 parents f779453 + ea7db1b commit c23e95e

File tree

1 file changed

+88
-0
lines changed
  • content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core

1 file changed

+88
-0
lines changed
 

‎content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md

+88
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,94 @@ int servoMove(int angle) {
558558
}
559559
```
560560

561+
### RTC RPC
562+
563+
The Real-time Clock (RTC) can be accessed from the M4 core, and using RPC, we can read the values.
564+
565+
In this example, we set the RTC to a specific date (can be adjusted in the example), send it to the M7 via RPC, and finally prints it out in the Serial Monitor using the M7 core.
566+
567+
**M4 sketch:**
568+
```arduino
569+
/**
570+
* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary)
571+
* modified 03 December 2024
572+
* by Hannes Siebeneicher
573+
*/
574+
575+
#include "mbed.h"
576+
#include <mbed_mktime.h>
577+
#include "RPC.h"
578+
579+
constexpr unsigned long printInterval{ 1000 };
580+
unsigned long printNow{};
581+
582+
void setup() {
583+
if (RPC.begin()) {
584+
RPC.println("M4: Reading the RTC.");
585+
RTCset(); //sets the RTC to start from a specific time & date
586+
}
587+
}
588+
589+
void loop() {
590+
if (millis() > printNow) {
591+
RPC.print("M4 System Clock: ");
592+
RPC.println(getLocaltime());
593+
printNow = millis() + printInterval;
594+
}
595+
}
596+
597+
String getLocaltime() {
598+
char buffer[32];
599+
tm t;
600+
_rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT);
601+
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
602+
return String(buffer);
603+
}
604+
605+
void RTCset() // Set cpu RTC
606+
{
607+
tm t;
608+
t.tm_sec = (0); // 0-59
609+
t.tm_min = (58); // 0-59
610+
t.tm_hour = (11); // 0-23
611+
t.tm_mday = (1); // 1-31
612+
t.tm_mon = (9); // 0-11 "0" = Jan, -1
613+
t.tm_year = ((24) + 100); // year since 1900, current year + 100 + 1900 = correct year
614+
set_time(mktime(&t)); // set RTC clock
615+
}
616+
```
617+
618+
The M7 sketch is found below, and uses RPC to print out the incoming data from the M4.
619+
620+
**M7 sketch:**
621+
```arduino
622+
/**
623+
* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary)
624+
* modified 03 December 2024
625+
* by Hannes Siebeneicher
626+
*/
627+
628+
#include "mbed.h"
629+
#include "RPC.h"
630+
631+
void setup() {
632+
RPC.begin();
633+
Serial.begin(9600);
634+
while (!Serial) {
635+
; // Wait for Serial (USB) connection
636+
}
637+
Serial.println("M7: Serial connection initiated");
638+
}
639+
640+
void loop() {
641+
if (RPC.available()) {
642+
char incomingByte = RPC.read(); // Read byte from RPC
643+
Serial.write(incomingByte); // Forward the byte to Serial (USB)
644+
}
645+
}
646+
647+
```
648+
561649
### MicroPython RPC LED
562650

563651
This example demonstrates how to use MicroPython (running on the M7 core) to remotely control an LED from the M4 core.

0 commit comments

Comments
 (0)
Please sign in to comment.