我定义了个uint32_t ADC_Value_arr[4]={0,0,0,0};接收四个通道的ADC,单通道+DMA读取数据没有问题,多通道读取是只有ADC_Value_arr[0]有数据,并且数据特别大,达到8位,还不断变化,显然错了,不知道是何原因,实在发现不了错在哪里?贴上代码,希望有人能指出错误,非常感谢!!! void HAL_ADC_MspInit(ADC_HandleTypeDef *hadc) { GPIO_InitTypeDef GPIO_InitStruct; static DMA_HandleTypeDef hdma_adc; /*##-1- Enable peripherals and GPIO Clocks #################################*/ /* Enable GPIO clock */ ADCx_CHANNEL_GPIO_CLK_ENABLE(); /* ADC1 Periph clock enable */ ADCx_CLK_ENABLE(); /* Enable DMA2 clock */ DMAx_CLK_ENABLE(); /*##-2- Configure peripheral GPIO ##########################################*/ /* ADC1 Channel2,3,6,7 GPIO pin configuration */ GPIO_InitStruct.Pin = ADCx_CHANNEL_PIN2|ADCx_CHANNEL_PIN3|ADCx_CHANNEL_PIN6|ADCx_CHANNEL_PIN7; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(ADCx_CHANNEL_GPIO_PORT, &GPIO_InitStruct); /*##-3- Configure the DMA streams ##########################################*/ /* Set the parameters to be configured */ hdma_adc.Instance = ADCx_DMA_STREAM; //选择stream0 hdma_adc.Init.Channel = ADCx_DMA_CHANNEL;//通道0 hdma_adc.Init.Direction = DMA_PERIPH_TO_MEMORY;//ÍâÉèµÀÄÚ´æ hdma_adc.Init.PeriphInc = DMA_PINC_DISABLE;//ÍâÉè²»Ôö hdma_adc.Init.MemInc = DMA_MINC_ENABLE;//内存增 hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; // hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc.Init.Mode = DMA_CIRCULAR; //循环模式 hdma_adc.Init.Priority = DMA_PRIORITY_HIGH; hdma_adc.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_adc.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_HALFFULL; hdma_adc.Init.MemBurst = DMA_MBURST_SINGLE; hdma_adc.Init.PeriphBurst = DMA_PBURST_SINGLE; HAL_DMA_Init(&hdma_adc); /* Associate the initialized DMA handle to the the ADC handle */ __HAL_LINKDMA(hadc, DMA_Handle, hdma_adc); /*##-4- Configure the NVIC for DMA #########################################*/ /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(ADCx_DMA_IRQn, 5, 0); HAL_NVIC_EnableIRQ(ADCx_DMA_IRQn); } void set_ADC(void) { ADC_ChannelConfTypeDef sConfig; /* Configure the ADC peripheral */ AdcHandle.Instance = ADCx;//ADC1 AdcHandle.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;//21MHZ AdcHandle.Init.Resolution = ADC_RESOLUTION12b; //12位 //AdcHandle.Init.ScanConvMode = DISABLE; AdcHandle.Init.ScanConvMode = ENABLE;//扫描模式 AdcHandle.Init.ContinuousConvMode = ENABLE;//连续模式 AdcHandle.Init.DiscontinuousConvMode = DISABLE;// AdcHandle.Init.NbrOfDiscConversion = 0; AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; AdcHandle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1; AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT; AdcHandle.Init.NbrOfConversion = 4; AdcHandle.Init.DMAContinuousRequests = ENABLE; AdcHandle.Init.EOCSelection = DISABLE; HAL_ADC_Init(&AdcHandle); /* Configure ADC regular channel */ sConfig.Channel = ADCx_CHANNEL2; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); sConfig.Channel = ADCx_CHANNEL3; sConfig.Rank = 2; sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); sConfig.Channel = ADCx_CHANNEL6; sConfig.Rank = 3; sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); sConfig.Channel = ADCx_CHANNEL7; sConfig.Rank = 4; sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES; sConfig.Offset = 0; HAL_ADC_ConfigChannel(&AdcHandle, &sConfig); /* Start the conversion process and enable interrupt */ // HAL_ADC_Start_DMA(&AdcHandle, (uint32_t*)&ADCConvertedValue, 1); HAL_ADC_Start_DMA(&AdcHandle, ADC_Value_arr, 4); } |
盘古UE-STM32F407工控板原理图
STM32F407 定时器触发DMA 求助大神
【MCU实战经验】基于STM32F407的音频播放器设计
【STM32F429心得\疑问】+STM32F4之FSMC和FMC
STM32F429读取IO口传输的数据速率
STM32F407ZGT6 手摸芯片背部重启
STM32F4 SPI 动作时,软件片选信号被拉高,IO口程序逻辑失控
STM32F401RE NUCLEO求助,串口一直不能进中断
读取STM32F407内部温度传感器值错误
STM32F429多路内部ADC独立采集的办法
hdma_adc.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; //
hdma_adc.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD
感觉应该定义为WORD的,因为HAL_ADC_Start_DMA(&AdcHandle, ADC_Value_arr, 4);中,ADC_Value_arr是uint32
按你说的我改了,就没问题了,准确度太差了……非常感谢
你是说可以采集多路了?能把工程发来看看吗
AdcHandle.Init.ScanConvMode = ENABLE;//扫描模式
请改为
AdcHandle.Init.ScanConvMode = ADC_SCAN_ENABLE;//扫描模式
F1这个库有BUG