初级会员
- 积分
- 60
- 金钱
- 60
- 注册时间
- 2012-12-28
- 在线时间
- 7 小时
|
1金钱
代码如下stm32L471 ADC DMA采样。
1.采样时间为LL_ADC_SAMPLINGTIME_2CYCLES_5 一切正常,当改变时无法采集到数据。
2.同时 LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_6, LL_ADC_SINGLE_ENDED); 设置多个通道后者不设置 都无法采集到数据
以上两个问题十分怪异!
LL_ADC_InitTypeDef ADC_InitStruct = {0};
LL_ADC_REG_InitTypeDef ADC_REG_InitStruct = {0};
LL_ADC_CommonInitTypeDef ADC_CommonInitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
u8 i;
//ADC 时钟初始化
LL_RCC_PLLSAI1_ConfigDomain_ADC(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_1, 8, LL_RCC_PLLSAI1R_DIV_2);
LL_RCC_PLLSAI1_EnableDomain_ADC();
LL_RCC_PLLSAI1_Enable();
while(LL_RCC_PLLSAI1_IsReady() != 1);
LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_PLLSAI1);
//ADC
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_ADC);
ADC_CommonInitStruct.CommonClock = LL_ADC_CLOCK_ASYNC_DIV1;
ADC_CommonInitStruct.Multimode = LL_ADC_MULTI_INDEPENDENT;
ADC_CommonInitStruct.MultiTwoSamplingDelay=LL_ADC_MULTI_TWOSMP_DELAY_12CYCLES;
ADC_CommonInitStruct.Multimode=LL_ADC_MULTI_INDEPENDENT;
LL_ADC_CommonInit(__LL_ADC_COMMON_INSTANCE(ADCx), &ADC_CommonInitStruct);
LL_ADC_SetMultiDMATransfer(__LL_ADC_COMMON_INSTANCE(ADCx),LL_ADC_MULTI_REG_DMA_UNLMT_RES12_10B);
ADC_InitStruct.Resolution = LL_ADC_RESOLUTION_12B;
ADC_InitStruct.DataAlignment = LL_ADC_DATA_ALIGN_RIGHT;
ADC_InitStruct.LowPowerMode = LL_ADC_LP_MODE_NONE;
LL_ADC_Init(ADC1, &ADC_InitStruct);
ADC_REG_InitStruct.TriggerSource = LL_ADC_REG_TRIG_SOFTWARE;
ADC_REG_InitStruct.SequencerLength = 3-1;
ADC_REG_InitStruct.SequencerDiscont = LL_ADC_REG_SEQ_DISCONT_DISABLE;
ADC_REG_InitStruct.ContinuousMode = LL_ADC_REG_CONV_CONTINUOUS;
ADC_REG_InitStruct.DMATransfer = LL_ADC_REG_DMA_TRANSFER_UNLIMITED; //
ADC_REG_InitStruct.Overrun = LL_ADC_REG_OVR_DATA_PRESERVED;
LL_ADC_REG_Init(ADC1, &ADC_REG_InitStruct);
LL_ADC_DisableIT_EOC(ADC1);
LL_ADC_DisableIT_EOS(ADC1);
LL_ADC_DisableDeepPowerDown(ADC1);
LL_ADC_EnableInternalRegulator(ADC1);
//端口和通道初始化
LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_6, LL_ADC_SINGLE_ENDED);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
GPIO_InitStruct.Pin =LL_GPIO_PIN_0|LL_GPIO_PIN_1|LL_GPIO_PIN_2;
GPIO_InitStruct.Mode =LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
LL_GPIO_EnablePinAnalogControl(GPIOA,LL_GPIO_PIN_0);
LL_GPIO_EnablePinAnalogControl(GPIOA,LL_GPIO_PIN_1);
LL_GPIO_EnablePinAnalogControl(GPIOA,LL_GPIO_PIN_2);
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_1, LL_ADC_CHANNEL_5);
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_5, LL_ADC_SAMPLINGTIME_2CYCLES_5); //转换时间修改后无法采集到数据
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_2, LL_ADC_CHANNEL_6);
LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_6, LL_ADC_SAMPLINGTIME_2CYCLES_5); //转换时间修改后无法采集到数据
LL_ADC_REG_SetSequencerRanks(ADC1, LL_ADC_REG_RANK_3, LL_ADC_CHANNEL_7);
LL_ADC_StartCalibration(ADC1,LL_ADC_SINGLE_ENDED); //校准
while (LL_ADC_IsCalibrationOnGoing(ADC1)); //等待校准完成
//DMA
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
LL_DMA_SetPeriphAddress(DMA1,LL_DMA_CHANNEL_1,(u32)&ADC1->DR);
LL_DMA_SetMemoryAddress(DMA1,LL_DMA_CHANNEL_1,(u32)AdcBuffer);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
LL_DMA_SetDataLength(DMA1,LL_DMA_CHANNEL_1,3*ADC_BufSize); //设定接收长度
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_HALFWORD);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_HALFWORD);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMA_REQUEST_0);
LL_DMA_EnableChannel(DMA1,LL_DMA_CHANNEL_1);
LL_ADC_Enable(ADC1);
LL_ADC_REG_StartConversion(ADC1);
|
|