Interrupt lpc1343

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

Interrupt lpc1343

1,333 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xOrElse on Thu Jul 05 04:19:59 MST 2012
Hello,
I'm havnig a little problem with interrupt.

http://4.bp.blogspot.com/-scoXFGGR5qI/T_VL8_wbFTI/AAAAAAAAAMk/3GYHfmxStXk/s1600/Untitled.jpg

In this picture is how I connect all wires. Don't look the chip, it's just so you can see where is the button. In reality chip is: lpc1343.

This are all connections http://3.bp.blogspot.com/-QqWyBNYHbxY/T_VNMUDh6dI/AAAAAAAAAMs/bpmduXOdscI/s1600/P7050004.JPG
In this picture you can see one LED, it's just so I could see if the interrupt is working right.
The program is always in one loop while (1), where the led is OFF, and when I press the button the led should be ON, and it should be always ON. But it's not, like the chip doesn't recognize interrupt.

LED is working perfectly, but I have problems whit this button, I'm not shure in the scheme anymore. (btw. that same scheme is working just fine on PIC18f456)

This is my code for main program:

int main (void)
{
  GPIOInit();

  /* use port0_1 as input event, interrupt test. */
  GPIOSetDir( PORT2, 4, 0 );
  GPIOSetDir( PORT2, 1, 1 );
  /* port0_1, single trigger, active high. */
  GPIOSetInterrupt( PORT2, 4, 0, 0, 0 );
  GPIOIntEnable( PORT2, 4 );

  while( 1 ){
      GPIOSetValue( PORT2, 1, 0 );
      while (1){
      if (val!=0){
          GPIOSetValue( PORT2, 1, 1 );
      }}
  };
}
This is interrupt code:

void PIOINT2_IRQHandler(void)
{
  uint32_t regVal;

  val=1;
  gpio2_counter++;
  regVal = GPIOIntStatus( PORT2, 0 );
  if ( regVal )
  {
    p2_1_counter++;
    GPIOIntClear( PORT2, 0 );
  }        
  return;
}
val is global variable, so that I can use in all program...
Everything else is pretty much the same as their example on offical site...

Please help me, I've been doing it for so long....
0 Kudos
Reply
6 Replies

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xOrElse on Wed Jul 11 06:14:05 MST 2012
Hello,
I have few problems with my lpcxpresso board and debugger actually I don't know where is problem.

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

#include <cr_section_macros.h>
#include <NXP/crp.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 ;

// TODO: insert other include files here
#include "gpio.h"
// TODO: insert other definitions and declarations here
volatile unsigned int v=0;
int main(void) {
    volatile unsigned int tipka;

    GPIOInit();

    //set interrupt P2.2 - red button
    LPC_GPIO2->DIR &= ~(0x4); //direction is input - button
    LPC_GPIO2->IS &= ~(0x4); //level sensitive
    LPC_GPIO2->IBE &= ~(0x4); //controlled by register IEV (not sure I did it correctly??)
    //LPC_GPIO2->IEV |= 0x4; //when I push the button then it's recognized
    LPC_GPIO2->IE |= (0x4); //!!!!!!

    //led
    LPC_GPIO2->DIR |= 0x2; // led had direction to be output
    LPC_GPIO2->DATA |= 0x2; //led is on
    LPC_GPIO3->DIR |= 0x1; // led had direction to be output
    LPC_GPIO3->DATA |= 0x1; //led is on

    //loop
    while(1){
        LPC_GPIO2->DATA &= ~(0x2); // led is off
        while ((tipka=LPC_GPIO2->MIS) & 0x4){
            LPC_GPIO2->DATA |= 0x2; //led is on only if there was interrupt
        }
    }

    return 0 ;
}


Okay so here is the code...

- P2.1- led  that is on pics turned off
- P2.2-blue trigger
- Red trigger in on reset pin
- P3.0-led that is turned on on pics
Program should do:
P3.0 should be always on (as it is-that part of the program is working), when I press the blue button p2.1 led should be on and always on.

When I explained everything, here is my problem. I started to use program debugger and I test every line, few times I click in first while loop and variable tipka is 0 (this should be) after that I press the blue button and variable tipka is 0x4, this is also ok and the led is on after that. Well in debugger mode it works exactly as it suppose to be working. But when I unplug usb cable from PC and plug it again in PC (just to get power supply for board and chip) program in chip lpc1343 doesn't work!

I really don't know where I'm wrong! Please help me! I've been working on that simple program for so long, and worst of all I have no idea where I'm wrong...
0 Kudos
Reply

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Jul 07 02:46:49 MST 2012

Quote:

...in gpiotest.c nothing changes, now it's even worse, it won't built!

No, that's good :) Now Interrupt handler code is compiled and compiler is showing your errors to help you :):)

Wiki is your friend: http://en.wikipedia.org/wiki/Volatile_variable


Quote:

In computer programming, particularly in the C, C++, C#, and Java programming languages, a variable or object declared with the volatile keyword usually has special properties related to optimization and/or threading. Generally speaking, the volatile keyword is intended to prevent the compiler from applying any optimizations on the code that assume values of variables cannot change "on their own."

0 Kudos
Reply

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xOrElse on Sat Jul 07 02:31:03 MST 2012

Quote: Zero

#2 Use volatiles in interrupts:
volatile uint32_t val=0; //this variable is added by me and corrected by ZERO



When I remove "//" signs in gpio.c
and change int to
volatile uint32_t val=0;
in gpiotest.c nothing changes, now it's even worse, it won't built!
Could you tell me where to put that declaration? I'm new at that field and new in lpc xpresso...

EDIT: I succeeded  in turning on the led (I did it by adding one while loop in interrupt function just to check if my program and hardwere really works), but only problem is to "transfer" value of the variable val into the main program. I don't know how to make that variable global.
In school we learned that any variable we want to make global we have to put it before main function. But we didn't make programs of few files (like header, and few .c files), so it's pretty new to me.
Could you please tell me how to make that variable global and explain what does volatile stands for?

Also could you tell me something more about interrupts:
If I have 3 buttons on PORT 0, where can I check which button made an interrupt?

Thank you soo much on every help!
0 Kudos
Reply

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Jul 06 22:54:04 MST 2012
#1 You've excluded your interrupt code:

Quote:

//#define GPIO_GENERIC_INTS 1

#ifdef GPIO_GENERIC_INTS

If code is grayed out that means that it's excluded via #ifdef :eek:

change that to:


Quote:

#define GPIO_GENERIC_INTS 1

#ifdef GPIO_GENERIC_INTS

#2 Use volatiles in interrupts:
volatile uint32_t val=0; //this variable is added by me and corrected by ZERO
#3 Learn to use breakpoints with your debugger. Debugger is your friend See: http://www.youtube.com/watch?v=E6vSPloei-0
0 Kudos
Reply

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xOrElse on Fri Jul 06 20:51:13 MST 2012
I added .zip file, there is my project. Also little notice for you, I changed some ports in program and on protoboard. Just telling...

P2.2 - button
P2.1 - LED

On my protoboard LED (I tested it) and  trigger is connected like on this scheme. 10k ohm resistor is set to be pull-down, and trigger goes to +5V.

I seriously hope that is the problem why mine program doesn't work.


Another questions:
1. Also would you help me and tell me where do I change on what pin/port is interrupt?  I only saw that part of the code where I wrote: "I CHANGED ONLY THIS NEXT PART!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!", in gpio.c file. But I think I change code partially.

2. Where can I find schemes for lpc1343? Not datasheets, I thought something like: how to connect led, trigger, simple projects just to find out does my (beginners) projects work.

3. Where can I find something like library. I used to program in microBasic, and in Help there was list of all comands for lcd, timer etc. I haven't find it in lpcxpresso. Do I have to make it (.h and .c file-with funkcitons in it) every time I make projects?

4. I noticed that I can't use pin P0.10. Is that true? I connected 6 leds on P3.2, P3.1, P3.0, P0.6, P1.8, P0.10 and only one of them doesn't work, the one on P0.10 (I'm having this board).

Thank you so much!
0 Kudos
Reply

1,098 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Fri Jul 06 01:16:57 MST 2012
We need to see you complete program. Please export your program en post it here. Because now we don't know if you are using the internal pullups or pulldowns for example. These internal pullups or pulldowns can and will have an influence on the way your switch is behaving.
0 Kudos
Reply