Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

External Interrupt Not Working in LPC2148???

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
Activity points
10,591
Hello!! Everyone i had just started using ARM LPC2148..

I am having problem with using Interrupts...

I am trying to use external interrupt EINT1 P0.14 Pin

ARM_Interrupt.PNG

Here is my Program and it is not working...

Code:
#include <LPC214X.H>

//Function Prototype
void Init_EXT_1(void);
void FIQ_Handler(void);

unsigned char flag;

int main()
{
	flag = 0xAA;
	Init_EXT_1();
	while(1);

}

//Function Definitions
void Init_EXT_1()
{
	PINSEL0 |= (1<<29);				//Enable Pin for receiving External-1 Interrupt P0.14
	IO1DIR = 0x00FF0000;		  	// Port1 16-23 as output
	IO1CLR = 0x00FF0000;
	VICIntSelect = 0x00008000;		// External Interrupt-1 as FIQ Interrupt
	VICIntEnable = 0x00008000;		// Enable External Interrupt-1
}

void FIQ_Handler()
{
	if(flag == 0xAA)
	{
		IOSET1	= 0x00FF0000;		//Set the LED pins
	}
	else if(flag == 0x55)
	{
		IOCLR1 = 0x00FF0000;		//Clear the LED Pins
	}
	flag = ~flag;
	EXTINT = 0x00000002;			//Clear the peripheral interrupt flag
}

I searched on internet and found the way to define isr routine as

void FIQ_Handler(void) __fiq;

But whenever i write this i am getting error, but the above code is compiling fine. but i think it is not going in interrupt.
Just stay in while loop..

May be i am not able to manage how to write the isr routine..
Please Someone help me...
 

Fist of all I don't see in your code the interrupt setting

Code:
/******************************************************************************
                           External interrupts
*******************************************************************************
    Ext. interrupt 1 mode: Level sensitivity / Active low  / wake on interrupt 1 is Off
*/
    EXTMODE = 0x00;     /* binary: 00000000 */
    EXTPOLAR = 0x00;     /* binary: 00000000 */
    EXTINT = 0x02;     /* clear the external interrupt flags */

or

Code:
/******************************************************************************
                           External interrupts
*******************************************************************************
    Ext. interrupt 1 mode: Edge sensitivity / Falling edge  / wake on interrupt 1 is Off
*/
    EXTMODE = 0x02;     /* binary: 00000010 */
    EXTPOLAR = 0x00;     /* binary: 00000000 */
    EXTINT = 0x02;     /* clear the external interrupt flags */

I suppose you use uvision?

The FIQ function is
Code:
__irq void FIQ_Handler (void) {
/* write code here */


EXTINT = (1UL<<1);   /* Clear EINT1 interrupt flag */ 
VICVectAddr = 0;     /* Acknowledge Interrupt */
}

In order to use the FIQ you have to make a couple of changes in startup code

Code:
COMMENT THIS LINE IN THE STARTUP FILE USING A SEMICOLON ";" ---> "[COLOR="#FF0000"];FIQ_Handler     B       FIQ_Handler[/COLOR]" 

  ADD THE FOLLOWING LINE IN THE STARTUP CODE DIRECTLY ABOVE THE "Reset_Addr      DCD     Reset_Handler"

[COLOR="#0000FF"]       IMPORT FIQ_Handler    ;<---- add this line and use space in front of it[/COLOR]

The startup looks like
Code:
; Exception Vectors
;  Mapped to Address 0.
;  Absolute addressing mode must be used.
;  Dummy Handlers are implemented as infinite loops which can be modified.

Vectors         LDR     PC, Reset_Addr         
                LDR     PC, Undef_Addr
                LDR     PC, SWI_Addr
                LDR     PC, PAbt_Addr
                LDR     PC, DAbt_Addr
                NOP                            ; Reserved Vector 
;               LDR     PC, IRQ_Addr
                LDR     PC, [PC, #-0x0FF0]     ; Vector from VicVectAddr
                LDR     PC, FIQ_Addr

[COLOR="#0000FF"]       IMPORT FIQ_Handler    ;<---- add this line and use space in front of it[/COLOR]
Reset_Addr      DCD     Reset_Handler
Undef_Addr      DCD     Undef_Handler
SWI_Addr        DCD     SWI_Handler
PAbt_Addr       DCD     PAbt_Handler
DAbt_Addr       DCD     DAbt_Handler
                DCD     0                      ; Reserved Address 
IRQ_Addr        DCD     IRQ_Handler
[COLOR="#FF0000"];FIQ_Addr        DCD     FIQ_Handler[/COLOR]

Undef_Handler   B       Undef_Handler
SWI_Handler     B       SWI_Handler
PAbt_Handler    B       PAbt_Handler
DAbt_Handler    B       DAbt_Handler
IRQ_Handler     B       IRQ_Handler
FIQ_Handler     B       FIQ_Handler

you comment the red line and add the blue line

Alex
 
Thanks for your reply...
I will follow what you say...
But I want to know.
How can i expertise my self in arm..

It look much more complicated than any other controller I had used till now...

it's really very complicated...
 

You can reads books or find tutorials using google.
The user manual is also very useful.

The FIQ is fairly complicated, I also had a hard time when I ws searching how to use it properly.
 

Can you suggest me any books related to arm 7 lpc2148..
Till now I am not able to finds books on arm7 lpc2148...

Found some codes on internet but not able to understand them...
only few of them compiles rest not...

If you can suggest me a good book it will be a great helpfull for me..
 

Thanks ...
The Code is Working on my Hardware...

Without any problem

Code:
#include <LPC214X.H>

//Function Prototype
void Init_EXT_1(void);
__irq void FIQ_Handler(void);

unsigned char flag;

int main()
{
	flag = 0xAA;
	Init_EXT_1();
	while(1);

}

//Function Definitions
void Init_EXT_1()
{
	PINSEL0 |= (1<<29);				//Enable Pin for receiving External-1 Interrupt P0.14
	IO1DIR = 0x00FF0000;		  	// Port1 16-23 as output
	IO1CLR = 0x00FF0000;
	EXTMODE = 0x02;     /* binary: 00000010 */
    EXTPOLAR = 0x00;     /* binary: 00000000 */
    EXTINT = 0x02;     /* clear the external interrupt flags */
	VICIntSelect = 0x00008000;		// External Interrupt-1 as FIQ Interrupt
	VICIntEnable = 0x00008000;		// Enable External Interrupt-1
}

__irq void FIQ_Handler()
{
	if(flag == 0xAA)
	{
		IOSET1	= 0x00FF0000;		//Set the LED pins
	}
	else if(flag == 0x55)
	{
		IOCLR1 = 0x00FF0000;		//Clear the LED Pins
	}
	flag = ~flag;
	EXTINT = 0x00000002;			//Clear the peripheral interrupt flag
	VICVectAddr = 0;
}
'

I just want to know the changes what you told me to do in the startup file..
What that means can you please explain that
 

There is a default FIQ handler in the startup, you remove it and import your FIQ function
 

But why we don't use the default FIQ....

Can you please elaborate it...
I am also reading the user manual and the document given by you..
Very Usefull
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top