Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

timer interrupt not firing in lpc2106

timer interrupt not firing in lpc2106

2006-01-11 by vicky gosar

hi
   
  i am working on the lpc2106 
  i have been working day & night to get the timer interrupt to fire but it is not.
   
  i have attached my code along with the message.
  i am using crossworks v1.2
   
  the timer interrupt is trigerred but it does not go to the ISR & stops responding
   
  if anybody can help i will be greatly grateful to him
   
  please reply 
   
  Vicky


Send instant messages to your online friends http://in.messenger.yahoo.com 
  ----------

// Copyright (c) 2001-2004 Rowley Associates Limited.
//
// This file may be distributed under the terms of the License Agreement
// provided with this software.
//
// THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
////////////////////////////////////////////////////////////////////////////////
//
//                    Philips LPC210X - UART Example
//
// Description
// -----------
// This example demonstrates configuring and writing to a UART. It also 
// demonstrates how to get printf output over the UART by implementing 
// __putchar.
//
// To see output:
//   - Connect serial cable from UART0 connector on your target board to your
//     host computer.
//   - Open CrossStudio's "Terminal Emulator Window". Configure it to 9600 baud, 
//     8 data bits, no parity, 1 stop bits. Click "Connect" to start the
//     terminal emulator window.
//
////////////////////////////////////////////////////////////////////////////////

#include <targets/LPC210x.h>
#include <stdio.h>
//#include <ctl_api.h>

static int timer0Count, timer1Count;
static unsigned int processorClockFrequency();
static unsigned int peripheralClockFrequency();
static void delay(int n);
static void UARTInitialize(unsigned int baud);
static void UARTWriteChar(unsigned char ch);
static unsigned char UARTReadChar();
static void UARTWriteChar(unsigned char ch);
void __putchar(int ch);
static void ledInit();
static void ledOff();
static void ledOn();
static void tim_init(void);

static unsigned int
processorClockFrequency(void)
{
  return 14.7456 * 1000000 * (PLLCON & 1 ? (PLLCFG & 0xF) + 1 : 1);
}

static unsigned int
peripheralClockFrequency(void)
{
  unsigned int divider;
  switch (VPBDIV & 3)
    {
      case 0:
        divider = 4;
        break;
      case 1:
        divider = 1;
        break;
      case 2:
        divider = 2;
        break;
    }
  return processorClockFrequency() / divider;
}

static void
delay(int n)
{
  volatile int i;
  for (i = 0; i < n; ++i);
}

static void
UARTInitialize(unsigned int baud)
{
  unsigned int divisor = peripheralClockFrequency() / (16 * baud);
  U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
  U0DLL = divisor & 0xFF;
  U0DLM = (divisor >> 8) & 0xFF;
  U0LCR &= ~0x80; /* Disable DLAB */
  PINSEL0 = PINSEL0 & ~0xF | 0x5;
  U0FCR = 1;
}

static void
UARTWriteChar(unsigned char ch)
{
  while ((U0LSR & 0x20) == 0);
  U0THR = ch;
}

static unsigned char
UARTReadChar(void)
{
  while ((U0LSR & 0x01) == 0);
  return U0RBR;
}

void 
__putchar(int ch)
{
  if (ch == '\n')
    UARTWriteChar('\r');
  UARTWriteChar(ch);
}


static void
ledInit()
{
  IODIR |= 0x00000080;
  IOSET = 0x00000080;
}

static void
ledOff(void)
{
  IOCLR = 0x00000080;
}

static void
ledOn(void)
{
  IOSET = 0x00000080;
}

static void timer0ISR(void) __attribute__ ((interrupt ("IRQ")));

static void
timer0ISR(void)
{
  if (++timer0Count % 2)
    ledOn();
  else
    ledOff();
  /* Clear the timer 0 interrupt */
  T0IR = 0xFF;
  /* Update VIC priorities */
  VICVectAddr = 0;
}

static void timer1ISR(void) __attribute__ ((interrupt ("IRQ")));

static
void
timer1ISR(void)
{
  ++timer1Count;
  /* Clear the timer 1 interrupt */
  T1IR = 0xFF;
  /* Update VIC priorities */
  VICVectAddr = 0;
}

static void
tim_init(void)
{
//   T0IR = 0;
//   T1IR = 0;
     T0IR = 0x00000000;
     T1IR = 0x00000000; 
 
   T0TC = 0;
   T1TC = 0;

/* Timer 0 interrupt is an IRQ interrupt */
  VICIntSelect &= ~0x10;
  /* Enable timer 0 interrupt */
  VICIntEnable = 0x10;
  /* Use slot 0 for timer 0 interrupt */
  VICVectCntl0 = 0x24;
  /* Set the address of ISR for slot 0 */
  VICVectAddr0 = (unsigned long)timer0ISR;

  /* Timer 1 interrupt is an IRQ interrupt */
  VICIntSelect &= ~0x20;
  /* Enable timer 1 interrupt */
  VICIntEnable = 0x20;
  /* Use slot 1 for timer 1 interrupt */
  VICVectCntl1 = 0x25;
  /* Set the address of ISR for slot 1 */
  VICVectAddr1 = (unsigned long)timer1ISR;

  /* Reset timer 0 */
  T0TCR = 0;//timer Control register
  /* Set the timer 0 prescale counter */
  T0PR = 2500000;
  /* Set timer 0 match register */
  T0MR0 = 10;
  /* Generate interrupt and reset counter on match */
  T0MCR = 3;
  /* Start timer 0 */
  T0TCR = 1;

  /* Reset timer 1 */
  T1TCR = 0;
  /* Set the timer 1 prescale counter */
  T1PR = 2500000;
  /* Set timer 1 match register */
  T1MR0 = 10;
  /* Generate interrupt and reset counter on match */
  T1MCR = 3;
  /* Start timer 1 */
  T1TCR = 1;

  T0IR = 0;
   T1IR = 0;
}


int
main(void)
{
  int i;
  unsigned char vic;

  tim_init();
  UARTInitialize(9600);
  ledInit();
  delay(1000);
  /* Enable Interrupts */
  //__ARMLIB_enableIRQ();
  
  for (i = 0; ; ++i)
   { 
    printf("Hello World (%d) (%d) (%d)\n\n", i,T0TC,T1TC);
 //   printf("Vicky (%d)\n\r",i);
 //   printf("Kushal (%d)\n\r",i);
 //   printf("Bimal (%d)\n\r",i);

      //vic = UARTReadChar();
      //putchar(vic);
      
      if(T0IR != 0 || T1IR != 0)
      {
       printf("Interrupt (%d) (%d)",T0IR,T1IR);
       T0IR = 0x00000000;
       T1IR = 0x00000000; 
      }
      
      ledOff();
      delay(100000);
      ledOn();
      delay(100000); 
    }
       return 0;
  }
        


[Non-text portions of this message have been removed]

Re: [lpc2000] timer interrupt not firing in lpc2106

2006-01-11 by Aalt Lokhorst

Hello Vicky,

I am just leaving the office so no time to check, but I can remember two
things from my first experience with the interrupts.

Enable the IRQ in your main()
(The line is already in your main() but its commented)

Add the define VECTORED_IRQ_INTERRUPTS.
(See the Startup.s file for details, it is needed to load the 
VICVectAddr register on an IRQ)

By the way, you are using version 1.2 but Rowley is already at v1.5 and 
I think our Rowley friends are very busy working on 1.6.
(Any information? Paul, Michael, Jon...?)

Best Regards,
Aalt

-- 
==============================
Aalt Lokhorst
Schut Geometrische Meettechniek bv
Duinkerkenstraat 21
9723 BN Groningen
P.O. Box 5225
9700 GE Groningen
The Netherlands
Tel: +31-50-5877877
Fax: +31-50-5877899
E-mail: Lokhorst@...
==============================


vicky gosar wrote:
Show quoted textHide quoted text
>   hi
>   
>   i am working on the lpc2106
>   i have been working day & night to get the timer interrupt to fire but 
> it is not.
>   
>   i have attached my code along with the message.
>   i am using crossworks v1.2
>   
>   the timer interrupt is trigerred but it does not go to the ISR & stops 
> responding
>   
>   if anybody can help i will be greatly grateful to him
>   
>   please reply
>   
>   Vicky

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.