Set port pin interrupt

Droopy
Benutzer
Avatar
Gender:
Age: 58
Posts: 24
Registered: 01 / 2016
Subject:

Set port pin interrupt

 · 
Posted: 12.12.2018 - 16:50  ·  #1
Hello all,

I've already used interrupts for a timer in AVRco, but now i need to set and serve a port pin interrupt. For instance, I want an interrupt when Port pin E4 get high on a Xmega256A3u?

Can some help me for this?

Thnx a lot;)
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Set port pin interrupt

 · 
Posted: 12.12.2018 - 17:00  ·  #2
Hello Droopy,

there are two samples:
XMega_PortInt
XMega_PCIint
in the demos directory.

rolf
Droopy
Benutzer
Avatar
Gender:
Age: 58
Posts: 24
Registered: 01 / 2016
Subject:

Re: Set port pin interrupt

 · 
Posted: 12.12.2018 - 21:37  ·  #3
Ok thnx Rolf, I forgot to look to the demos :oops:
Lschreyer
Schreiberling
Avatar
Gender: n/a
Posts: 527
Registered: 02 / 2007
Subject:

Re: Set port pin interrupt

 · 
Posted: 13.12.2018 - 17:53  ·  #4
For example on a Xmega:

DDRE:= %11101000; // I/O Direction: 0= input, 1= Output
PIN0CTRLE:= %00011000; //Activate Pullup
PIN1CTRLE:= %00011000; //Activate Pullup
PIN2CTRLE:= %00011000; //Activate Pullup
PIN3CTRLE:= %00000000; //
PIN4CTRLE:= %00000010; //Pinchange Interrupt Active Low: Falling Sense Bit 0-1 = 10
PIN5CTRLE:= %00000000; //
PIN6CTRLE:= %00000000; //
PIN7CTRLE:= %00000000; //

INTCTRLE:= %00000010; // Interrupt Level medium for Int0
INT0MASKE:= %00010000; // Pin 4 Interrupt #0 (There is also INT1MASKE for INT #1)


For each PINxCTRLn you have


Bit 7 – SRLEN: Slew Rate Limit Enable Setting this bit will enable slew rate limiting on pin n.
Bit 6 – INVEN: Inverted I/O Enable Setting this bit will enable inverted output and input data on pin n.

Bit 5:3 – OPC: Output and Pull Configuration
000 TOTEM Totem-pole (N/A)
001 BUSKEEPER Totem-pole Bus-keeper
010 PULLDOWN Totem-pole Pull-down (on input)
011 PULLUP Totem-pole Pull-up (on input)
100 WIREDOR Wired-OR (N/A)
101 WIREDAND Wired-AND (N/A)
110 WIREDORPULL Wired-OR Pull-down
111 WIREDANDPULL Wired-AND Pull-up

Bit 2:0 – ISC[2:0]: Input/Sense Configuration
000 BOTHEDGES Sense both edges
001 RISING Sense rising edge
010 FALLING Sense falling edge
011 LEVEL Sense low level(1)
100 Reserved
101 Reserved
110 Reserved
111 INTPUT_DISABLE Digital input buffer disabled(2)


I had PIN4CTRLE:= %00000010; for example, which is 010 at the end, which is FALLING Sense.
If you like to detect rising sense, just use 001 for the first 3 bits.
Both Edges are 000 etc.

To activate a pin INT you need to set INTCTRLN .
Bits 0,1 are for INT0 interrupt level (High. Medium, Low, off: 11 10 01 or 00
Bits 2-3 are for INT1.

To select the Pins for the Interrupt use
INT0MASKn for INT0, INT1MASKn for INT1 of that port.
The Bit where you set a "1" is the Interrupt pin.
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Set port pin interrupt

 · 
Posted: 14.12.2018 - 18:07  ·  #5
Hallo Louis,
wäre es nicht einfacher den AVRco-internen Treiber zu verwenden?
XMega PortInt
XMega PCint

rolf
Lschreyer
Schreiberling
Avatar
Gender: n/a
Posts: 527
Registered: 02 / 2007
Subject:

Re: Set port pin interrupt

 · 
Posted: 27.12.2018 - 19:10  ·  #6
Ja, das ist einfacher, aber ich mache es immer von Hand, da weiß ich was eingestellt ist :-)
rh
Administrator
Avatar
Gender:
Location: Germany
Age: 24
Homepage: e-lab.de
Posts: 5558
Registered: 03 / 2002
Subject:

Re: Set port pin interrupt

 · 
Posted: 27.12.2018 - 22:58  ·  #7
Hallo louis,
Wieso denn dann ein Compiler benutzen
Oder noch besser, alles gleich in ASM schreiben
dann har man alles im Griff ;-)
rolf
Lschreyer
Schreiberling
Avatar
Gender: n/a
Posts: 527
Registered: 02 / 2007
Subject:

Re: Set port pin interrupt

 · 
Posted: 02.01.2019 - 11:51  ·  #8
Ja, ich verstehe das, ich bin es halt so gewohnt. Und da ich meist an den Ports eh diverse Dinge einstellen muss, Pullups, Slew Rate usw. mache ich das gleich da mit, dann habe ich es quasi übersichtlich in einer Liste. Ich setze die Dinge auch zur Laufzeit oft anders, manche Pins sind da mehrfach beschaltet. Ich dachte auch dass es evtl. interessant wäre mal zu zeigen wie man es auch "nach Handbuch" machen kann. Da gibt es halt schon noch nette Dinge die man im Xmega mit den Ports anstellen kann, output invertieren z.B.

Und einiges schreibe ich tatsächlich in asm wenn es Sinn macht, ich bin da aber nicht so der Master, daher verlasse ich mich meist auf den Compiler und den Optimizer.
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   141   155 · Page-Gen-Time: 0.029471s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI