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

Unexpected ADC Interrupt on Cortex M3 (LPC1788)

I'm using the LPC1788 Cortex M3 ADC and I get intermittent unexpected ADC interrupts. In the following code, I will eventually get an ASSERT. I tried reading the appropriate channel data register thinking it may clear it.

When I get the ASSERT:
globalDataRegister is 0x0100AF60 (no done flag, no overrun flag, but channel 1 has data)
globalStatusRegister is 0x00010002 (channel 1 done flag, no overrun flag, A/D interrupt)

I set up the interrupt:

  int adcChannel = 1
  LPC_ADC->CR |= ADC_CR_CH_SEL(adcChannel);     // select channel
  uint32_t adcReading = LPC_ADC->DR[adcChannel];// clear channel interrupt by reading it
  LPC_ADC->INTEN |= _BIT(adcChannel);           // enable interrupt for channel
  LPC_ADC->CR |= ADC_CR_START_NOW;                // start next conversion

The interrupt Service Routine:

void ADC_IRQHandler (void)
{
  // read channel causing interrupt, its value, its done flag and its overrun flag
  uint32_t globalDataRegister = LPC_ADC->GDR;

  if ( (globalDataRegister & 0x80000000) == 0 ) {
    uint32_t globalStatusRegister = LPC_ADC->STAT;
    ASSERT ( (globalDataRegister & 0x80000000) == 0x80000000 );
    return;
  }
  uint32_t adcChannel =  (globalDataRegister >> 24) & 0x7;

  // interrupt is not cleared unless data register is read ???
  uint32_t adcReading =  (globalDataRegister >> 4) & 0xFFF;
  // uint32_t adcReading =  (LPC_ADC->DR[adcChannel] >> 4) & 0xFFF;

  readingTable[adcChannel] = adcReading;

  LPC_ADC->CR |= ADC_CR_START_NOW;   // start next reading
}