cancel
Showing results for 
Search instead for 
Did you mean: 

how to use external interrupts?

marco5
Associate II
Posted on March 28, 2007 at 08:34

how to use external interrupts?

9 REPLIES 9
marco5
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I tried to use external interrupts but it doesnt work.

Im using the mcbstr9 eval board vers. 4 from keil.

Here is my code:

Code:

<BR> <BR>__irq void EXT_WIU1_IRQ_Handler(void); /* EXT interrupt routine */ <BR>int count = 0; <BR> <BR>int main(void) <BR>{ <BR> <BR> SCU->GPIOIN[5] = 0x00; /* P5.0..7 input - mode 0 */ <BR> SCU->GPIOOUT[5] = 0x0000; /* P5.0..7 output - mode 0 */ <BR> GPIO5->DDR = 0x00; /* P5.0..7 direction - input */ <BR>//SCU->WKUPSEL = 0x0038; /* use P5.7 as VIC1.11 interrupt src*/ <BR> <BR> /* Configure and enable IRQ for EXTINT WIU Group 1 */ <BR> VIC1->VAiR[11] = (unsigned int)&EXT_WIU1_IRQ_Handler; <BR> VIC1->VCiR[11] |= 0x20; /* Enable the vector interrupt */ <BR> VIC1->VCiR[11] |= 11; /* Specify the interrupt number */ <BR> VIC1->INTSR &= ~(1<<11); /* Set Interrupt as IRQ */ <BR> VIC1->INTER |= (1<<11); /* Enable EXT interrupt */ <BR> <BR> <BR> <BR> while(1) <BR> { <BR> <BR> /* some code to print variable 'count' */ <BR> <BR> } <BR>} <BR> <BR> <BR> <BR>__irq void EXT_WIU1_IRQ_Handler(void) /* EXT interrupt routine */ <BR>{ <BR> count++; <BR> <BR> VIC0->VAR = 0; /* Acknowledge Interrupt */ <BR> VIC1->VAR = 0; /* Acknowledge Interrupt */ <BR>} <BR>

GPIO5 uses external interrupts 8 to 15 as default input function.

They are grouped to WIU group 1 and is connected to VIC1.11.

I also tried to mask one of GPIO5 bit in SCU->WKUPSEL,

but the interrupt routine is never called.

any ideas?

[ This message was edited by: MarcoHansen on 26-03-2007 20:42 ]

mtraman
Associate II
Posted on May 17, 2011 at 09:40

HI

You can use only one of the 8 pins of GPIO5 as external interrupt. for the code u hav shown atleast one pin should hav worked

bye

marco5
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I already tried to use P5.7 as intterupt source but it doesnt work.

jkl
Associate II
Posted on May 17, 2011 at 09:40

Hi,

Did u set up the WIU registers?

Enable the WIU interrupt in WIU->CTRL and WIU->MR registers

Also u may have to set the pin as alternate input 1 in the GPIOIN register...

marco5
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I tried these config:

Code:

WIU->CTRL |= 0x02; /* Global WIU Interrupt enable */

WIU->MR |= 0xFFFC; /* Enable all Interrupts in Maskreg */

No effect. Setting the input as alternate input also has no effect.

marco5
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I added these lines:

Code:

SCU->PCGRO |= (1<<5); /* Enable VIC peripheral clock gating*/

SCU->PCGR1 |= (1<<19); /* Enable GPIO5 port clock gating */

SCU->PCGR1 |= (1<<13); /* Enable WIU peripheral clock gating*/

SCU->PRR0 |= (1<<5); /* VIC not held in reset */

SCU->PRR1 |= (1<<19); /* GPIO5 not held in reset */

SCU->PRR1 |= (1<<13); /* WIU not held in reset */

Also no effect.

The output of GPIO5-register shows change of value so input should work correctly.

jkl
Associate II
Posted on May 17, 2011 at 09:40

Hi,

Did u enable the clock gating and disable the reset for the VIC, WIU and GPIO peripherals?

jkl
Associate II
Posted on May 17, 2011 at 09:40

This works for me:

Code:

WIU->PR = 0xFFFFFFFC; // Clear pending interrupts

WIU->MR = WIU_Line2; // Enable external interrupt from pin3_2 (interrupt pin)

WIU->CTRL = WIU_Mode_Interrupt; // Enable interrupt from pins

VIC1->VAiR[9] = (unsigned int)interrupt_handler; // Setup external interrupts handler vector

VIC1->VCiR[9] = 0x20; // Enable the vector interrupt

VIC1->VCiR[9] |= (WIU_ITLine-16); // Specify the interrupt number

VIC1->INTER = (1 << (WIU_ITLine-16)); // Enable interrupt

I use VIC1.9 and pin 3.2 for external interrupt...

The predefined numbers are from the ST library header files...

marco5
Associate II
Posted on May 17, 2011 at 09:40

Hi,

I tried your code, but it doesnt work.

I had to set up the port clock gating in startup code. Writing to SCU->PCGR1 had no effect.

I attached the project. Maybe I forgot something to configure in startup code or there is something wrong with the board. :-?