void initAdc() { /* Disable Power down bit to the ADC block. */ LPC_SYSCON->PDRUNCFG &= ~(0x1 << 4); /* Enable AHB clock to the ADC. */ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 13); LPC_IOCON->R_PIO0_11 = 0x02; // Select AD0 pin function LPC_IOCON->R_PIO1_0 = 0x02; // Select AD0 pin function LPC_IOCON->R_PIO1_1 = 0x02; // Select AD0 pin function LPC_IOCON->R_PIO1_2 = 0x02; // Select AD0 pin function LPC_ADC->CR = ((SystemCoreClock / LPC_SYSCON->SYSAHBCLKDIV) / 2400000 - 1) << 8; // Set clock to 2.4 MHz LPC_ADC->CR |= 0x01; // Select channel AD0 NVIC_EnableIRQ(ADC_IRQn); LPC_ADC->INTEN = 0x00F;// enable ADC0 interrupt } void ADC_IRQHandler (void) { static volatile uint8_t selectedChannel = 0; volatile uint32_t value1 = 0, value2 = 0, value3 = 0; value1 = LPC_ADC->DR[selectedChannel]; //this line doesn't seem to transfer the result correctly all the time value2 = value1 >> 6; value3 = value2 & 0x3FF; selectedChannel++; if(selectedChannel > 3){ selectedChannel = 0; } LPC_ADC->CR &= ~0x00FF; LPC_ADC->CR |= (1<<selectedChannel); } |