PIOINT0_IRQHandler not work

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

PIOINT0_IRQHandler not work

1,091 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethan_kao on Mon Jan 26 00:23:20 MST 2015
Dear all,

    I use the LPC1113 MCU, 2 IO for HW IRQ, it's PIO0_11 and PIO1_11
   1. Set this 2 IO is input
   2. Use GPIOSetInterrupt(0,11,0,0,1); and GPIOSetInterrupt(1,11,0,0,1); to define HW trigger condition
   3. NVIC_EnableIRQ(EINT0_IRQn); and NVIC_EnableIRQ(EINT1_IRQn);
   4. PIOINT0_IRQHandler function as below, especial use PIO1_3 for debug.
       Then...I never see the PIO1_3 change to LOW, it means this IRQ not triggered...
       Is anything or setting miss?

In LPC11xx.h
  EINT3_IRQn                    = 28,       /*!< External Interrupt 3 Interrupt                   */
  EINT2_IRQn                    = 29,       /*!< External Interrupt 2 Interrupt                   */
  EINT1_IRQn                    = 30,       /*!< External Interrupt 1 Interrupt                   */
  EINT0_IRQn                    = 31,       /*!< External Interrupt 0 Interrupt                   */

In startup_LPC11xx.s
                DCD     PIOINT3_IRQHandler        ; 16+28: PIO INT3
                DCD     PIOINT2_IRQHandler        ; 16+29: PIO INT2
                DCD     PIOINT1_IRQHandler        ; 16+30: PIO INT1
                DCD     PIOINT0_IRQHandler        ; 16+31: PIO INT0

void GPIOInit( void )
{
  /* Enable AHB clock to the GPIO domain. */
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<6);
LPC_IOCON->R_PIO0_11  = 0x01;// set AD0 pin as gpio
        LPC_IOCON->PIO1_11  = 0x00;     // set AD7 is GPIO
LPC_IOCON->R_PIO1_1 = 0x01;
LPC_IOCON->R_PIO1_2 = 0x01;
        LPC_IOCON->SWDIO_PIO1_3 = 0x01;  // for debug IO, default is output HIGH
LPC_IOCON->PIO1_4 = 0x00;

LPC_IOCON->PIO0_2   = 0x00;
LPC_IOCON->PIO0_3   = 0x00;
LPC_IOCON->PIO0_4   = 0x00;
LPC_IOCON->PIO0_5   = 0x00;
LPC_IOCON->PIO0_6   = 0x00;
LPC_IOCON->PIO0_7   = 0x00;
LPC_IOCON->PIO0_9   = 0x00;

LPC_IOCON->PIO3_2   = 0x00;
LPC_IOCON->PIO3_5   = 0x00;

//LPC_IOCON->PIO1_8 &= ~0x07;
        LPC_IOCON->PIO1_8 = 0x00;
        //LPC_IOCON->PIO1_9 &= ~0x07;
        LPC_IOCON->PIO1_9 = 0x00;
GPIOSetDir(1,8,1);
//GPIOSetValue(1,8,0);
GPIOSetDir(1,9,0);
//GPIOSetValue(1,9,1);


LPC_IOCON->R_PIO1_0 = 0x01;//set p1_0 pin as gpio

GPIOSetDir(0,11,0);//AD0 is input GPIO, detect square wave  __compare time
GPIOSetDir(1,11,0);                                        //AD7 is input GPIO, detect PWM square  _/
 
GPIOSetDir(1,3,1);
GPIOSetDir(1,4,1);
GPIOSetValue(1,3,1);
GPIOSetValue(1,4,1);

GPIOSetDir(1,0,1);//
GPIOSetValue(1,0,1);//Set default output HIGH

GPIOSetDir(3,2,1);//Set PIO3_2 be output
GPIOSetValue(3,2,1);//Set default input HIGH

GPIOSetDir(3,5,0);//Set PIO3_5 be input
GPIOSetValue(3,5,1);//Set default input HIGH

        GPIOSetInterrupt(0,11,0,0,1);  // set port_0/bit_11 as interrupt/edge trigger/single edge/falling edge
        GPIOSetInterrupt(1,11,0,0,1);


GPIOSetDir(1,5,1);// set p1_5 output
GPIOSetValue(1,5,1);// set p1_5 high

GPIOSetDir(0,2,1);  // a
        GPIOSetValue(0,2,1);
GPIOSetDir(0,3,1);// b
GPIOSetDir(0,4,1);// c
GPIOSetDir(0,5,1);// d
GPIOSetDir(0,6,1);// e
GPIOSetDir(0,7,1);// f
GPIOSetDir(0,9,1);// g

GPIOSetValue(1,8,0);

  /* Set up NVIC when I/O pins are configured as external interrupts. */
  NVIC_EnableIRQ(EINT0_IRQn);
  NVIC_EnableIRQ(EINT1_IRQn); 
  GPIOIntEnable(0,11);
  GPIOIntEnable(1,11);

  return;
}

void PIOINT0_IRQHandler(void)
{
  uint32_t regVal;
  //gpio0_counter++;
  regVal = GPIOIntStatus( PORT0, 11 );
  if ( regVal )
  {
    GPIOSetValue(1,3,0);  // debug IO, if IRQ occured, set output LOW
    PIO0_FLAG = 1;
  //p0_1_counter++;
    GPIOIntClear( PORT0, 11 );
    GPIOIntDisable( PORT0, 11 );
  }
  return;
}

    Regards, Ethan
Labels (1)
0 Kudos
Reply
6 Replies

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethan_kao on Tue Jan 27 21:39:00 MST 2015
Dear R2D2,

    Thanks for your reply and help. :)

    Regards, Ethan
0 Kudos
Reply

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Jan 27 06:02:18 MST 2015
It's important to set 'Digital function mode' bit (bit 7) in IOCON settings for Pins with [color=#f00]GPIO and AD[/color] function  :exmark:

If you delete this bit you are switching to 'Analog input mode' and digital functions (interrupt) don't work  :((
0 Kudos
Reply

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethan_kao on Tue Jan 27 05:36:35 MST 2015
Dear R2D2,

    Yes, I use as below, maybe only set 0x01 also clear bit3~7, is not serious enough
    LPC_IOCON->R_PIO0_11 &= ~0x07;
    LPC_IOCON->R_PIO0_11 |= 0x01;// set AD0 pin as gpio

    HW IRQ is work, thank you. :)

    Regards, Ethan
0 Kudos
Reply

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Jan 26 21:30:19 MST 2015
LPC_IOCON->R_PIO0_11 = 0x01; // set AD0 pin as gpio


is nonsense, you can't use GPIO and Analog input mode 

Use:

LPC_IOCON->R_PIO0_11 &= ~(3<<3); //inactive
LPC_IOCON->R_PIO0_11 |= 1; //PIO0_11 function: GPIO, digital function mode

0 Kudos
Reply

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ethan_kao on Mon Jan 26 18:56:56 MST 2015
Hi R2D2,

   I edit my original post and paste GPIO setting function.
   I just want to use 2 I/O pin be a HW IRQ to detect square wave edge :(
0 Kudos
Reply

895 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Mon Jan 26 05:53:23 MST 2015

Quote: ethan_kao
Is anything or setting miss?



Could be useful if you post you complete code (or better the project)  :)

Your code snippet isn't very informative  :(
0 Kudos
Reply