
UM10800
All information provided in this document is subject to legal disclaimers.
© NXP Semiconductors N.V. 2016. All rights reserved.
User manual
Rev. 1.2 — 5 October 2016
439 of 487
NXP Semiconductors
UM10800
Chapter 30: LPC82x ROM API ADC drivers
// < RAMBLOCK_H
adc_handle_0 = pAdcApi->adc_setup(LPC_ADC0_BASE, (uint8_ *)start_of_ram_block0);
5. Set up the ADC0 for calibration by defining the ADC_CONFIG_T structure:
ADC_CONFIG_T adc_set;
adc_set.system_clock = SYSTEMCLOCK; //system clock
adc_set.adc_clock = ADC_CALIB_CLK; // ADC clock
6. Always calibrate the ADC before performing conversions:
pAdcApi->adc_calibration(adc_handle_0, &adc_set);
7. Set up the ADC0 for interrupt mode using the hardware trigger pin ADC0_PINTRIG0
by defining the ADC_CONFIG_T structure:
adc_set.adc_clock = ADC_ADC_CLK; // this is the ADC clock - in synchronous mode
//equal to the system clock divided by the CLKDIV value in the CTRL register
// in synchronous mode set system_clock >= adc_clock.
adc_set.async_mode = 0; //async mode disabled
adc_set.tenbit_mode = 0; //10-bit mode disabled
adc_set.lpwr_mode = 0; //low-power mode disabled
adc_set.thr0_low = 0; //threshold disabled
adc_set.thr0_high = 0; //threshold disabled
adc_set.thr1_low = 0; //threshold disabled
adc_set.thr1_high = 0; //threshold disabled
adc_set.error_en = OVR_ENA; //overrun error interrupt disabled
adc_cfg.seqa_ctrl = CHANNELS(0xFFF) | TRIGGER(0x0); //use all 12 channels and
// trigger # 0
adc_cfg.channel_num = 0xC; // highest channel number is 12
8. Initialize ADC0 conversion:
pAdcApi->adc_init(adc_handle_0, &adc_set);
9. Enable the ADC_SEQA interrupt in the NVIC.
10. Set up the ADC parameter structure ADC_PARAM_T:
param.driver_mode = 0x01; //interrupt mode.
param.seqa_hwtrig = 0x1;
param.adc_cfg = (ADC_CONFIG_T *)&adc_cfg;
param.buffer = (uint32_t *)adc_buffer;
param.comp_flags = 0;
param.seqa_callback_pt = adc_seqa_callback;
11. Define the callback function invoked when the sequence A interrupt is raised. The
ADC0 handle is passed as an argument to the callback function.
void adc_seqa_callback( ADC_HANDLE_T handle ) {
ADC_DRIVER_TypeDef *driver = (ADC_DRIVER_TypeDef *)handle;
ADC_REGS_T *adcr = ((ADC_REGS_T *)((ADC_DRIVER_TypeDef
*)handle)->base_addr);
if ((ErrorCode_t)driver->error_code != LPC_OK) {
while(1);
}
adcr->SEQA_CTRL &= ~( ADC_SEQ_ENA ); // stop ADC SEQA now.
adcr->INTEN &= ~SEQA_ENA;
completiona_tag = 1;