ADC interrupt problem in LPC2138

Guest #2043241
Hi!

I am using yagarto last ver. in my project. normaly if i use timer0 
interrupt in project, everything ok! timer0 is working.(the LED is 
blinking!!)
if i use two interrupt in system (timer0 and A/D0 ) the system is 
halting.
the code as below,

cpu: LPC2138
//---------------------------------------------------------
#define IRQ_MASK (~0x000000C0)

void tc0_IRQ(void) __attribute__((interrupt("IRQ")));
void adc0_IRQ(void) __attribute__((interrupt("IRQ")));
//-------------------------------------------------------------
/* ****************************************************** */

void EnableIRQ(void)
{
  _SET_CPSR(_GET_CPSR() & IRQ_MASK);

}
/******************************************************** */
static inline unsigned _GET_CPSR(void)
{
  unsigned long retCode;
  asm volatile (" mrs  %0, cpsr" : "=r" (retCode) : );
  return retCode;
}
/* ****************************************************** */
static inline void _SET_CPSR(unsigned value)
{
  asm volatile (" msr  cpsr, %0" : : "r" (value)  );
}
/* ****************************************************** */


void vectorinit (void)
{
#define VICVectCntl0_ENABLE (1<<5)
#define VIC_Channel_Timer0  4
#define VIC_Channel_adc0  18

    // setup timer0 for IRQ
  // set interrupt as IRQ
  VICIntSelect &= ~(1<<VIC_Channel_Timer0);
  VICIntEnable |=  (1<<VIC_Channel_Timer0);// Enable Timer0 Interrupt
  VICIntEnable |=  (1<<VIC_Channel_adc0);


  // assign VIC slot
  VICVectCntl0 = VICVectCntl0_ENABLE | VIC_Channel_Timer0;// use it for 
Timer 0 Interrupt
  VICVectCntl1 = VICVectCntl0_ENABLE | VIC_Channel_adc0;

  VICVectAddr0 = (unsigned long )tc0_IRQ;// set interrupt vector in  0
  VICVectAddr1 = (unsigned long )adc0_IRQ;// set interrupt vector in 1

  /* Enable interrupts */
  EnableIRQ();

}
****************************************************************

void adc0_IRQ (void)
{

#define VIC_Channel_adc  18

unsigned int r,ch;
     VICVectAddr = 0x00000000;       // clear this interrupt from the 
VIC
    //
    //------------------------------------------------------
  r = AD0DR; // Read Data Register and clear DONE flag
  ch = (r >> 24) & 0x07; // which channel was converted
  ADCresult0[ch] = (r>>6) & 0x03FF; // bit 6:15 is 10 bit AD value
:
:Some code in here....
}
/******************************************************* */
void tc0_IRQ (void)
{
:
:some code in here...
:

            VICVectAddr = 0x00000000;             // clear this 
interrupt from the VIC
     T0IR |= 0x00000001;
}
/**********************************************************/
 void init_adc0(unsigned char clk_div){

 PINSEL0 |= 0x00003C00; // P0.5, P0.6 setup for AD0.7, AD1.0
 PCONP |= 0x00001000;   /*Power on the A/D converter 0 */
                          // AD0CR = 0x00200604; // enable ADC, 11 
clocks/10 bits, ADC clock = 4.286MHz
   AD0CR = ( ((clk_div-1))<<8 ) | pdn_bit  ; /* | (1<<ch) configuerthe 
A/D control register of A/D 0  with clock = PCLK/(14+1) = 3.8Mhz
*/
  // power up
   AD0CR |= 0x00010000;    // start burst mode

}
//***************************************************************
//********************************************************************** 
******
int main(void)
{

some code.......

init_adc0(14); /*pass channel number and clkdiv*/
init_adc1(14);
:
:
:
:
}
------------------------------------------------------------------

Best regrads
kamil

Reply

A question of your own? This thread is over 15 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.