Skip to content

Commit 92bf11a

Browse files
committed
Upon further inspection it seems set time isnt working, get time seems to be working, and the RTC is defo running (seen from seconds counting up)
1 parent 6ee708a commit 92bf11a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

examples/rtc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() -> ! {
5050
let mut timer = Delay::new(cp.SYST, clocks);
5151
let mut pwr = Pwr::pwr(&mut rcc.apb1r1);
5252
let rtc = Rtc::rtc(dp.RTC, &mut rcc.apb1r1, &mut rcc.bdcr, &mut pwr.cr1);
53-
let time = Time::new(0, 0, 19, false);
53+
let time = Time::new(19, 0, 0, false);
5454
rtc.set_time(&time);
5555

5656
timer.delay_ms(1000_u32);

src/rtc.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ pub struct Time {
1616
impl Time {
1717
pub fn new(hours: u8, minutes: u8, seconds: u8, daylight_savings: bool) -> Self {
1818
Self {
19-
seconds: seconds,
20-
minutes: minutes,
2119
hours: hours,
20+
minutes: minutes,
21+
seconds: seconds,
2222
daylight_savings: daylight_savings
2323
}
2424
}
@@ -108,11 +108,11 @@ impl Rtc {
108108
w.pm()
109109
.clear_bit()
110110
.hu()
111-
.bits(byte_to_bcd2(time.hours as u8))
111+
.bits(time.hours)
112112
.mnu()
113-
.bits(byte_to_bcd2(time.minutes as u8))
113+
.bits(time.minutes)
114114
.su()
115-
.bits(byte_to_bcd2(time.seconds as u8))
115+
.bits(time.seconds)
116116

117117
});
118118

@@ -135,11 +135,12 @@ impl Rtc {
135135
{
136136
let timer = self.rtc.tr.read();
137137
let cr = self.rtc.cr.read();
138-
time = Time::new(timer.su().bits(), timer.mnu().bits(), timer.hu().bits(), cr.fmt().bit());
138+
time = Time::new(timer.hu().bits(), timer.mnu().bits(), timer.su().bits(), cr.fmt().bit());
139139
}
140140
init_mode(&self.rtc, false);
141141
}
142142
write_protection(&self.rtc, true);
143+
143144
time
144145
}
145146

0 commit comments

Comments
 (0)