Skip to content

Commit 66b3a03

Browse files
committed
Merge pull request #4 from rogerclarkmelbourne/master
Fixes
2 parents 28b2d99 + 4f6667a commit 66b3a03

15 files changed

Lines changed: 191 additions & 907 deletions

File tree

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* test-rtc.c
3+
*
4+
* Example program that sets up the Real Time Clock and then blinks the
5+
* LED in patterns for seconds and alarm interrupts.
6+
*
7+
* Created by Rod Gilchrist on 11-12-24.
8+
Ray Burnette: 20150521:
9+
Edited: \Documents\Arduino\hardware\STM32\STM32F1\system\libmaple\stm32f1\include\series\rcc.h to include:
10+
#include <libmaple/bitband.h>
11+
#define RCC_BDCR_RTCSEL_LSI (0x2 << 8)
12+
static inline void rcc_start_lsi(void)
13+
static inline void rcc_start_lse(void)
14+
static inline void rcc_start_hse(void)
15+
16+
Arduino GUI 1.7.3 from Arduino.org
17+
Sketch uses 20,268 bytes (18%) of program storage space. Maximum is 110,592 bytes.
18+
Global variables use 4,552 bytes of dynamic memory.
19+
*/
20+
21+
#include "RTClock.h"
22+
23+
#define BOARD_LED_PIN PB1
24+
25+
int globAlmCnt = 0;
26+
int globOvCnt = 0;
27+
int globSecCnt = 0;
28+
int specAlmCnt = 0;
29+
int lastGlobAlmCnt = -1;
30+
int lastSpecAlmCnt = -1;
31+
32+
void rtc_sec_intr() { if (rtc_is_second()) globSecCnt++; }
33+
void rtc_ovf_intr() { if (rtc_is_overflow()) globOvCnt++; }
34+
void rtc_glob_alm_intr() { if (rtc_is_alarm()) globAlmCnt++; }
35+
void rtc_spec_alm_intr() { if (rtc_is_alarm()) specAlmCnt++; }
36+
37+
void setup() {
38+
// http://forums.leaflabs.com/topic.php?id=1437
39+
// slow! div speed. NOTE! 512 is stop/hang when USB not connected!
40+
// rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_256);
41+
// Normal speed:
42+
// rcc_set_prescaler(RCC_PRESCALER_AHB, RCC_AHB_SYSCLK_DIV_1);
43+
44+
pinMode(BOARD_LED_PIN, OUTPUT);
45+
delay(5000);
46+
Serial.println("begin RTC blink");
47+
delay(1000);
48+
49+
rtc_init(RTCSEL_LSI);
50+
rtc_set_prescaler_load(0x7fff);
51+
rtc_set_count(0);
52+
53+
rtc_attach_interrupt(RTC_SECONDS_INTERRUPT, rtc_sec_intr);
54+
rtc_attach_interrupt(RTC_OVERFLOW_INTERRUPT, rtc_ovf_intr); // expected every 128000 seconds
55+
rtc_attach_interrupt(RTC_ALARM_GLOBAL_INTERRUPT, rtc_glob_alm_intr);
56+
rtc_attach_interrupt(RTC_ALARM_SPECIFIC_INTERRUPT, rtc_spec_alm_intr);
57+
}
58+
59+
void loop() {
60+
int i,n;
61+
62+
Serial.print("Time + interrupt counts: ");
63+
Serial.print(rtc_get_count());
64+
Serial.print(".");
65+
Serial.print(rtc_get_divider());
66+
Serial.print(" (");
67+
Serial.print(globSecCnt);
68+
Serial.print(", ");
69+
Serial.print(globOvCnt);
70+
Serial.print(", ");
71+
Serial.print(globAlmCnt);
72+
Serial.print(", ");
73+
Serial.print(specAlmCnt);
74+
Serial.println(")");
75+
76+
delay(1000);
77+
78+
digitalWrite(BOARD_LED_PIN, 1);
79+
if ((lastSpecAlmCnt != specAlmCnt) || (lastGlobAlmCnt != globAlmCnt)){
80+
lastGlobAlmCnt = globAlmCnt;
81+
lastSpecAlmCnt = specAlmCnt;
82+
83+
Serial.println(" -- alarm -- ");
84+
for (i=0;i<3;i++) { digitalWrite(BOARD_LED_PIN, 0); delay(100); digitalWrite(BOARD_LED_PIN, 1); delay(100);}
85+
n = rtc_get_count() + 5;
86+
rtc_set_alarm(n);
87+
}
88+
89+
delay(1000);
90+
digitalWrite(BOARD_LED_PIN, 0);
91+
}
92+
93+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include <RTClock.h>
2+
3+
RTClock rt (RTCSEL_LSE); // initialise
4+
uint32 tt;
5+
6+
#define LED_PIN PB1
7+
8+
// This function is called in the attachSecondsInterrpt
9+
void blink ()
10+
{
11+
digitalWrite(LED_PIN,!digitalRead(LED_PIN));
12+
}
13+
14+
void setup()
15+
{
16+
pinMode(LED_PIN, OUTPUT);
17+
18+
rt.attachSecondsInterrupt(blink);// Call blink
19+
}
20+
21+
22+
23+
void loop()
24+
{
25+
26+
if (rt.getTime()!=tt)
27+
{
28+
tt = rt.getTime();
29+
30+
Serial.print("time is: ");
31+
Serial.println(tt);
32+
}
33+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#######################################
2+
# Syntax Coloring Map RTClock
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
RTClock KEYWORD1
9+
10+
11+
setTime KEYWORD2
12+
getTime KEYWORD2
13+
14+
createAlarm KEYWORD2
15+
attachSecondsInterrupt KEYWORD2
16+
detachSecondsInterrupt KEYWORD2
17+
setAlarmTime KEYWORD2
18+
19+
20+
#######################################
21+
# Constants (LITERAL1)
22+
#######################################
23+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name=RTClock
2+
version=1.0
3+
author=Various
4+
email=
5+
sentence=Real Time Clock
6+
paragraph=Real Time Clock for STM32F1
7+
url=
8+
architectures=STM32F1
File renamed without changes.

STM32F1/libraries/Untested/RTClock/RTClock.h renamed to STM32F1/libraries/RTClock/src/RTClock.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include "utility/rtc_util.h"
1+
#include <utility/rtc_util.h>
2+
#include <libmaple/rcc.h>
3+
#include <libmaple/bitband.h>
24
#include <time.h>
35

46

File renamed without changes.

STM32F1/libraries/Untested/RTClock/utility/rtc_util.h renamed to STM32F1/libraries/RTClock/src/utility/rtc_util.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
#ifndef _RTC_UTIL_H
3535
#define _RTC_UTIL_H
3636

37-
#include <libmaple\libmaple.h>
38-
#include <libmaple\rcc.h>
39-
#include <libmaple\nvic.h>
40-
#include <libmaple\bitband.h>
41-
#include <libmaple\pwr.h>
42-
#include <libmaple\bkp.h>
43-
#include <libmaple\exti.h>
37+
#include <libmaple/libmaple.h>
38+
#include <libmaple/rcc.h>
39+
#include <libmaple/nvic.h>
40+
#include <libmaple/bitband.h>
41+
#include <libmaple/pwr.h>
42+
#include <libmaple/bkp.h>
43+
#include <libmaple/exti.h>
4444

4545
#define EXTI_RTC_ALARM_BIT 17 // the extra exti interrupts (16,17,18,19) should be defined in exti.h (BUG)
4646

STM32F1/libraries/Untested/RTClock/README

Lines changed: 0 additions & 19 deletions
This file was deleted.

STM32F1/libraries/Untested/RTClock/examples/Test_RTClock/Test_RTClock.ino

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)