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

lpc 2148 adc interrupt problem

hello i have written code for for adc in interupt mode using keil for lpc 2148 controller.im getting a problem such that whenever interrupt occurs for first time control goes to isr routine
and the returns to main but,for next conversion i,e interrupt invoke control desnt goes to isr.

here is the code

#include<stdio.h>
#include<lpc214x.h>
#include"uart.h"

unsigned int convert,convert1,reg;
volatile int flag=0;

void adc_isr(void) __irq

{

 convert = (AD0DR3 >> 6)& 0x3ff;
 convert1=AD0GDR;
 reg=AD0STAT;
 //AD0CR &= 0xF8FFFFFF;
 VICVectAddr0 = 0;
 flag=1;


}


adc_intr()

{

PINSEL1 = (1<<28);
AD0CR |= (1<<3);
AD0CR |= 0x0000D00;
AD0CR |= (1<<16); //burst mode
AD0CR |= (1<<21);
//AD0CR |= (1<<24); //start conversion now

AD0INTEN |= (1<<3);
//AD0INTEN |= (1<<8);
VICVectCntl0 = 0x32;
VICVectAddr0 = (unsigned long)adc_isr;
VICIntEnable = (1<<18);

}



int main()

{



 uart_init();
 adc_intr();

 while(1)
 {
  if(flag==1)
  {
   tx_ch('h');
   flag=0;
  }
 }



}


  • How can you read code like this and understand what it does - or get it to work?

    PINSEL1 = (1<<28);
    AD0CR |= (1<<3);
    AD0CR |= 0x0000D00;
    AD0CR |= (1<<16); //burst mode
    AD0CR |= (1<<21);
    //AD0CR |= (1<<24); //start conversion now
    
    AD0INTEN |= (1<<3);
    //AD0INTEN |= (1<<8);
    

    Lots of sequences of random, magic, values written to registers. What part of you don't think it important for a reader to see exactly what the line does?

    Exactly what is (1<<3)? You expect a full revisit to the user manual/datasheet whenever you want to look at a source code line? Another thing - only doing "relative" accesses can sometimes hurt. Sometimes it is very helpful to perform a full assign of all bits of the register, while documenting what that full assign actually does.

  • 
    #include<stdio.h>
    #include<lpc214x.h>
    #include"uart.h"
    
    unsigned int convert,convert1,reg;
    volatile int flag=0;
    
    void adc_isr(void) __irq
    
    {
    
    convert = (AD0DR3 >> 6)& 0x3ff;
    
    convert1=AD0GDR;
    
    reg=AD0STAT;
    
    VICVectAddr0 = 0;
    
    flag=1;
    
    
    }
    
    
    adc_intr()
    
    {
    
    PINSEL1 = 0x10000000;  //select pin AD0.3
    
    AD0CR = 0x00210D08; //select channel 0.3,burst mode,operational mode
    
    
    AD0INTEN = 0x00000008; // will generate interrupt for ADC channel 3
    
    VICVectCntl0 = 0x32;
    
    VICVectAddr0 = (unsigned long)adc_isr;
    
    VICIntEnable = 0x00040000; //enble AD0 interrupt source
    
    }
    
    int main()
    {
    
    
    
     uart_init();
    
     adc_intr();
    
     while(1)
     {
    
       if(flag==1)
    
       {
    
         tx_ch('h');
    
         flag=0;
    
       }
    
     }
    
    
    
    }