EDIT: This is very weird - I have swapped for another (virtually identical board) and the below issue does not present (i.e. the clock keeps counting). Is the board's RTC defective?
Hi
I have an Arduino Zero and I am using this library to keep a track of the time using the inbuilt 'rtc'. However, I have noticed that my rtc stops counting time when I call the sendText() function. The code below demonstrates the problem:
#include <Arduino.h>
#include <RtcAlarmScheduler.h>
#include <RadioFunctions.h>
// clock object
RTCZero remoteStationClock;
// alarms and ISRs
#define CS_M0 8
#define RST_M0 4
#define INT_M0 3
// Radio settings
const int FREQ = 434;
const int TX_PWR = 20;
const int SPREAD_FACTOR = 12;
const int BANDWIDTH = 125E3;
const int CODING_DENOM = 5;
const bool CRC_ON = true;
RH_RF95 remoteStationRadio(CS_M0, INT_M0);
char TEST_TXT[] = "HELLO TEST WORLD BLAH BLAH BLAH. GOODBYE!HELLO TEST WORLD BLAH BLAH BLAH. GOODBYE!HELLO TEST WORLD BLAH BLAH BLAH. GOODBYE!";
bool sendText(const char* txt, RH_RF95& radio)
{
if ( !radio.send( (uint8_t*)txt, strlen(txt)) )
{
return false;
}
if ( !radio.waitPacketSent() )
{
return false;
}
radio.setModeRx(); // put back into RX mode
return true;
}
void setup() {
Serial.begin(9600);
const int C_TIME = 1622494907;
Serial.print("TIME IS: ");
Serial.println(C_TIME);
remoteStationClock.begin();
remoteStationClock.setEpoch(C_TIME);
setupRadio(remoteStationRadio,RST_M0, FREQ, TX_PWR, SPREAD_FACTOR, BANDWIDTH, CODING_DENOM, CRC_ON);
Serial.println("RADIO SETUP");
}
void loop() {
delay(10000);
Serial.print("EPOCH START:");
Serial.println(remoteStationClock.getEpoch());
uint32_t startSW = millis();
if ( !sendText(TEST_TXT, remoteStationRadio) )
{
Serial.println("FAILED TO SEND");
}
Serial.print("SEND TIME (MSECS):");
Serial.println(millis() - startSW);
Serial.print("EPOCH END:");
Serial.println(remoteStationClock.getEpoch());
Serial.println("");
}
This produces the following output:
EPOCH START:1622494917
SEND TIME (MSECS):4926
EPOCH END:1622494917 // why isn't this 1622494917 + 4.9 secs?
EPOCH START:1622494927
SEND TIME (MSECS):4926
EPOCH END:1622494928
EPOCH START:1622494938
SEND TIME (MSECS):4925
EPOCH END:1622494938
Does anyone know what might be going on here? Why does the clock stop during this function?
Thanks