Using: LPC11U14 setting up an external interrup not working

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using: LPC11U14 setting up an external interrup not working

1,390 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ticup on Wed May 23 13:32:42 MST 2012
Hi there, down below is the code that I wrote to set up an external interrupt; I could build and transfer the code to LPC11U14. I have a switch between PIO1_29 and ground. I press on the switch and I expect to print in the trace window some text. I get nothing. Could someone have a look at my code and help me to understand where I am wrong...??? thanks

/*
===============================================================================
Name        : main.c
Author      :
Version     :
Copyright   : Copyright (C)
Description : main definition
===============================================================================
*/

#ifdef __USE_CMSIS
#include "LPC11Uxx.h"
#endif

#include "cr_section_macros.h"
#include "NXP/crp.h"

//#include "lpc11uxx_pinsel.h"
//#include "stdio.h"
//#include "gpio.h"

#include "lpc_types.h"
#include "lpc11uxx_gpio.h"
#include "LPC11Uxx.h"
#include "lpc11uxx_pinsel.h"
#include "string.h"
#include "stdio.h"


// Variable to store CRP value in. Will be placed automatically
// by the linker when "Enable Code Read Protect" selected.
// See crp.h header for more information
__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;


void FLEX_INT0_IRQHandler(void)
{
    printf("FLEX_irq handler kicked");
    NVIC_ClearPendingIRQ(FLEX_INT0_IRQn);
}

int main(void) {

   // TODO: insert code here
   volatile static int i = 0 ;
   LPC_GPIO_PIN_INT->ISEL &= ~(0x1<<LPC_IOCON->PIO1_29);/* Edge trigger */
   LPC_GPIO_PIN_INT->IENF |= (0x1<<LPC_IOCON->PIO1_29); );/* falling edge */
   LPC_SYSCON->PINTSEL[0] = LPC_IOCON->PIO1_29; //here we assign the port 1 pin 29 to ext. interrupt 0
   LPC_IOCON->PIO1_29 = PINSEL_FUNC_0;  //default is the general IO
  
   NVIC_SetPriority(FLEX_INT0_IRQn,0);   /* Default priority can be 0(highest) - 31(lowest) */
   NVIC_EnableIRQ(FLEX_INT0_IRQn);       /* Enable External Interrupt 0 Interrupt */
  
// Enter an infinite loop, just incrementing a counter
    while(1) {

i++ ;
   }
   return 0 ;
}

Thanks for the help....!!

Labels (1)
0 Kudos
Reply
4 Replies

1,308 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexan.e on Fri May 25 01:12:31 MST 2012
I noticed in your first post the following code
------------------
NVIC_SetPriority(FLEX_INT0_IRQn,0); /* Default priority can be 0(highest) - 31(lowest) */
NVIC_EnableIRQ(FLEX_INT0_IRQn); /* Enable External Interrupt 0 Interrupt */
------------------

Seems to be from ARMwizard but in my application these two are used in the reverse order which I know now (after reading the M0 manual) that shouldn't be used because the priority level shouldn't be changed when the interrupt is enabled, it should be set before enabling the interrupt.
The second bug I have is that M0 have only four interrupt priority, 0 to 3 so the 0-31 comment is not correct.
These will be corrected in the next release in a few days.

About your question, I think you should use the timer capture mode directly and not use an external pin interrupt that stores that timer value etc.
You can set the capture to be trigger with falling edge (CAP pins), get the first interrupt timer value and then the second and do the math.

Alex
0 Kudos
Reply

1,308 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by PhilYoung on Thu May 24 17:43:52 MST 2012
there is not enough information here to help.
Did you try printing from main to ensure that printf actually works, for this to work you need to have set up succifient stack / heap space in the startup code or you will never even get to main.

The code is also dependant on the startup file you are using since the ISR handler is installed in the vector table using a weak definition overriddedn by the name from your C file, so these must match exactly.

Try switching the ISR to a timer ISR to verify if it is a problem generating the interrupt from a pin, or a problem with the code setup.

( unless of course you already did this ).
0 Kudos
Reply

1,308 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ticup on Thu May 24 08:58:21 MST 2012
Alex, it work nicely using the code provided. And the wizard is beautiful ....thanks a lot. I learned a lot. Next I have to start a timer on receiving the interrupt and to store the value accumulated in the timer ,clear the timer and start it again and let it run until next interrupt, and if the timer exceed a certain value then that is the end off my measurement. So I need to recognize ones and zeros by the length of the pulses (falling edges) My bottom line is to start and stop the timer read the clock value and generate a software interrupt if the timer exceed a certain value.....please give me a hint how to set up the wizard timer1 specifically for my task, thanks a lot in anticipation....  
0 Kudos
Reply

1,308 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by alexan.e on Thu May 24 06:22:05 MST 2012
I'm not sure of what value you write to ISEL and IENF.
Why is the PIO1_29 used there?
bits 7:0 represent pin interrupts 7:0, your setting is based on interrupt number not pin, for pin interrupt 0 you just use bit0 of these two registers
The pin is only set in the PINTSEL register in which I'm also not sure of the value you assign because I don't have these headers.
I also don't see the GPIO clock being enabled.


Basically the correct values are (hard coded)
<code>/******************************************************************************
                           GPIO pin interrupts
*******************************************************************************
   GPIO pin interrupt 0 set for: P1.29 triggered with FALLING EDGE
*/

    LPC_SYSCON->SYSAHBCLKCTRL = (LPC_SYSCON->SYSAHBCLKCTRL & 0x098DFFFF) | (1UL<<19);   /* enable clock for GPIO pin interrupt (default is disabled)*/

    LPC_GPIO_PIN_INT->ISEL = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
    LPC_GPIO_PIN_INT->IENR = 0x00000000;     /* binary: 00000000_00000000_00000000_00000000 */
    LPC_GPIO_PIN_INT->IENF = 0x00000001;     /* binary: 00000000_00000000_00000000_00000001 */

    LPC_SYSCON->PINTSEL[0] = 0x00000035;     /* binary: 00000000_00000000_00000000_00110101 */
</code>

The 11Uxx series is included in ARMwizard, you may want to experiment and see the values you get in the generated code

http://alexan.edaboard.eu/index.php?page=armwizard

Alex
0 Kudos
Reply