Hallo Ihr, ich versuche den RTC zum laufen zu bekommen, scheine aber irgendwas im Datenblatt übersehen zu haben. Könnt Ihr mal drüber sehen?
1 | #define F_CPU 20000000 |
2 | |
3 | #include <avr/io.h> |
4 | #include <avr/cpufunc.h> |
5 | #include <avr/interrupt.h> |
6 | #include <util.h> |
7 | #include <util/delay.h> |
8 | |
9 | uint64_t systemtick64_10ms = 0; |
10 | |
11 | void CLOCK_init(){ |
12 | ccp_write_io((void*)& CLKCTRL.MCLKCTRLA,0); // Masterclock set to 16/20MHz, CLK_OUT is off |
13 | ccp_write_io((void*)& CLKCTRL.MCLKCTRLB,0); // no division, prescaler disabled |
14 | |
15 | RTC.CLKSEL = 0x00; // internal rtc |
16 | RTC.CNT = 16384; // 2Hz for Debugtest, original 327 // 16Bit counter value for 10ms period @ prescaler 0 & 32768Hz (10.009ms) |
17 | RTC.CTRLA = 0x01; // no prescaler - rtc enable |
18 | RTC.INTCTRL = 0b00000001; // Overflow |
19 | } |
20 | |
21 | void pinout_init(){ |
22 | PORTA.DIR = 0b01001000; // PA 3 & 6 are output, others are input |
23 | PORTA.PIN3CTRL = 0x00; // Signal inverted by transistor - writing 1 to this output will pull the reset on mainboard to 0V |
24 | PORTA.PIN6CTRL = 0x80; // Signal inverted on µC, writing 1 will pull CFGMODE to 0 (activate mode) |
25 | } |
26 | |
27 | int main(){ |
28 | CLOCK_init(); |
29 | pinout_init(); |
30 | sei(); |
31 | while (1) { |
32 | ; |
33 | } |
34 | } |
35 | |
36 | ISR(RTC_CNT_vect){ // OVF for CTC Mode |
37 | PORTA.OUTTGL |= PIN6_bm; // toggelt CFGMODE zu Testzwecken |
38 | //RTC.INTFLAGS = RTC_OVF_bm; // clear interrupt |
39 | } |