Skip to content

Commit 5b2d9f7

Browse files
committed
Add examples
1 parent e36cc61 commit 5b2d9f7

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* Author: Nathan Seidle
2+
Created: Septempter 27th, 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to initialize and read from the on board RTC.
6+
Most SparkFun Artemis boards have the necessary external 32kHz crystal to
7+
enable the RTC. If you are using the Artemis module bare you will either
8+
need an external 32kHz xtal or use the internal LFRC. Read the datasheet
9+
section 12.1 for more information.
10+
11+
This example is based on the Ambiq SDK EVB2 RTC example.
12+
*/
13+
14+
#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
15+
APM3_RTC myRTC; //Create instance of RTC class
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println("SparkFun RTC Example");
21+
22+
myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
23+
//myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM
24+
}
25+
26+
void loop()
27+
{
28+
myRTC.getTime();
29+
30+
Serial.printf("It is now ");
31+
Serial.printf("%d:", myRTC.hour);
32+
Serial.printf("%02d:", myRTC.minute);
33+
Serial.printf("%02d.", myRTC.seconds);
34+
Serial.printf("%02d", myRTC.hundredths);
35+
36+
Serial.printf(" %02d/", myRTC.month);
37+
Serial.printf("%02d/", myRTC.dayOfMonth);
38+
Serial.printf("%02d", myRTC.year);
39+
40+
Serial.printf(" Day of week: %d =", myRTC.weekday);
41+
Serial.printf(" %s", myRTC.textWeekday);
42+
43+
Serial.println();
44+
45+
delay(1000);
46+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/* Author: Nathan Seidle
2+
Created: Septempter 27th, 2019
3+
License: MIT. See SparkFun Arduino Apollo3 Project for more information
4+
5+
This example demonstrates how to put the core to sleep for a number of
6+
milliseconds before waking and printing the current time/date. This
7+
is helpful for checking power consumption of the core while RTC+CT6 are running.
8+
*/
9+
10+
#include "RTC.h" //Include RTC library included with the Aruino_Apollo3 core
11+
APM3_RTC myRTC; //Create instance of RTC class
12+
13+
uint32_t msToSleep = 2000; //This is the user editable number of ms to sleep between RTC checks
14+
#define TIMER_FREQ 3000000L //Counter/Timer 6 will use the HFRC oscillator of 3MHz
15+
uint32_t sysTicksToSleep = msToSleep * (TIMER_FREQ / 1000);
16+
17+
void setup()
18+
{
19+
Serial.begin(115200);
20+
Serial.println("SparkFun RTC Example");
21+
22+
myRTC.setToCompilerTime(); //Easily set RTC using the system __DATE__ and __TIME__ macros from compiler
23+
//myRTC.setTime(7, 28, 51, 0, 21, 10, 15); //Manually set RTC back to the future: Oct 21st, 2015 at 7:28.51 AM
24+
25+
setupWakeTimer();
26+
}
27+
28+
void loop()
29+
{
30+
myRTC.getTime();
31+
32+
Serial.printf("It is now ");
33+
Serial.printf("%d:", myRTC.hour);
34+
Serial.printf("%02d:", myRTC.minute);
35+
Serial.printf("%02d.", myRTC.seconds);
36+
Serial.printf("%02d", myRTC.hundredths);
37+
38+
Serial.printf(" %02d/", myRTC.month);
39+
Serial.printf("%02d/", myRTC.dayOfMonth);
40+
Serial.printf("%02d", myRTC.year);
41+
42+
Serial.printf(" Day of week: %d =", myRTC.weekday);
43+
Serial.printf(" %s", myRTC.textWeekday);
44+
45+
Serial.println();
46+
47+
am_hal_sysctrl_sleep(AM_HAL_SYSCTRL_SLEEP_DEEP); //Sleepy time
48+
}
49+
50+
//We use counter/timer 6 for this example but 0 to 7 are available
51+
//CT 7 is used for Software Serial. All CTs are used for Servo.
52+
void setupWakeTimer()
53+
{
54+
//Clear compare interrupt
55+
am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG); //Use CT6
56+
57+
am_hal_stimer_int_enable(AM_HAL_STIMER_INT_COMPAREG); // Enable C/T G=6
58+
59+
//Don't change from 3MHz system timer, but enable G timer
60+
am_hal_stimer_config(AM_HAL_STIMER_CFG_CLEAR | AM_HAL_STIMER_CFG_FREEZE);
61+
am_hal_stimer_config(AM_HAL_STIMER_HFRC_3MHZ | AM_HAL_STIMER_CFG_COMPARE_G_ENABLE);
62+
63+
//Setup ISR to trigger when the number of ms have elapsed
64+
am_hal_stimer_compare_delta_set(6, sysTicksToSleep);
65+
66+
//Enable the timer interrupt in the NVIC.
67+
NVIC_EnableIRQ(STIMER_CMPR6_IRQn);
68+
}
69+
70+
//Called once number of milliseconds has passed
71+
extern "C" void am_stimer_cmpr6_isr(void)
72+
{
73+
uint32_t ui32Status = am_hal_stimer_int_status_get(false);
74+
if (ui32Status & AM_HAL_STIMER_INT_COMPAREG)
75+
{
76+
am_hal_stimer_int_clear(AM_HAL_STIMER_INT_COMPAREG);
77+
78+
//Reset compare value. ISR will trigger when the number of ms have elapsed
79+
am_hal_stimer_compare_delta_set(6, sysTicksToSleep);
80+
}
81+
}

0 commit comments

Comments
 (0)