EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC 2148 Timer 0 Interrupt Programming

Started by sarmacsmg July 19, 2011
Hello all,
I am trying to program my lpc 2148 to generate timer0 interrupt. My
development environment is Ububtu with gcc. After a lot of tweaking I
tried the same sample on Keil on windows and the program worked fine.
Complete details are here
. Please let
me know what's going wrong.

Thanks in anticipation.

Cheers!
Sarma
PS: I am posting my query after referring the lists here. I haven't come
across a situation like this. Pardon me if the is a noob approach.

An Engineer's Guide to the LPC2100 Series

OOpps Pardon me for the duplicate post!..

--- In l..., "sarmacsmg" wrote:
>
> Hello all,
> I am trying to program my lpc 2148 to generate timer0 interrupt. My
> development environment is Ububtu with gcc. After a lot of tweaking I
> tried the same sample on Keil on windows and the program worked fine.
> Complete details are here
> . Please let
> me know what's going wrong.
>
> Thanks in anticipation.
>
> Cheers!
> Sarma
> PS: I am posting my query after referring the lists here. I haven't come
> across a situation like this. Pardon me if the is a noob approach.
>

--- In l..., "sarmacsmg" wrote:
>
> OOpps Pardon me for the duplicate post!..
>
> --- In l..., "sarmacsmg" wrote:
> >
> > Hello all,
> > I am trying to program my lpc 2148 to generate timer0 interrupt. My
> > development environment is Ububtu with gcc. After a lot of tweaking I
> > tried the same sample on Keil on windows and the program worked fine.
> > Complete details are here
> > . Please let
> > me know what's going wrong.
> >
> > Thanks in anticipation.
> >
> > Cheers!
> > Sarma
> >
> >
> > PS: I am posting my query after referring the lists here. I haven't come
> > across a situation like this. Pardon me if the is a noob approach.
>
There are too many versions of the code at the linked site to be able to figure out what is going on.

However, IOSET and IOCLR are just IOSET = never IOSET |=

Keil handles ISRs with a different syntax than GNU.

Here is timer.h from one of my projects. It generates 1kHz interrupts but that is based on how I set up the PLL and PCLK which is not shown here. Look at the prototype for T0ISR:

#ifndef _TIMER_H_
#define _TIMER_H_

void T0Init(void);
void T0ISR(void) __attribute__ (( interrupt ));

#endif //_TIMER_H_

The C code looks like:

#include "timer.h"
#include "lpc214x.h"

unsigned int CurrentTime = 0;

void T0Init(void)
{
T0TC = 0;
T0PR = 1;
T0MR0 = 29490;
T0MCR = 0x03;
T0TCR = 0x01;
VICVectCntl3 = 0x00000024;
VICVectAddr3 = (unsigned long) T0ISR;
VICIntEnable = 0x00000010;
}

void T0ISR(void)
{
CurrentTime++;
T0IR = 0x01;
VICVectAddr = 0xFF;
}

There is also a little clock function that returns CurrentTime but it is unimportant for this example.

I haven't checked the Keil startup code versus the GNU version. There is no reason to suspect that they are the same.

The best sample code for the LPC2148 using GCC is at:
www.jcwren.com/arm

Richard


The 2024 Embedded Online Conference