This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ARM7 Timer Interrupts (Some working...some not)

All:

I am writing a few test apps to get familiarized with the peripherals on the LPC2378 ARM7. I am using a Keil MCB2300 board to do so.

I've managed to get Timer0 and Timer1 to generate interrupts on 100 msec and 300 msec intervals respectively. I am trying to set up Timer2 to generate and interrupt similarly. Timer0 and Timer1 both work fine. But, I am having no luck with Timer2.

Unfortunately, the peripheral windows in uVision3 don't yet support Timers 2 and 3, so I can't see for sure if things are getting set correctly. But, I am following the same logic that I used for the first two. Here's the IRQ.C code:

#include <LPC23xx.H>                    /* LPC23xx definitions                */



/* Import function for turning LEDs on or off                                 */
extern void LED_On (unsigned int num);
extern void LED_Off(unsigned int num);
extern int debug_cntr;

/* Timer0 IRQ: Executed periodically                                          */
__irq void T0_IRQHandler (void) {
  static unsigned int clk_cntr;
  clk_cntr++;
  if((clk_cntr%2)==0) LED_On(1);
  else LED_Off(1);
  T0IR        = 1;                      /* Clear interrupt flag               */
  VICVectAddr = 0;                      /* Acknowledge Interrupt              */
}


__irq void T1_IRQHandler(void){
  static unsigned int clk_cntr1;
  clk_cntr1++;
  if((clk_cntr1%2)==0) LED_On(2);
  else LED_Off(2);
  T1IR=1;
  VICVectAddr=0;
}

__irq void T2_IRQHandler(void){
  static unsigned int clk_cntr2;
  clk_cntr2++;
  debug_cntr++;
  if((clk_cntr2%2)==0) LED_On(3);
  else LED_Off(3);
  T2IR=1;
  VICVectAddr=0;
}

And here is the main code that sets the VIC and timers up (does some serial stuff too).

#include <stdio.h>
#include <LPC23xx.H>                    /* LPC23xx definitions                */
#include "LCD.h"                        /* Graphic LCD function prototypes    */
#define CR  10
#define LF  13
void LED_Init(void);
void LED_On(unsigned int num);
void LED_Off(unsigned int num);

 /* Import external functions from Serial.c file */
extern int sendchar (int ch);
extern int getkey (void);
extern __irq void T0_IRQHandler  (void);
extern __irq void T1_IRQHandler  (void);
extern __irq void T2_IRQHandler  (void);

extern void init_serial(void);
unsigned int debug_cntr=0;

int main (void) {
  int count=0;
  unsigned char val=0;
  int retval=0;


  LED_Init();                           /* LED Initialization                 */

  init_serial();                               /* Init UART                   */

  lcd_init();
  lcd_clear();
  lcd_print ("  RM_Timer  ");
  set_cursor (0, 1);
  lcd_print ("  11/19/2006  ");


  /* Enable and setup timer interrupt, start timer                            */
  T0MR0         = 1439999;                       /* 100msec = 1440000-1 at 14.4 MHz */
  T0MCR         = 3;                           /* Interrupt and Reset on MR0  */
  T0TCR         = 1;                           /* Timer0 Enable               */
  VICVectAddr4  = (unsigned long)T0_IRQHandler;/* Set Interrupt Vector        */
  VICVectCntl4  = 4;                          /* use it for Timer0 Interrupt */
  VICIntEnable  = (1  << 4);                   /* Enable Timer0 Interrupt     */


  T1MR0         = 4319999;                      /* 300msec = 4320000-1 at 14.4 Mhz */
  T1MCR         = 3;
  T1TCR         = 1;
  VICVectAddr5  = (unsigned long)T1_IRQHandler;
  VICVectCntl5  = 5;
  VICIntEnable  = (1 << 5);

  T2MR0         = 1439999;
  T2MCR         = 3;
  T2TCR         = 1;
  VICVectAddr26 = (unsigned long)T2_IRQHandler;
  VICVectCntl26 = 26;
  VICIntEnable  = (1 << 26);

  while(1)
  {
    printf("Count= %d",count++);
    val=getkey();
    LED_On(7);                   //give a little flash to let us know its working!
    printf("\tYou typed: ");
    retval=sendchar(val);
    retval=sendchar(CR);  //Carriage Return
    retval=sendchar(LF);  //Linefeed
    LED_Off(7);
  }


}

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

/* Function that initializes LEDs                                             */
void LED_Init(void) {
  PINSEL10 = 0;                         /* Disable ETM interface, enable LEDs */
  FIO2DIR  = 0x000000FF;                /* P2.0..7 defined as Outputs         */
  FIO2MASK = 0x00000000;
}

/* Function that turns on requested LED                                       */
void LED_On (unsigned int num) {
  FIO2SET = (1 << num);
}

/* Function that turns off requested LED                                      */
void LED_Off (unsigned int num) {
  FIO2CLR = (1 << num);
}

/* Function that outputs value to LEDs                                        */
void LED_Out(unsigned int value) {
  FIO2CLR = 0xFF;                       /* Turn off all LEDs                  */
  FIO2SET = (value & 0xFF);             /* Turn on requested LEDs             */
}

Anybody see what I'm missing?

Best Regards,

-=Rich=-

0