SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By Bobby13
#192909
Hello Together,

i have the sparkfun SAMD21 dev breakout board, and did all the examples form the Hookup Guide including the Example for the Real-Time Clock.

I started to use the Arduino IDE 1.8.1 to get the board running with that, that worked very well. :) (Thanks to sparkfun!!!)
Now i moved to the Atmel Studio 7.0.1188 and created there a new project from an exisiting arduino project "Real-Time Clock".
To communicate to the Sparkfun dev board i have an atmel-ice which is also working, and now the interesting part is comming....

I want to put the samd21 into standby mode, and via an alarm, it should wake up, do something, set a new alarm, and go to standby again.
In the RTCZero Library from Arduino, ther is a method available called rtc.standbyMode() but it seems in my case it is not working.

In the function itself it is commented, that "Entering standby mode when connected via the native USB port causes issues."
So i tried to disconnect my SAMD21 dev breakout board from the usb and run it via the LiPo battery, but this did not helped.

For me it seems, like the rtc.standbyMode() call will be just ignored, and the SAMD21 will stay active.
I controll this via the led's. The blue led is triggered via the alarm every minute, this is working, and in the main loop i blink the RX-Led,
to be able to controll if i'm in active mode or in standby.

To understand what i did, here the complete code:
Code: Select all
/*Begining of Auto generated code by Atmel studio */
#include <Arduino.h>

/*End of auto generated code by Atmel studio */

#include <RTCZero.h> // Include RTC library - make sure it's installed!

void alarmMatch();
//End of Auto generated function prototypes by Atmel Studio



RTCZero rtc; // Create an RTC object
byte lastSecond = 60;
byte alarmMinute = 1; // Minutes after clock starts to sound alarm
bool alarmTriggered = false;


//*********************
const int BLUE_LED = 13; // Blue "stat" LED on pin 13
const int RX_LED = PIN_LED_RXL; // RX LED on pin 25, we use the predefined PIN_LED_RXL to make sure
const int TX_LED = PIN_LED_TXL; // TX LED on pin 26, we use the predefined PIN_LED_TXL to make sure

bool ledState = LOW;

void setupled()
{
	pinMode(BLUE_LED, OUTPUT);
	pinMode(RX_LED, OUTPUT);
	pinMode(TX_LED, OUTPUT);
}

void led_blink_once()
{
	digitalWrite(RX_LED, LOW); // RX LED on
	delay(333);
	digitalWrite(RX_LED, HIGH); // RX LED off
	digitalWrite(TX_LED, LOW); // TX LED on
	delay(333);
	digitalWrite(TX_LED, HIGH); // TX LED off
	digitalWrite(BLUE_LED, HIGH); // Blue LED on
	delay(333);
	digitalWrite(BLUE_LED, LOW); // Blue LED off
}

void setupAlarm()
{
	// Set new alarm time
	byte minute = rtc.getMinutes();
	byte hour = rtc.getHours();
	byte alarmHour = hour + ((alarmMinute + minute) / 60);
	alarmMinute = (alarmMinute + minute) % 60;
		
	// To set an alarm, use the setAlarmTime function.
	rtc.setAlarmTime(alarmHour, alarmMinute, rtc.getSeconds());
	// After the time is set, enable the alarm, configuring
	// which time values you want to trigger the alarm
	rtc.enableAlarm(rtc.MATCH_HHMMSS); // Alarm when hours, minute, & second match
}

void setup() 
{
  setupled();
  led_blink_once();

  byte hour = 1;
  byte minute = 0; // Get the minute
  byte second = 0; // Get the second
  byte day = 14; // Get the day
  byte month = 1; // Get the month
  byte year = 17; // Get the year

  rtc.begin(); // To use the RTC, first begin it
  rtc.setTime(hour, minute, second); // Then set the time
  rtc.setDate(day, month, year); // And the date

  // Configure the alarm for the next minute
  setupAlarm();
  
  // When the alarm triggers, alarmMatch will be called:
  rtc.attachInterrupt(alarmMatch);
  
  rtc.standbyMode();
}

void loop() 
{
	digitalWrite(RX_LED, LOW); // RX LED on
	delay(333);
	digitalWrite(RX_LED, HIGH); // RX LED off
	delay(1000);
	
	if(alarmTriggered)
	{
		alarmTriggered = false;
		digitalWrite(BLUE_LED, HIGH); // Blue LED on
		delay(333);
		digitalWrite(BLUE_LED, LOW); // Blue LED off
		
		// Set the new alarm time
		setupAlarm();
		
		// When the alarm triggers, alarmMatch will be called:
		rtc.attachInterrupt(alarmMatch);
		
		rtc.standbyMode();
	}
}

void alarmMatch()
{
  // This function is called when the alarm values match
  // and the alarm is triggered.
  alarmTriggered = true; // Set the global triggered flag
}
Do somebody have an idea, what i did wrong here, or what i need to change, that i get this functionality working?
Any help would be welcome.

Thank you very much in advance,
best regards,

Bobby