STM32W108单通道如下设置就可以了
void ADCConfigura
tion(void){
// 将GPIOA的引脚5定义为模拟输入
halGpioConfig(PORTA_PIN(5), GPIOCFG_ANALOG);
ADC_CFG = 0;
ADC_OFFSET = 0;
ADC_GAIN = 0x8000;
ADC_DMACFG = ADC_DMARST;
ADC_DMACFG = (ADC_DMAAUTOWRAP | ADC_DMALOAD);
ADC_DMABEG = (int32u)&adcData;
ADC_DMASIZE = 1;
// DMA缓冲区满中断使能
INT_ADCCFG = INT_ADCULDFULL;
// 清除所有中断标志
INT_ADCFLAG = 0xFFFF;
// 使能ADC全局中断
INT_CFGSET = INT_ADC;
ADC_CFG = (// 采样时间:1024 clocks,有效位:10 bits
(5
ADC_GAINR registers.
5. Start the ADC and the DMA.
Write the desired conversion configuration, with the ADC_EN bit set, to ADC_CR.
Clear the ADC buffer full flag – write DMABF to ADC_ISR.
Start the DMA in auto wrap mode – set the AUTOWRAP and LOAD bits in
ADC_DMACR.
6. Wait until the DMABF bit is set in ADC_ISR, then read the result from analogData.
To convert multiple inputs using this approach, repeat Steps 4 through 6, loading the desired
input configurations to ADC_CR in Step 5. If the inputs can use the same offset/gain
correction, just repeat Steps 5 and 6.
一周热门 更多>