troubles with debugging the "gpio" example

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

troubles with debugging the "gpio" example

498 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by asieg on Wed Jun 30 13:31:09 MST 2010
Hello everybody,
I just tried to readout the interrupt status from port 2 pin1 and I've trouble with it:
[LEFT][SIZE=2][COLOR=#3f7f5f][FONT=Arial][SIZE=2][COLOR=#3f7f5f]/* use port2_1 as input event, interrupt test. */[/COLOR][/SIZE][/FONT]
[/COLOR][/SIZE][SIZE=2][FONT=Arial]GPIOSetDir( PORT2, 1, 0 );[/FONT][/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f][FONT=Arial]/* port2_1, single trigger, active high. */[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2][FONT=Arial]GPIOSetInterrupt( PORT2, 1, 1, 0, 0 );[/FONT][/SIZE]
[SIZE=2][FONT=Arial]GPIOIntEnable( PORT2, 1 );[/FONT][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][FONT=Arial]while[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][FONT=Arial]( 1 )[/FONT][/SIZE]
[SIZE=2][FONT=Arial]{[/FONT][/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][FONT=Arial]if[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][FONT=Arial] ( GPIOIntStatus( PORT2, 1 )==1 )[/FONT][/SIZE]
[SIZE=2][FONT=Arial]{ i++;[/FONT][/SIZE]
[SIZE=2][FONT=Arial]GPIOIntClear( PORT2, 1 );[/FONT][/SIZE]
[SIZE=2][FONT=Arial]}[/FONT][/SIZE][/LEFT]
[SIZE=2][FONT=Arial]}[/FONT][/SIZE]
[SIZE=2][SIZE=3]I step to the line with "if" and when I don't pull the port 2 pin1 to GND the debugger goes to the function GPIOIntStatus. In this function I step to the line:[/SIZE]

[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]case
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]PORT2:[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ( LPC_GPIO2->MIS & (0x1<<bitPosi) )[/SIZE][/LEFT]
[SIZE=2]regVal = 1;[/SIZE]
[SIZE=2]
[SIZE=3]and then pull the port 2 pin 1 to GND. Then the regVal is 1 and if I step back to the main my variable "i" will be increased.[/SIZE]
[SIZE=3]BUT if i pull the port2 pin 1 to GND before the debugger is on the line "[/SIZE][SIZE=2]case PORT2:" , [SIZE=3]for example I'm at the line "[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055][FONT=Arial]if[/FONT][/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][FONT=Arial] ( GPIOIntStatus( PORT2, 1 )==1 )[/FONT][/SIZE][/SIZE]" [/SIZE][SIZE=3]in main() then the debugger crashes.[/SIZE]
[SIZE=3]Why???[/SIZE]
[/SIZE][/SIZE]
[/LEFT]
0 Kudos
Reply
3 Replies

482 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jul 01 13:40:27 MST 2010
What do you mean with 'debugger hangs' ??

Did you check this part of the program in 'Disassembly' window with Single Step (F5) ? There you can see what is going on.

Did you check 'PC' and 'Cycle' in 'Core' window ?

There you should see that line
 
if(counter != p2_1_counter) //new edge interrupt

is exactly doing what intended for: waiting for PIO2 Interrupt.

If on / off are not incremeting, there's something wrong with your interrupt handler.

So set breakpoint in PIO2 Interrupt handler and check it.

And BTW: The different behavier seems to result from inexperienced debugger usage. So just play around with breakpoints, disassembly- and core-windows and you will learn a lot about debugger and Cortex M3.
0 Kudos
Reply

482 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by asieg on Thu Jul 01 12:51:27 MST 2010
Thank you, Zero, for your help.
I've copied your code into gpiotest.c and my debugger hangs on the line:

[FONT=Arial]if(counter != p2_1_counter) //new edge interrupt[/FONT]

regardless if the port 2 pin 1 pulled to GND or not.
If I comment this line out the other part of programm works fine.
By the way: my question was why do I have different behaiviours depending on when the pin is down?
But it would help if your code would work.
Thank you.
0 Kudos
Reply

482 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Jun 30 18:04:32 MST 2010
Reading and clearing interrupt status should be done by PIOINT2_IRQHandler in gpio.c and not in your main loop.
I would suggest to check this with a breakpoint in this handler.
Also p2_1_counter could be used to count this pin interrupt if you include something like this in gpiotest:

 
extern volatile uint32_t p2_1_counter;
uint32_t counter;
uint32_t on;
uint32_t off;
...
 
/* use port2_1 as input event, interrupt test. */
GPIOSetDir( PORT2, 1, 0 );
/* port0_1, single edge trigger, active high. */
GPIOSetInterrupt( PORT2, 1, 0, 0, 0 );
GPIOIntEnable( PORT2, 1 );
...
 
counter = p2_1_counter;
while( 1 )
{
 if(counter != p2_1_counter) //new edge interrupt
 {
  if(LPC_GPIO2->DATA & (1<<1)) //pin set?
  {
   on++;
  }
  else
  {
   off++;
  }
  counter = p2_1_counter;
 } //end new interrupt
}
0 Kudos
Reply