完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用ADC进行多通道采样,通道2,5采样正确,通道10,11,15采样同样的信号老是不对。这是什么原因啊
IO初始化如下 void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc){GPIO_InitTypeDef GPIO_InitStruct = {0};if(hadc- gt;Instance==ADC1){/* USER CODE BEGIN ADC1_MspInit 0 *//* USER CODE END ADC1_MspInit 0 *//* Peripheral clock enable */__HAL_RCC_ADC1_CLK_ENABLE();__HAL_RCC_GPIOC_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();__HAL_RCC_GPIOB_CLK_ENABLE();/**ADC1 GPIO ConfigurationPC0 ------ gt; ADC1_IN6PC1 ------ gt; ADC1_IN7PC2 ------ gt; ADC1_IN8PC3 ------ gt; ADC1_IN9PA1 ------ gt; ADC1_IN2PA2 ------ gt; ADC1_IN3PA3 ------ gt; ADC1_IN4PA4 ------ gt; ADC1_IN5PA6 ------ gt; ADC1_IN10PA7 ------ gt; ADC1_IN15PB0 ------ gt; ADC1_IN11*/GPIO_InitStruct.Pin = ADC1_IN6_BDC1_Pin|ADC1_IN7_BDC2_Pin|ADC1_IN8_BDC3_Pin|ADC1_IN9_TEMP_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(GPIOC, amp;GPIO_InitStruct);GPIO_InitStruct.Pin = ADC1_IN2_VBUS_Pin|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4 |GPIO_PIN_6|BLDC_BK_CMP_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(GPIOA, amp;GPIO_InitStruct);GPIO_InitStruct.Pin = ADC1_IN11_CURR_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(ADC1_IN11_CURR_GPIO_Port, amp;GPIO_InitStruct);/* ADC1 DMA Init *//* ADC1 Init */hdma_adc1.Instance = DMA1_Channel1;hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;hdma_adc1.Init.Mode = DMA_CIRCULAR;hdma_adc1.Init.Priority = DMA_PRIORITY_VERY_HIGH;if (HAL_DMA_Init( amp;hdma_adc1) != HAL_OK){ Error_Handler();}__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);/* ADC1 interrupt Init */HAL_NVIC_SetPriority(ADC1_IRQn, 0, 0);HAL_NVIC_EnableIRQ(ADC1_IRQn);__HAL_RCC_GPIOC_CLK_ENABLE();__HAL_RCC_GPIOA_CLK_ENABLE();__HAL_RCC_GPIOB_CLK_ENABLE();/**ADC1 GPIO ConfigurationPC0 ------ gt; ADC1_IN6PC1 ------ gt; ADC1_IN7PC2 ------ gt; ADC1_IN8PC3 ------ gt; ADC1_IN9PA1 ------ gt; ADC1_IN2PA2 ------ gt; ADC1_IN3PA3 ------ gt; ADC1_IN4PA4 ------ gt; ADC1_IN5PA6 ------ gt; ADC1_IN10PA7 ------ gt; ADC1_IN15PB0 ------ gt; ADC1_IN11*/GPIO_InitStruct.Pin = ADC1_IN6_BDC1_Pin|ADC1_IN7_BDC2_Pin|ADC1_IN8_BDC3_Pin|ADC1_IN9_TEMP_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(GPIOC, amp;GPIO_InitStruct);GPIO_InitStruct.Pin = ADC1_IN2_VBUS_Pin|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4 |GPIO_PIN_6|BLDC_BK_CMP_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(GPIOA, amp;GPIO_InitStruct);GPIO_InitStruct.Pin = ADC1_IN11_CURR_Pin;GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;GPIO_InitStruct.Pull = GPIO_NOPULL;HAL_GPIO_Init(ADC1_IN11_CURR_GPIO_Port, amp;GPIO_InitStruct);/* ADC1 DMA Init *//* ADC1 Init */hdma_adc1.Instance = DMA1_Channel1;hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;hdma_adc1.Init.Mode = DMA_CIRCULAR;hdma_adc1.Init.Priority = DMA_PRIORITY_VERY_HIGH;if (HAL_DMA_Init( amp;hdma_adc1) != HAL_OK){ Error_Handler();}__HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1);/* ADC1 interrupt Init */HAL_NVIC_SetPriority(ADC1_IRQn, 0, 0);HAL_NVIC_EnableIRQ(ADC1_IRQn);/* USER CODE BEGIN ADC1_MspInit 1 *//* USER CODE END ADC1_MspInit 1 */}}ADC配置如下 {/* USER CODE BEGIN ADC1_Init 0 *//* USER CODE END ADC1_Init 0 */ADC_ChannelConfTypeDef sConfig = {0};/* USER CODE BEGIN ADC1_Init 1 *//* USER CODE END ADC1_Init 1 *//** Common config*/hadc1.Instance = ADC1;hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;hadc1.Init.Resolution = ADC_RESOLUTION_12B;hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;hadc1.Init.ContinuousConvMode = ENABLE;hadc1.Init.DiscontinuousConvMode = DISABLE;hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;hadc1.Init.NbrOfConversion = 10;hadc1.Init.DMAContinuousRequests = ENABLE;hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;hadc1.Init.LowPowerAutoWait = DISABLE;hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;if (HAL_ADC_Init( amp;hadc1) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_6;sConfig.Rank = ADC_REGULAR_RANK_1;sConfig.SingleDiff = ADC_SINGLE_ENDED;sConfig.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;sConfig.OffsetNumber = ADC_OFFSET_NONE;sConfig.Offset = 0;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_7;sConfig.Rank = ADC_REGULAR_RANK_2;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_8;sConfig.Rank = ADC_REGULAR_RANK_3;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_2;sConfig.Rank = ADC_REGULAR_RANK_4;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_10;sConfig.Rank = ADC_REGULAR_RANK_5;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_11;sConfig.Rank = ADC_REGULAR_RANK_6;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_15;sConfig.Rank = ADC_REGULAR_RANK_7;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_3;sConfig.Rank = ADC_REGULAR_RANK_8;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_4;sConfig.Rank = ADC_REGULAR_RANK_9;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/** Configure Regular Channel*/sConfig.Channel = ADC_CHANNEL_5;sConfig.Rank = ADC_REGULAR_RANK_10;if (HAL_ADC_ConfigChannel( amp;hadc1, amp;sConfig) != HAL_OK){Error_Handler();}/* USER CODE BEGIN ADC1_Init 2 *//* USER CODE END ADC1_Init 2 */} |
|
相关推荐
1个回答
|
|
hadc1.Init.NbrOfConversion = 10;看一下这里,我看你配置的是要采集11个AD值,这里写的是10个。
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1627 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1550 浏览 1 评论
984 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
688 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1601 浏览 2 评论
1867浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
650浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
518浏览 3评论
536浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
506浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 14:41 , Processed in 0.760475 second(s), Total 82, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号