EmbDev.net

Forum: ARM programming with GCC/GNU tools Help on Timer0 interrupt in LPC2214


Author: sprint (Guest)
Posted on:

Rate this post
0 useful
not useful
I have a problem in firing the inteerupt in ISR.I have posted my source
code here for your ref.Iam checking for a flag, in main()- while()loop,
which is never enabled in TIMER0 ISR.But when i used polling mode its
working fine. So I think I definately missing some things some where. I
have used this timer ISR to trigger for every 10seconds.
Environment: Eclipse/GNUARM/LPC2214..
I didnt do any thing related to this ISR in any of the startup file and
linker script..Please help me on this.

/******************************

main()
{
InitVIC();
while(1)
{
if(Timer_Flag==1)
{
LEDON;
}
}

}

void InitVIC()
{
VICProtection = 0; // Setup interrupt controller.


VICIntEnClear = 0xffffffbf; // Disable all interrupts but the one used
for the ROM monitor

VICDefVectAddr = (unsigned int)&DefDummyInterrupt;

T0TCR = 2; // Disable timer 0. and rese
T0PC = 0; // Prescaler is set to no division.
T0MR0 = 0xE666; //PCLKFREQ/1000; // Count up to this value. Generate
1000 Hz interrupt.
T0MCR = 3; // Reset and interrupt on MR0 (match register 0).
T0CCR = 0; // Capture is disabled.
T0EMR = 0; // No external match output.

T0TCR = 1; // Enable timer 0.

VICIntSelect &= ~(0x10); // IRQ on timer 0 line.
VICVectAddr1 = (unsigned int)TimerInterrupt;
VICVectCntl1 = 0x20 | 0x04; // Enable vector interrupt for timer 0.
VICIntEnable = 0x10; // Enable timer 0 interrupt.
}

// Timer interrupt handler
static void TimerInterrupt()
{
(*timer_function)(); // Call timer callback function.

Timer_Count++;
Timer_Flag=0;

if(Timer_Count>10000)
{Timer_Count=0;Timer_Flag=1;}

T0IR = 0xff; // Clear timer 0 interrupt line.
}

//Dummy interrupt handler, called as default in irqHandler() if no other
vectored interrupt is called.
static void DefDummyInterrupt()
{}
**/

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 useful
not useful
I have not looked to close on your code.  Just some general hints:

Are interrupts enabled in the cpsr (IRQ-Bit)? I do not see this in your
code. See the file armVIC.c which is included in some of the examples to
see how to enable interrupts in "non-user"-mode.

Interrupts can also be enabled in the startup-code, usualy together with
the initialisation of the stacks or by implementing an SWI-Handler with
functions to enabled/disable interrupts.

Is the flag-variable defined with "volatile"?

Martin Thomas

Author: sprint (Guest)
Posted on:

Rate this post
0 useful
not useful
Martin,

Thanks for your suggestions.
I have checked the CPSR.. it is enabed in startup file. and also the
flag is defined as volatile.But even its not working.. when i tried to
use armVIc.c and called enableIRQ()..then the lpc2214 is continuously
resetting.. what could be the problem.. If you have some time, I will
send the start up file also.It is working in polling mode.
Thanks for your help and appreciate it.



Martin Thomas wrote:
> I have not looked to close on your code.  Just some general hints:
>
> Are interrupts enabled in the cpsr (IRQ-Bit)? I do not see this in your
> code. See the file armVIC.c which is included in some of the examples to
> see how to enable interrupts in "non-user"-mode.
>
> Interrupts can also be enabled in the startup-code, usualy together with
> the initialisation of the stacks or by implementing an SWI-Handler with
> functions to enabled/disable interrupts.
>
> Is the flag-variable defined with "volatile"?
>
> Martin Thomas

Author: Martin Thomas (Guest)
Posted on:

Rate this post
0 useful
not useful
Sorry, I do not own an LPC2214 board and so I can not test, also I do
not like code with a lot of "magic-hex-numbers".

Did you compare your code with the timer-code in the blink_switch_irq
examples? If you are writing for ARM-machine-code you have to declare
the ISR with an attribute (_attribute_ ((interrupt("IRQ"))). The
IRQ-attribute-method does not work for me with thumb/interwork and
optimisation enabled (at least until gcc 4.0.2 it may be fixed in
4.1.0). For this you may follow the other examples which declare the ISR
with attribute "nacked" and include entry- and exit-macros. There have
been discussions in the gnuarm yahoo-group that those macros are not
needed but it simply did not work for me with attr IRQ and thumb/opt.
without naked/macros.

The third option are "assembler-wrappers" as demonstrated i.e. in the
Atmel-"uart-simple"-example (for the AT91SAM7 AIC not the Philips VIC
but you should get the idea). With such wrappers you do not need
attributes or macros.

Martin Thomas

Author: Guest (Guest)
Posted on:

Rate this post
0 useful
not useful
on LPC2129 wors fine:


#include <LPC21XX.H>            // LPC21XX Peripheral Registers
#include "timer.h"
#include "ssi.h"


long time;
char time_to_check;
char time_to_send;
char time_to_receive;

// Timer Counter 0 Interrupt
void tc0 (void) __irq  {

  if((time%TIME_TO_CHECK)==0) time_to_check=1;
  if((time%TIME_TO_SEND)==0) time_to_send=1;

  ++time;
  T0IR        = 1;            // Clear interrupt flag
  VICVectAddr = 0;            // Acknowledge Interrupt
}


// Setup the Timer Counter 0 Interrupt
void Timer_Init(void) {
  T0MR0 = 300000;              // 1Sec = 30,000,000 counts  on 12MHz*5
  T0MCR = 3;                // Interrupt and Reset on MR0
  T0TCR = 1;                // Timer0 Enable
  VICVectAddr3 = (unsigned long)tc0;    // set interrupt vector in 3
  VICVectCntl3 = 0x24;          // use it for Timer 0 Interrupt
  VICIntEnable |= 0x00000010;        // Enable Timer0 Interrupt
}

Mirek

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.