Is there a RTC Keywords.txt for the R4

Hi,
I am having difficulty understanding how to use "DayOfWeek RTCTime::getDayOfWeek() const { return day_of_week; }" .
Is there a keywords file for the RTC or any help using the library RTC commands?
Thanks

A keywords.txt file will not help you understand the library. Where did you get the library and has it got any examples ?

1 Like

Thank you for your help.
The library is the Arduino Renesas core on github for the R4. The examples don't all work (been written for the renesas chip on the Portenta) . They use commands/keywords that do not seem to be consistent. The rtc library for the ds3231 and similar clocks is pretty straightforward to use. Well explained with examples.
This one for the R4 seems over complicated.

I don't have an R4, but what problem are you having with the getDayOfWeek() function ?

1 Like

I am away from my pc now so can't be specific with function formats and code. From memory printing the date/time is:-

Serial.print(currentTime.getDayOfMonth());
Serial.print("/"); 
Serial.print(Month2int(currentTime.getMonth())); 
Serial.print("/");
Serial.print(currentTime.getYear());
Serial.print(" - ");

Get day of month and get year use the same format.
Get month is different, and if I substitute say getYear() with getDayOfWeek() it will not compile. Can't remember the error. Will have to continue tomorrow with details.
Thanks

The full error message would be helpful

1 Like

I was just reading through the posts and saw this. And yes something like:

    /* GET CURRENT TIME FROM RTC */
    RTC.getTime(currenttime);
    
    /* PRINT CURRENT TIME on Serial */
    Serial.print("Current time: ");
    Serial.print(currenttime.getDayOfWeek());
    Serial.print(" ");
    /* DATE */
    Serial.print(currenttime.getDayOfMonth());
    Serial.print("/");
    Serial.print(Month2int(currenttime.getMonth()));
...

And first part of error messages:

C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\arm-none-eabi-gcc\\7-2017q4/bin/arm-none-eabi-g++" -c -Wall -Wextra -Os -g3 -fno-use-cxa-atexit -fno-rtti -fno-exceptions -MMD -nostdlib -DF_CPU=48000000 -DNO_USB -DBACKTRACE_SUPPORT -DARDUINO_UNOR4_WIFI -MMD -std=gnu++17 -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsigned-char -ffunction-sections -fdata-sections -fmessage-length=0 -fno-builtin -DARDUINO=10607 "-DPROJECT_NAME=\"C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\2A9B4B8244501C149441E70368337DF9/Test_RTC.ino\"" -DARDUINO_UNOWIFIR4 -DARDUINO_ARCH_RENESAS_UNO -DARDUINO_ARCH_RENESAS -DARDUINO_FSP -D_XOPEN_SOURCE -mthumb "@C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\variants\\UNOWIFIR4/defines.txt" -DCFG_TUSB_MCU=OPT_MCU_RAXXX "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1/cores/arduino/tinyusb" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\cores\\arduino/api/deprecated" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\cores\\arduino/api/deprecated-avr-comp" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\cores\\arduino" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\variants\\UNOWIFIR4" "-IC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\libraries\\RTC\\src" "-iprefixC:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1" "@C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\renesas_uno\\1.0.1\\variants\\UNOWIFIR4/includes.txt" "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\2A9B4B8244501C149441E70368337DF9\\sketch\\Test_RTC.ino.cpp" -o "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\2A9B4B8244501C149441E70368337DF9\\sketch\\Test_RTC.ino.cpp.o"
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved202364-34892-2octmx.qu1ui\Test_RTC\Test_RTC.ino: In function 'void loop()':
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved202364-34892-2octmx.qu1ui\Test_RTC\Test_RTC.ino:72:44: error: no matching function for call to 'UART::print(DayOfWeek)'
     Serial.print(currenttime.getDayOfWeek());
                                            ^
In file included from C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/ArduinoAPI.h:31:0,
                 from C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/Arduino.h:4,
                 from C:\Users\kurte\AppData\Local\Temp\arduino\sketches\2A9B4B8244501C149441E70368337DF9\sketch\Test_RTC.ino.cpp:1:
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:63:12: note: candidate: size_t arduino::Print::print(const arduino::__FlashStringHelper*)
     size_t print(const __FlashStringHelper *);
            ^~~~~
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:63:12: note:   no known conversion for argument 1 from 'DayOfWeek' to 'const arduino::__FlashStringHelper*'
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:64:12: note: candidate: size_t arduino::Print::print(const arduino::String&)
     size_t print(const String &);
            ^~~~~
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:64:12: note:   no known conversion for argument 1 from 'DayOfWeek' to 'const arduino::String&'
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:65:12: note: candidate: size_t arduino::Print::print(const char*)
     size_t print(const char[]);
            ^~~~~
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:65:12: note:   no known conversion for argument 1 from 'DayOfWeek' to 'const char*'
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.1\cores\arduino/api/Print.h:66:12: note: candidate: size_t arduino::Print::print(char)
     size_t print(char);
            ^~~~~

I simply added:

   Serial.print(currenttime.getDayOfWeek());
    Serial.print(" ");

lines to the Test_RTC sketch.

In RTC.h DayOfWeek is defined as:

enum class DayOfWeek : uint8_t {
    MONDAY = 1,
    TUESDAY = 2, 
    WEDNESDAY = 3, 
    THURSDAY = 4, 
    FRIDAY = 5, 
    SATURDAY = 6, 
    SUNDAY = 0
};

This will compile:

    /* PRINT CURRENT TIME on Serial */
    Serial.print("Current time: ");
    DayOfWeek dow = currenttime.getDayOfWeek();
    Serial.print((uint8_t)dow);
    Serial.print(" ");
    switch (dow) {
      case DayOfWeek::SUNDAY: Serial.print("Sun "); break;
      case DayOfWeek::MONDAY: Serial.print("Mon "); break;
      case DayOfWeek::TUESDAY: Serial.print("Tue "); break;
      case DayOfWeek::WEDNESDAY: Serial.print("Wed "); break;
      case DayOfWeek::THURSDAY: Serial.print("Thu "); break;
      case DayOfWeek::FRIDAY: Serial.print("Fri "); break;
      case DayOfWeek::SATURDAY: Serial.print("Sat "); break;
    }
    /* DATE */
    Serial.print(currenttime.getDayOfMonth());

However the example sketch will CRASH

First issue: const int LED_ON_INTERRUPT = 22;
The PinMode of that to OUTPUT Will crash.

Quick and dirty change that define to -1;
My output shows:

Test RTC Started:1
After LED_BUILTIN
After LED_ON_INTERRUPT
After RTC.begin
RTC is running
Current time: 4 Thu 25/8/2022 - 14:37:1
P

A lot of those lines were debug lines like:

  Serial.print("Test RTC Started:"); Serial.flush();
  Serial.println(millis(), DEC);
  
  pinMode(LED_BUILTIN, OUTPUT); 
  Serial.println("After LED_BUILTIN"); Serial.flush();
  pinMode(LED_ON_INTERRUPT, OUTPUT);
  Serial.println("After LED_ON_INTERRUPT"); Serial.flush();
  
  RTC.begin();
  Serial.println("After RTC.begin"); Serial.flush();
  RTCTime mytime(25, Month::AUGUST, 2022, 14, 37, 00, DayOfWeek::THURSDAY, SaveLight::SAVING_TIME_ACTIVE);

Note I think it is still crashing as it is showing just a P on last line and nothing after that.

I am guessing that comes from:

void periodic_cbk() {
  static bool clb_st = false;
  if(clb_st) {
    digitalWrite(LED_ON_INTERRUPT,HIGH);
  }
  else {
    digitalWrite(LED_ON_INTERRUPT,LOW);
  }
  clb_st = !clb_st;
 
  Serial.println("PERIODIC INTERRUPT");
}

But that is something to look at later.

Hope that helps

1 Like

Thanks @KurtE a great help.
I now understand I have to use the DayOfWeek dow = getDayOfWeek() to return a day number and then convert that to Text days.
Having seen this :-

DayOfWeek tm2DayOfWeek(struct tm &t) {
    switch(t.tm_wday) {
        case 0: return DayOfWeek::SUNDAY;
        case 1: return DayOfWeek::MONDAY;
        case 2: return DayOfWeek::TUESDAY;
        case 3: return DayOfWeek::WEDNESDAY;
        case 4: return DayOfWeek::THURSDAY;
        case 5: return DayOfWeek::FRIDAY;
        case 6: return DayOfWeek::SATURDAY;
        default: return DayOfWeek::SUNDAY;
    }
    return DayOfWeek::SUNDAY;

There is also one for month so I presumed there was a way of getting day of the week returned in verbose text i.e THURSDAY and also the month i.e. MAY, not just numerical values that need to be translated in the program.

On the hang problem examples "RTC_AutomaticExample.ino also hangs .
void alarmCallback() {
Serial.println("An alarm was triggered at:");

The RTC was just set to:
2023-7-5 11:29:21
A
It stops after the first letter just the same.

Again thanks for your help.

Hi @UKHeliBob, I think I am sorted now. just for reference the error message:-
Arduino: 1.8.19 (Windows 10), TD: 1.57, Board: "Arduino Uno R4 WiFi"

C:\Users\vaughn\Documents\Arduino\Sketches\R4SetFixedTime\R4SetFixedTime.ino: In function 'void loop()':

R4SetFixedTime:20:42: error: no matching function for call to 'UART::print(DayOfWeek)'

Serial.print(currentTime.getDayOfWeek());

Thanks

I would like to add this to the RTC alarm discussion.
I did a post to the topic: UNO R4 WIFI board examples lifted from Portenta C33 not working, Post #5 about how I also experienced "Board hangs when trying to Serial.println("any message") inside an alarmCallback routine."
I decided to try and see how an I2c DS3231 alarm would behave. I loaded the library: RTClib by Adafruit and ran the example: Examples:RTClib:DS3231:DS3231_alarm. I ran the example as is and got this output on the Serial monitor:
Alarm will happen in 10 seconds!

09:31:28 [Alarm1: 05 09:31:38, Mode: Second] SQW: 1 Fired: 0

09:31:30 [Alarm1: 05 09:31:38, Mode: Second] SQW: 1 Fired: 0

09:31:33 [Alarm1: 05 09:31:38, Mode: Second] SQW: 1 Fired: 0

09:31:35 [Alarm1: 05 09:31:38, Mode: Second] SQW: 1 Fired: 0

09:31:37 [Alarm1: 05 09:31:38, Mode: Second] SQW: 1 Fired: 0

A

As with previous test, after the alarm interrupt, only a single character was sent to the Serial monitor before the board hangs.

1 Like

Thanks for the info. I gather you are using the DS3231 via the UNO R4?

Probably like most of us up here, I have not had much of a chance to learn enough about this board to know the ins and outs of the core code and likewise the processor.

But my guess is that when the call to: Serial.println("PERIODIC INTERRUPT");

Each character output will funnel it's way down to:
/* -------------------------------------------------------------------------- */
size_t UART::write(uint8_t c) {
/* -------------------------------------------------------------------------- */  
  if(init_ok) {
    tx_done = false;
    R_SCI_UART_Write(&uart_ctrl, &c, 1);
    while (!tx_done) {}
    return 1;
  }
  else {
    return 0;
  }
}

So there is no buffering of the characters and it sits and waits for the character to be output, which the tx_done is cleared by a callback, which I am guessing is to process an interrupt.
And we are already in an interrupt and the UART callback is not getting called.

Not sure if this processor has nested interrupts or not, or if this is an interrupt priority issue, or ...

Will look more

1 Like

Yes this test was on an R4. And, Oh By The Way, the example DS3231_alarm runs fine on an R3.

1 Like

@KurtE, I found a way to get day of the week straight into the print statement.

char WeekDays[7][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Serial.print(WeekDays[(DayOfWeek2int(currentTime.getDayOfWeek(), 0))]);