Skip to content

Commit 6c2cd1c

Browse files
Aymane-STfpistm
authored andcommitted
fix(RTC): RTC_Tests example for new STM32RTC prediv API (uint32_t)
- use uint32_t for userPredA, userPredS and local prediv variables (a, s), - call rtc.getPrediv() and rtc.setPrediv() with uint32_t arguments, - use PREDIVA_MAX + 1 and PREDIVS_MAX + 1 to reset prescalers to computed values See: stm32duino/STM32RTC@9d07ee5 Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent 2869f14 commit 6c2cd1c

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

examples/NonReg/RTC/RTC_Tests/RTC_Tests.ino

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,8 @@ static const char* mytime = __TIME__;
3838
clk = RTCCLK / ((predA +1) * (predS +1))
3939
clk = 1000000 / ((99 +1) * (9999+1)) = 1 Hz
4040
*/
41-
#if defined(STM32F1xx)
4241
static uint32_t userPredA = 99;
43-
#else
44-
static int8_t userPredA = 99;
45-
#endif /* STM32F1xx */
46-
static int16_t userPredS = 9999;
42+
static uint32_t userPredS = 9999;
4743

4844
/* */
4945
static byte seconds = 0;
@@ -112,35 +108,35 @@ void loop()
112108

113109
#if defined(STM32F1xx)
114110
Serial.println("Testing only asynchronous prescaler setting");
115-
uint32_t a;
116111
#else
117112
Serial.println("Testing asynchronous and synchronous prescaler setting");
118-
int8_t a;
119113
#endif /* STM32F1xx */
120-
int16_t s = 0;
114+
uint32_t a = 0;
115+
uint32_t s = 0;
116+
121117
rtc.getPrediv(&a, &s);
122118
Serial.print("Async/Sync for default LSI clock: ");
123-
Serial.printf("%i/%i\n", a, s);
119+
Serial.printf("%u/%u\n", a, s);
124120
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
125121
Serial.print("Async/Sync for selected clock: ");
126122
rtc.getPrediv(&a, &s);
127-
Serial.printf("%i/%i\n", a, s);
123+
Serial.printf("%u/%u\n", a, s);
128124
rtc.end();
129125

130126
if (clkSource == rtc.HSE_CLOCK) {
131-
Serial.printf("User Async/Sync set to %i/%i:", userPredA, userPredS);
127+
Serial.printf("User Async/Sync set to %u/%u:", userPredA, userPredS);
132128
rtc.setPrediv(userPredA, userPredS);
133129
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
134130
rtc.getPrediv(&a, &s);
135-
Serial.printf("%i/%i\n", a, s);
131+
Serial.printf("%u/%u\n", a, s);
136132
printDateTime(10, 1000, false);
137133
}
138134

139135
Serial.print("User Async/Sync reset to use the computed one: ");
140-
rtc.setPrediv(-1, -1);
136+
rtc.setPrediv(PREDIVA_MAX + 1, PREDIVS_MAX + 1);
141137
rtc_config(clkSource, rtc.HOUR_24, mydate, mytime);
142138
rtc.getPrediv(&a, &s);
143-
Serial.printf("%i/%i\n", a, s);
139+
Serial.printf("%u/%u\n", a, s);
144140

145141
// Check date change
146142
Serial.println("Testing date and time");

0 commit comments

Comments
 (0)