diff --git a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md index 65ca66b3c9..f707566916 100644 --- a/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md +++ b/content/hardware/10.mega/boards/giga-r1-wifi/tutorials/giga-dual-core/giga-dual-core.md @@ -558,6 +558,94 @@ int servoMove(int angle) { } ``` +### RTC RPC + +The Real-time Clock (RTC) can be accessed from the M4 core, and using RPC, we can read the values. + +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. + +**M4 sketch:** +```arduino +/** +* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary) +* modified 03 December 2024 +* by Hannes Siebeneicher +*/ + +#include "mbed.h" +#include +#include "RPC.h" + +constexpr unsigned long printInterval{ 1000 }; +unsigned long printNow{}; + +void setup() { + if (RPC.begin()) { + RPC.println("M4: Reading the RTC."); + RTCset(); //sets the RTC to start from a specific time & date + } +} + +void loop() { + if (millis() > printNow) { + RPC.print("M4 System Clock: "); + RPC.println(getLocaltime()); + printNow = millis() + printInterval; + } +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +void RTCset() // Set cpu RTC +{ + tm t; + t.tm_sec = (0); // 0-59 + t.tm_min = (58); // 0-59 + t.tm_hour = (11); // 0-23 + t.tm_mday = (1); // 1-31 + t.tm_mon = (9); // 0-11 "0" = Jan, -1 + t.tm_year = ((24) + 100); // year since 1900, current year + 100 + 1900 = correct year + set_time(mktime(&t)); // set RTC clock +} +``` + +The M7 sketch is found below, and uses RPC to print out the incoming data from the M4. + +**M7 sketch:** +```arduino +/** +* Initial author: Henatu (https://forum.arduino.cc/u/henatu/summary) +* modified 03 December 2024 +* by Hannes Siebeneicher +*/ + +#include "mbed.h" +#include "RPC.h" + +void setup() { + RPC.begin(); + Serial.begin(9600); + while (!Serial) { + ; // Wait for Serial (USB) connection + } + Serial.println("M7: Serial connection initiated"); +} + +void loop() { + if (RPC.available()) { + char incomingByte = RPC.read(); // Read byte from RPC + Serial.write(incomingByte); // Forward the byte to Serial (USB) + } +} + +``` + ### MicroPython RPC LED This example demonstrates how to use MicroPython (running on the M7 core) to remotely control an LED from the M4 core.