Hallo zusammen,
Als Umsteiger auf die XMega Serie hab ich gleich ein erstes Problem:
Folgender Code welcher jeweils einen Interrupt bei fallender Flanke an
PB2 und PB3 auslösen soll funktiniert nicht.
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 |
|
4 | //Interruptroutine Interrupt0
|
5 | ISR(PORTB_INT0_vect){
|
6 | //PC0 auf High schalten
|
7 | PORTC.OUT = PIN0_bm;
|
8 | //PC1 auf Low schalten
|
9 | PORTC.OUT &= ~PIN1_bm;
|
10 | }
|
11 |
|
12 |
|
13 | //Interruptroutine Interrupt1
|
14 | ISR(PORTB_INT1_vect){
|
15 | //PC1 auf High schalten
|
16 | PORTC.OUT = PIN1_bm;
|
17 | //PC0 auf Low schalten
|
18 | PORTC.OUT &= ~PIN0_bm;
|
19 | }
|
20 |
|
21 | void clock_init(void);
|
22 |
|
23 | int main( void )
|
24 | {
|
25 | //clock konfigurieren
|
26 | clock_init();
|
27 | //PC0 und PC1 als Ausgang festlegen
|
28 | PORTC.DIR = PIN0_bm|PIN1_bm;
|
29 | //PB2 und PB3 als Eingang festlegen
|
30 | PORTB.DIRCLR = 0x0c;
|
31 | //Pullupwiderstände und Interrupt bei fallender Flanke festlegen
|
32 | PORTB.PIN2CTRL= PORT_ISC_FALLING_gc;
|
33 | PORTB.PIN3CTRL= PORT_ISC_FALLING_gc;
|
34 | //PB2 dem Interrupt 0 zuordnen
|
35 | PORTB.INT0MASK = 0x04;
|
36 | //PB3 dem Interrupt 1 zuordnen
|
37 | PORTB.INT1MASK = 0x08;
|
38 | //Die Level der Interrupts auf Hoch festlegen
|
39 | PORTB.INTCTRL |= PORT_INT0LVL_HI_gc|PORT_INT1LVL_HI_gc;
|
40 | //Alle Level für die Interrupts freigeben
|
41 | PMIC.CTRL |= PMIC_HILVLEN_bm |PMIC_MEDLVLEN_bm|PMIC_LOLVLEN_bm;
|
42 | //Globale Interruptfreigabe
|
43 | sei();
|
44 | //Ausgang PC0 auf High schalten
|
45 | PORTC.OUT = PIN0_bm;
|
46 | while (1){
|
47 | }
|
48 | return 0;
|
49 | }
|
50 |
|
51 | void clock_init(void){
|
52 | //Oszillator auf 32Mhz stellen
|
53 | OSC.CTRL |= OSC_RC32MEN_bm;
|
54 | // Warten bis der Oszillator bereit ist
|
55 | while(!(OSC.STATUS & OSC_RC32MRDY_bm));
|
56 | //Schützt I/O Register, Interrupts werden ignoriert
|
57 | CCP = CCP_IOREG_gc;
|
58 | //aktiviert den internen Oszillator
|
59 | CLK.CTRL = (CLK.CTRL & ~CLK_SCLKSEL_gm) | CLK_SCLKSEL_RC32M_gc;
|
60 | }
|
Vielleicht hat jemand einen Tip für mich, seh gerade dan Wald vor lauter
Bäumen nicht.
Gruß,
Max