EmbeddedRelated.com
Forums

Still Having problems getting vectored interrupts to work on LPC2103 with Keil

Started by C August 4, 2006
Background:

- Im using Keil dev tools with LPC2103 controller
- Need to service two external interrupts EINT1 and EINT2
- Want to use two separate ISRs
- Ive tried sample code from many places

Here is the code I am using to setup the Vectored Interrupts, please
someone let me know if I am missing something or doing something
wrong. Could something be wrong with my Startup.s file, if so could
someone please show me what I should be looking for in the file (what
should be changed, added or removed) I basically re-used the Startup.s
file from one of the sample projects that made a series of LEDs blink.

/* Start of INT init */
VICIntSelect = 0; // Select IRQ
VICIntEnClr = 0xFFFFFFFF;
VICProtection = 0;
VICVectAddr = 0;

VICIntSelect = 0;
VICVectAddr0 = (unsigned long) SignalA_IRQ;
VICVectAddr1 = (unsigned long) SignalB_IRQ;
VICVectCntl0 = 0x0000002F;
VICVectCntl1 = 0x00000030;

PINSEL0 = 0x30000000; // Enable the EXTINT1 & EXTINT2
EXTMODE = 0x26; // Enable EDGE trigger
EXTPOLAR = 0x00; // Set to falling EDGE
EXTINT = EXTINT; // Clear register after mode change

VICIntEnable = 0x00014000; // Enable
VICIntEnClr = 0x00000000;
/* End of code */

/* ISRs */
void SignalB_IRQ (void) __irq {
IOSET0 = 0x800000;
IOCLR0 = 0x010000;

EXTINT = 0x00000002; // Clear the peripheral interrupt flag
VICVectAddr =0x0;
}

void SignalA_IRQ (void) __irq {
IOSET0 = 0x010000;
IOCLR0 = 0x800000;

EXTINT = 0x00000002; // Clear the peripheral interrupt flag
VICVectAddr =0x0;

}
/* End of ISRs */

An Engineer's Guide to the LPC2100 Series

I know it's trivial, but do you enable interrupts in startup code? I.e. do you
clear the I in the CPSR?

Regards,

Dominic

On Friday 04 August 2006 21:40, C wrote:
> Background:
>
> - Im using Keil dev tools with LPC2103 controller
> - Need to service two external interrupts EINT1 and EINT2
> - Want to use two separate ISRs
> - Ive tried sample code from many places
>
> Here is the code I am using to setup the Vectored Interrupts, please
> someone let me know if I am missing something or doing something
> wrong. Could something be wrong with my Startup.s file, if so could
> someone please show me what I should be looking for in the file (what
> should be changed, added or removed) I basically re-used the Startup.s
> file from one of the sample projects that made a series of LEDs blink.
>
> /* Start of INT init */
> VICIntSelect = 0; // Select IRQ
> VICIntEnClr = 0xFFFFFFFF;
> VICProtection = 0;
> VICVectAddr = 0;
>
> VICIntSelect = 0;
> VICVectAddr0 = (unsigned long) SignalA_IRQ;
> VICVectAddr1 = (unsigned long) SignalB_IRQ;
> VICVectCntl0 = 0x0000002F;
> VICVectCntl1 = 0x00000030;
>
> PINSEL0 = 0x30000000; // Enable the EXTINT1 & EXTINT2
> EXTMODE = 0x26; // Enable EDGE trigger
> EXTPOLAR = 0x00; // Set to falling EDGE
> EXTINT = EXTINT; // Clear register after mode change
>
> VICIntEnable = 0x00014000; // Enable
> VICIntEnClr = 0x00000000;
> /* End of code */
>
> /* ISRs */
> void SignalB_IRQ (void) __irq {
> IOSET0 = 0x800000;
> IOCLR0 = 0x010000;
>
> EXTINT = 0x00000002; // Clear the peripheral interrupt flag
> VICVectAddr =0x0;
> }
>
> void SignalA_IRQ (void) __irq {
> IOSET0 = 0x010000;
> IOCLR0 = 0x800000;
>
> EXTINT = 0x00000002; // Clear the peripheral interrupt flag
> VICVectAddr =0x0;
>
> }
> /* End of ISRs */
I dont think so...Hers's what I have at the beginning of my Startup.s,
I've changed the I_Bit value to 0x80 and still nothing:

// Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs

Mode_USR EQU 0x10
Mode_FIQ EQU 0x11
Mode_IRQ EQU 0x12
Mode_SVC EQU 0x13
Mode_ABT EQU 0x17
Mode_UND EQU 0x1B
Mode_SYS EQU 0x1F

I_Bit EQU 0x00 /* when I bit is set, IRQ is disabled */
F_Bit EQU 0x40 /* when F bit is set, FIQ is disabled */
--- In l..., Dominic Rath wrote:
>
> I know it's trivial, but do you enable interrupts in startup code?
I.e. do you
> clear the I in the CPSR?
>
> Regards,
>
> Dominic
>
> On Friday 04 August 2006 21:40, C wrote:
> > Background:
> >
> > - Im using Keil dev tools with LPC2103 controller
> > - Need to service two external interrupts EINT1 and EINT2
> > - Want to use two separate ISRs
> > - Ive tried sample code from many places
> >
> > Here is the code I am using to setup the Vectored Interrupts, please
> > someone let me know if I am missing something or doing something
> > wrong. Could something be wrong with my Startup.s file, if so could
> > someone please show me what I should be looking for in the file (what
> > should be changed, added or removed) I basically re-used the Startup.s
> > file from one of the sample projects that made a series of LEDs blink.
> >
> > /* Start of INT init */
> > VICIntSelect = 0; // Select IRQ
> > VICIntEnClr = 0xFFFFFFFF;
> > VICProtection = 0;
> > VICVectAddr = 0;
> >
> > VICIntSelect = 0;
> > VICVectAddr0 = (unsigned long) SignalA_IRQ;
> > VICVectAddr1 = (unsigned long) SignalB_IRQ;
> > VICVectCntl0 = 0x0000002F;
> > VICVectCntl1 = 0x00000030;
> >
> > PINSEL0 = 0x30000000; // Enable the EXTINT1 & EXTINT2
> > EXTMODE = 0x26; // Enable EDGE trigger
> > EXTPOLAR = 0x00; // Set to falling EDGE
> > EXTINT = EXTINT; // Clear register after mode change
> >
> > VICIntEnable = 0x00014000; // Enable
> > VICIntEnClr = 0x00000000;
> > /* End of code */
> >
> > /* ISRs */
> > void SignalB_IRQ (void) __irq {
> > IOSET0 = 0x800000;
> > IOCLR0 = 0x010000;
> >
> > EXTINT = 0x00000002; // Clear the peripheral interrupt flag
> > VICVectAddr =0x0;
> > }
> >
> > void SignalA_IRQ (void) __irq {
> > IOSET0 = 0x010000;
> > IOCLR0 = 0x800000;
> >
> > EXTINT = 0x00000002; // Clear the peripheral interrupt flag
> > VICVectAddr =0x0;
> >
> > }
> > /* End of ISRs */
>
These lines define macros, they assign a value to the names, so you can
reference them later in your code. You have to leave the I_Bit as 0x80, if
you want to be able to reference the 8th bit of the CPSR by that name.

Does the Startup.s clear the I_Bit later in the code? The sequence should
consist of a MRS, BIC, MSR.

You have to think about the order in which you do things:
- program the VIC
- enable interrupts (clear I_Bit in the CPSR)

You also need code at the IRQ vector (0x18) that fetches the address of the
vectored interrupt from the VIC, like the
LDR pc, [pc,#-0xFF0]
recommended in the LPC2103 user manual.

Regards,

Dominic

On Friday 04 August 2006 21:57, C wrote:
> I dont think so...Hers's what I have at the beginning of my Startup.s,
> I've changed the I_Bit value to 0x80 and still nothing:
>
> // Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
>
> Mode_USR EQU 0x10
> Mode_FIQ EQU 0x11
> Mode_IRQ EQU 0x12
> Mode_SVC EQU 0x13
> Mode_ABT EQU 0x17
> Mode_UND EQU 0x1B
> Mode_SYS EQU 0x1F
>
> I_Bit EQU 0x00 /* when I bit is set, IRQ is disabled */
> F_Bit EQU 0x40 /* when F bit is set, FIQ is disabled */
>
> --- In l..., Dominic Rath wrote:
> > I know it's trivial, but do you enable interrupts in startup code?
>
> I.e. do you
>
> > clear the I in the CPSR?
> >
> > Regards,
> >
> > Dominic
> >
> You also need code at the IRQ vector (0x18) that fetches the address
of the
> vectored interrupt from the VIC, like the
> LDR pc, [pc,#-0xFF0]
> recommended in the LPC2103 user manual.

This is set correctly.
>Does the Startup.s clear the I_Bit later in the code? The sequence
should
> consist of a MRS, BIC, MSR.

I didnt see anything in the Startup.s file that cleared the I_Bit. I
have tried non-vectored interrupts and they work fine, wouldnt the
I_Bit also affect the non-vectored interrupts?
--- In l..., Dominic Rath wrote:
>
> These lines define macros, they assign a value to the names, so you can
> reference them later in your code. You have to leave the I_Bit as
0x80, if
> you want to be able to reference the 8th bit of the CPSR by that name.
>
> Does the Startup.s clear the I_Bit later in the code? The sequence
should
> consist of a MRS, BIC, MSR.
>
> You have to think about the order in which you do things:
> - program the VIC
> - enable interrupts (clear I_Bit in the CPSR)
>
> You also need code at the IRQ vector (0x18) that fetches the address
of the
> vectored interrupt from the VIC, like the
> LDR pc, [pc,#-0xFF0]
> recommended in the LPC2103 user manual.
>
> Regards,
>
> Dominic
>
> On Friday 04 August 2006 21:57, C wrote:
> > I dont think so...Hers's what I have at the beginning of my Startup.s,
> > I've changed the I_Bit value to 0x80 and still nothing:
> >
> > // Standard definitions of Mode bits and Interrupt (I & F) flags
in PSRs
> >
> > Mode_USR EQU 0x10
> > Mode_FIQ EQU 0x11
> > Mode_IRQ EQU 0x12
> > Mode_SVC EQU 0x13
> > Mode_ABT EQU 0x17
> > Mode_UND EQU 0x1B
> > Mode_SYS EQU 0x1F
> >
> > I_Bit EQU 0x00 /* when I bit is set, IRQ is disabled */
> > F_Bit EQU 0x40 /* when F bit is set, FIQ is disabled */
> >
> > --- In l..., Dominic Rath wrote:
> > > I know it's trivial, but do you enable interrupts in startup code?
> >
> > I.e. do you
> >
> > > clear the I in the CPSR?
> > >
> > > Regards,
> > >
> > > Dominic
> >
At the end of SignalB_IRQ() you have this:
EXTINT = 0x00000002;
It should be:
EXTINT = 0x00000004;
Regards
Zdravko Dimitrov

PS: VICIntEnClr = 0x00000000; is nonsense.

--- C wrote:

> Background:
>
> - Im using Keil dev tools with LPC2103 controller
> - Need to service two external interrupts EINT1 and
> EINT2
> - Want to use two separate ISRs
> - Ive tried sample code from many places
>
> Here is the code I am using to setup the Vectored
> Interrupts, please
> someone let me know if I am missing something or
> doing something
> wrong. Could something be wrong with my Startup.s
> file, if so could
> someone please show me what I should be looking for
> in the file (what
> should be changed, added or removed) I basically
> re-used the Startup.s
> file from one of the sample projects that made a
> series of LEDs blink.
>
> /* Start of INT init */
> VICIntSelect = 0; // Select IRQ
> VICIntEnClr = 0xFFFFFFFF;
> VICProtection = 0;
> VICVectAddr = 0;
>
> VICIntSelect = 0;
> VICVectAddr0 = (unsigned long) SignalA_IRQ;
> VICVectAddr1 = (unsigned long) SignalB_IRQ;
> VICVectCntl0 = 0x0000002F;
> VICVectCntl1 = 0x00000030;
>
> PINSEL0 = 0x30000000; // Enable the EXTINT1 &
> EXTINT2
> EXTMODE = 0x26; // Enable EDGE trigger
> EXTPOLAR = 0x00; // Set to falling EDGE
> EXTINT = EXTINT; // Clear register after mode
> change
>
> VICIntEnable = 0x00014000; // Enable
> VICIntEnClr = 0x00000000;
> /* End of code */
>
> /* ISRs */
> void SignalB_IRQ (void) __irq {
> IOSET0 = 0x800000;
> IOCLR0 = 0x010000;
>
> EXTINT = 0x00000002; // Clear the
> peripheral interrupt flag
> VICVectAddr =0x0;
> }
>
> void SignalA_IRQ (void) __irq {
> IOSET0 = 0x010000;
> IOCLR0 = 0x800000;
>
> EXTINT = 0x00000002; // Clear the
> peripheral interrupt flag
> VICVectAddr =0x0;
>
> }
> /* End of ISRs */
Знанието е лично преживяна истина.

__________________________________________________