I am using LPC1768 for my project. I used the following code to test the micro-controller's ADC on a training board. The code reads the channel 5 of the ADC and puts its value on DAC(polling strategy). However using a new designed board for the project the code does not run correctly on the new board. I'm sure that the program enters the ADC's interrupt service routine since un-comenting the commented lines of the code leads to generating a ramp signal in the DAC output (which is done in the ADC_IRQHandler). On the other hand the signal is valid on the related ADC pin (checked on oscilloscope). It seems the problem is related to an internal setting of LPC1768. Any clues? Thanks!
#define CLKDIV 38 uint32_t counter; void ADC_Init (void) { LPC_SC->PCONP |= (1<<12); /* Enable power to ADC block */ LPC_PINCON->PINSEL1 &= ~(3UL<<14); /* P1.23 is GPIO */ LPC_PINCON->PINSEL1 |= (1UL<<14); /* P1.23 is AD0.0 */ LPC_ADC->ADCR = (1UL << 0) | /* select AD0.0 */ (CLKDIV << 8) | /* ADC clock */ (1UL << 16) | /* ADC is in the burst mode */ (1UL << 21); /* enable ADC */ LPC_ADC -> ADINTEN = 0x00000001; /* enable interrupt on channel 0*/ } void ADC_IRQHandler (void) { uint32_t addr0; addr0 = LPC_ADC->ADDR0; addr0 = addr0 >> 6; // counter += 1; LPC_DAC->DACR = (addr0 & 0x3ff) << 6; // LPC_DAC->DACR = ((counter) & 0x3ff) << 6; } void DACInit(void) { /* setup the related pin to DAC output */ LPC_PINCON->PINSEL1 = 0x00200000; /* set p0.26 to DAC output */ LPC_DAC->DACCTRL = (1UL << 1); /* double-buffering is enabled */ return; } int main(void) { SystemInit(); ADC_Init(); DACInit(); NVIC_EnableIRQ(ADC_IRQn); while (1) { } }