Problem with two interruptions with GPIO

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

Problem with two interruptions with GPIO

2,087 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Mon Jun 30 02:45:27 MST 2014
Hello,

I have a problem with my lpc11c24. When I use one encoder on the port0 to make interruption with gpio, it works normally. But if I try to use two encoder, the first on the port0 and the second on the port1, I have no longer interruption. Here it's my code I am trying to work :

#include <chip.h>
#include <gpio_11xx_2.h>
#include <iocon_11xx.h>
#include <core_cm0.h>
#include <core_cmInstr.h>

#include "board.h"

#define GPIO_PININT_1111 /* GPIO pin number mapped to PININT */
#define GPIO_PININT_PORT_00 /* GPIO port number mapped to PININT */
#define IOCON_PIN_ID_1IOCON_PIO0_11 /* IOCON pin identifier */

#define GPIO_PININT_00 /* GPIO pin number mapped to PININT */
#define GPIO_PININT_PORT_11 /* GPIO port number mapped to PININT */
#define IOCON_PIN_ID_2IOCON_PIO1_0 /* IOCON pin identifier */

#define PININT_IRQ_HANDLER_1PIOINT0_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME_1EINT0_IRQn /* GPIO interrupt NVIC interrupt name */

#define PININT_IRQ_HANDLER_2PIOINT1_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME_2EINT1_IRQn /* GPIO interrupt NVIC interrupt name */

/*****************************************************************************
 * Private variables
 ****************************************************************************/

static volatile uint32_t ticks = 0;
static volatile uint32_t cpt_1 = 0;
static volatile uint32_t cpt_2 = 0;

/*****************************************************************************
 * Private functions
 ****************************************************************************/

/*****************************************************************************
 * Public functions
 ****************************************************************************/

void SysTick_Handler(void)
{
ticks++;
}

void PININT_IRQ_HANDLER_1(void)
{
if(ticks >= 1)
{
cpt_1 = cpt_1+1;
}

/* Clear interrupt */
Chip_GPIO_ClearInts(LPC_GPIO, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));

ticks = 0;
}

void PININT_IRQ_HANDLER_2(void)
{
if(ticks >= 1)
{
cpt_2 = cpt_2+1;
}

/* Clear interrupt */
Chip_GPIO_ClearInts(LPC_GPIO, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));

ticks = 0;
}

int main(void)
{
/* Generic Initialization*/
SystemCoreClockUpdate();

/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
   Chip_GPIO_Init is not called again */
Board_Init();

/* Enable and setup SysTick Timer at a 100Hz rate */
SysTick_Config(SystemCoreClock / 100);

/* Configure GPIO pin as input pin */
Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_PININT_PORT_0, GPIO_PININT_11);
Chip_GPIO_SetPinDIRInput(LPC_GPIO, GPIO_PININT_PORT_1, GPIO_PININT_0);


/* Configure pin as GPIO with pullup */
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIN_ID_1,
(IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIN_ID_2,
(IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));

/* Configure channel interrupt as edge sensitive and falling edge interrupt */
Chip_GPIO_SetupPinInt(LPC_GPIO, GPIO_PININT_PORT_0, GPIO_PININT_11, GPIO_INT_RISING_EDGE);
Chip_GPIO_SetupPinInt(LPC_GPIO, GPIO_PININT_PORT_1, GPIO_PININT_0, GPIO_INT_RISING_EDGE);

/* Enable GPIO pin interrupt */
Chip_GPIO_EnableInt(LPC_GPIO, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));
Chip_GPIO_EnableInt(LPC_GPIO, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));

/* Enable interrupt in the NVIC
NVIC_EnableIRQ(PININT_NVIC_NAME_1);
NVIC_EnableIRQ(PININT_NVIC_NAME_2);*/

while (1)
{
__WFI();
}

return 0;
}



Than you for your help,
Best regards.
0 Kudos
Reply
11 Replies

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Wed Jul 02 01:53:06 MST 2014
I found !! Actually it effectively need to plug interrupt on different port, but the port0 include pin 0 to 11 and the PIO1_0 ! I change the plugging of my second encoder to PIO1_1 and it works.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Tue Jul 01 06:03:01 MST 2014
I want to trigger an interrupt containing an counter when I turn my encoder. I succeed with one encoder, but when I try to plug two encoder, there is no interruption triggered when I turn the second encoder.
I included some .h because I had need their function.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jul 01 05:51:01 MST 2014
Still don't know what you are doing.

What is that and why do you include it ?

#include chip.h
#include gpio_11xx_2.h
#include iocon_11xx.h
#include core_cm0.h
#include core_cmInstr.h
#include cmsis_11cxx.h


I would strongly recommend to copy the original working LPCOpen sample and start from there again...

0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Tue Jul 01 05:35:31 MST 2014
Yes I have also nxp_lpcxpresso_11c24_board_lib, I have no error when I build my program.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jul 01 05:27:52 MST 2014
Board Library???

...or what's doing:

Board_Init();

0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Tue Jul 01 05:03:33 MST 2014
I use a MCU LPC11C24, and the library lpc_chip11cxx_lib downloaded on nxp wtih the package lpcopen. I checked the signal of the two encoder with my an oscilloscope and it works. I have only one counter that counting revolution, the other doesn't increment.

Thank.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jul 01 04:00:00 MST 2014
With  your code snippets it's impossible to help you.

I still have no idea which hardware is connected and if you checked your encoder signals (are there really there?).

Also I've no idea which board library you are linking and if that's a correct LPCOpen project?

Anyway, since both interrupts are firing here and counters are counting I would suggest to comment WFI out and use debugger to check your peripherals (especially IOCON settings)...

0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Tue Jul 01 03:12:57 MST 2014
I am trying to increment two counter with gpio interrupt, when the encoder associate make a revolution. I succeed to catch an edge when the two encoder are connected, but I can't catch the other signal. However I defined two register for the gpio interupt. Here this my code :

#include chip.h
#include gpio_11xx_2.h
#include iocon_11xx.h
#include core_cm0.h
#include core_cmInstr.h
#include cmsis_11cxx.h

#include "board.h"

#define GPIO_PININT_1111 /* GPIO pin number mapped to PININT */
#define GPIO_PININT_PORT_00 /* GPIO port number mapped to PININT */
#define IOCON_PIN_ID_1IOCON_PIO0_11 /* IOCON pin identifier */

#define GPIO_PININT_00 /* GPIO pin number mapped to PININT */
#define GPIO_PININT_PORT_11 /* GPIO port number mapped to PININT */
#define IOCON_PIN_ID_2IOCON_PIO1_0 /* IOCON pin identifier */

#define PININT_IRQ_HANDLER_1PIOINT0_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME_1EINT0_IRQn /* GPIO interrupt NVIC interrupt name */

#define PININT_IRQ_HANDLER_2PIOINT1_IRQHandler /* GPIO interrupt IRQ function name */
#define PININT_NVIC_NAME_2EINT1_IRQn /* GPIO interrupt NVIC interrupt name */

#define LPC_GPIO_0                ((LPC_GPIO_T*) LPC_GPIO_PORT0_BASE)
#define LPC_GPIO_1                ((LPC_GPIO_T*) LPC_GPIO_PORT1_BASE)

/*****************************************************************************
 * Private variables
 ****************************************************************************/

static volatile uint32_t ticks = 0;
static volatile uint32_t cpt_1 = 0;
static volatile uint32_t cpt_2 = 0;

/*****************************************************************************
 * Private functions
 ****************************************************************************/

/*****************************************************************************
 * Public functions
 ****************************************************************************/

void SysTick_Handler(void)
{
ticks++;
}

void PININT_IRQ_HANDLER_1(void)
{
if(ticks >= 1)
{
cpt_1 = cpt_1+1;
}

/* Clear interrupt */
Chip_GPIO_ClearInts(LPC_GPIO_0, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));

ticks = 0;
}

void PININT_IRQ_HANDLER_2(void)
{
if(ticks >= 1)
{
cpt_2 = cpt_2+1;
}

/* Clear interrupt */
Chip_GPIO_ClearInts(LPC_GPIO_1, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));

ticks = 0;
}

int main(void)
{
/* Generic Initialization*/
SystemCoreClockUpdate();

/* Board_Init calls Chip_GPIO_Init and enables GPIO clock if needed,
   Chip_GPIO_Init is not called again */
Board_Init();

Chip_GPIO_Init(LPC_GPIO_0);
Chip_GPIO_Init(LPC_GPIO_1);

/* Enable and setup SysTick Timer at a 100Hz rate */
SysTick_Config(SystemCoreClock / 100);

/* Configure GPIO pin as input pin */
Chip_GPIO_SetPinDIRInput(LPC_GPIO_0, GPIO_PININT_PORT_0, GPIO_PININT_11);
Chip_GPIO_SetPinDIRInput(LPC_GPIO_1, GPIO_PININT_PORT_1, GPIO_PININT_0);


/* Configure pin as GPIO with pullup */
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIN_ID_1,
(IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, IOCON_PIN_ID_2,
(IOCON_FUNC1 | IOCON_MODE_PULLUP | IOCON_DIGMODE_EN));

/* Configure channel interrupt as edge sensitive and rising edge interrupt */
Chip_GPIO_SetPinModeEdge(LPC_GPIO_0, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));
Chip_GPIO_SetEdgeModeSingle(LPC_GPIO_0, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));
Chip_GPIO_SetModeHigh(LPC_GPIO_0, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));

Chip_GPIO_SetPinModeEdge(LPC_GPIO_1, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));
Chip_GPIO_SetEdgeModeSingle(LPC_GPIO_1, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));
Chip_GPIO_SetModeHigh(LPC_GPIO_1, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));

/* Enable GPIO pin interrupt */
Chip_GPIO_EnableInt(LPC_GPIO_0, GPIO_PININT_PORT_0, (1 << GPIO_PININT_11));
Chip_GPIO_EnableInt(LPC_GPIO_1, GPIO_PININT_PORT_1, (1 << GPIO_PININT_0));

/* Enable interrupt in the NVIC*/
NVIC_EnableIRQ(PININT_NVIC_NAME_1);
NVIC_EnableIRQ(PININT_NVIC_NAME_2);

NVIC_SetPriority(PININT_NVIC_NAME_1, 1);
NVIC_SetPriority(PININT_NVIC_NAME_2, 2);

while (1)
{
__WFI();
}

return 0;
}


Thank.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jul 01 02:30:50 MST 2014
With enabled interrupts this code snippet is working here (at least firing both interrupts)...

Could be useful if you describe your hardware and especially your board library and what you've done already to find your problem...


0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Walker91 on Tue Jul 01 02:06:43 MST 2014
Yes I disable it to check, but even with them it's the same result. May be I have to define two register different for the GPIO because sometime I read that the GPIO for LPC11C24 manage all register and then, you only need LPC_GPIO. And sometime I see LPC_GPIO0, LPC_GPIO1...I am lost.

Thank.
0 Kudos
Reply

1,909 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Tue Jul 01 01:28:41 MST 2014

Quote: Walker91
...I have no longer interruption.





That's no surprise if you don't enable them...

...
[color=#f00]/*[/color] Enable interrupt in the NVIC
NVIC_EnableIRQ(PININT_NVIC_NAME_1);
NVIC_EnableIRQ(PININT_NVIC_NAME_2);[color=#f00]*/[/color]
...
}



0 Kudos
Reply