打印
[其他ST产品]

STM32 双ADC同步注入转换模式,模块ADC2没有数据。

[复制链接]
94|6
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jcky001|  楼主 | 2025-1-9 11:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我使用的是stm32g431这款芯片,现在想采样两路模拟信号,为了采样速度更快,想用adc1和adc2两个模块分别对这两路进行采样。使用ADC_DUALMODE_INJECSIMULT(双AD同步注入模式),CUBE配置如下所示,使用定时器更新事件触发ADC注入转换。
ADC1模块配置:
ADC2模块配置(ADC1配置了同步触发,此时ADC2配置页面中无触发源选项配置,其他与ADC1保持不变)
在CUBE生成的初始化代码后添加一些ADC启动代码:
问题出现:
只有ADC1的注入通道有数据,ADC2的注入通道无数据。
想问一下这个是什么情况呢?我试过两个ADC模块都使用独立模式(ADC_MODE_INDEPENDENT),触发源与模块ADC1一致,这样是有数据的。如下:
修改的代码如下:











[color=var(--default-a-next-color)][url=] 赞[/url][color=var(--default-a-next-color)][url=] 收藏[/url][color=var(--default-a-next-color)][url=] 评论4[/url][color=var(--default-a-next-color)]分享







请先[color=var(--default-a-hover-color)][url=]登录[/url]后回复
[color=var(--default-a-color)]4个回答
[color=var(--default-a-next-color)]lzylzy1212
[color=var(--default-a-next-color)]回答时间:前天 15:04

使用上述配置的双ADC模式同步注入转换,CUBE生成的代码如下:(ADC2无数据)
/* ADC1 init function */void MX_ADC1_Init(void){  /* USER CODE BEGIN ADC1_Init 0 */  /* USER CODE END ADC1_Init 0 */  ADC_MultiModeTypeDef multimode = {0};  ADC_InjectionConfTypeDef sConfigInjected = {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.DataAlign = ADC_DATAALIGN_RIGHT;  hadc1.Init.GainCompensation = 0;  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;  hadc1.Init.LowPowerAutoWait = DISABLE;  hadc1.Init.ContinuousConvMode = DISABLE;  hadc1.Init.NbrOfConversion = 1;  hadc1.Init.DiscontinuousConvMode = DISABLE;  hadc1.Init.DMAContinuousRequests = DISABLE;  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;  hadc1.Init.OversamplingMode = DISABLE;  if (HAL_ADC_Init(&hadc1) != HAL_OK)  {    Error_Handler();  }  /** Configure the ADC multi-mode  */  multimode.Mode = ADC_DUALMODE_INJECSIMULT;  multimode.DMAAccessMode = ADC_DMAACCESSMODE_DISABLED;  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)  {    Error_Handler();  }  //修改为独立模式//  multimode.Mode = ADC_MODE_INDEPENDENT;//  multimode.DMAAccessMode = ADC_DMAACCESSMODE_DISABLED;//  multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;//  if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)//  {//    Error_Handler();//  }   /** Configure Injected Channel  */  sConfigInjected.InjectedChannel = ADC_CHANNEL_1;  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;  sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_2CYCLES_5;  sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;  sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;  sConfigInjected.InjectedOffset = 0;  sConfigInjected.InjectedNbrOfConversion = 1;  sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;  sConfigInjected.AutoInjectedConv = DISABLE;  sConfigInjected.QueueInjectedContext = DISABLE;  sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJEC_T1_TRGO;  sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;  sConfigInjected.InjecOversamplingMode = DISABLE;  if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)  {    Error_Handler();  }  /* USER CODE BEGIN ADC1_Init 2 */  if(HAL_ADCEx_Calibration_Start(&hadc1,ADC_SINGLE_ENDED) != HAL_OK )//ADC模块的自校正(单端信号)  {    Error_Handler();  }  __HAL_ADC_ENABLE_IT(&hadc1,ADC_IT_JEOC);  HAL_ADCEx_InjectedStart(&hadc1);  /* USER CODE END ADC1_Init 2 */}/* ADC2 init function */void MX_ADC2_Init(void){  /* USER CODE BEGIN ADC2_Init 0 */  /* USER CODE END ADC2_Init 0 */  ADC_InjectionConfTypeDef sConfigInjected = {0};  /* USER CODE BEGIN ADC2_Init 1 */  /* USER CODE END ADC2_Init 1 */  /** Common config  */  hadc2.Instance = ADC2;  hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;  hadc2.Init.Resolution = ADC_RESOLUTION_12B;  hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;  hadc2.Init.GainCompensation = 0;  hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;  hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;  hadc2.Init.LowPowerAutoWait = DISABLE;  hadc2.Init.ContinuousConvMode = DISABLE;  hadc2.Init.NbrOfConversion = 1;  hadc2.Init.DiscontinuousConvMode = DISABLE;  hadc2.Init.DMAContinuousRequests = DISABLE;  hadc2.Init.Overrun = ADC_OVR_DATA_PRESERVED;  hadc2.Init.OversamplingMode = DISABLE;  if (HAL_ADC_Init(&hadc2) != HAL_OK)  {    Error_Handler();  }  /** Configure Injected Channel  */  sConfigInjected.InjectedChannel = ADC_CHANNEL_2;  sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;  sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_2CYCLES_5;  sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;  sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;  sConfigInjected.InjectedOffset = 0;  sConfigInjected.InjectedNbrOfConversion = 1;  sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;  sConfigInjected.AutoInjectedConv = DISABLE;  sConfigInjected.QueueInjectedContext = DISABLE;  //修改成独立模式后,手动添加以下2行触发源配置代码。//  sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJEC_T1_TRGO;//  sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;    sConfigInjected.InjecOversamplingMode = DISABLE;  if (HAL_ADCEx_InjectedConfigChannel(&hadc2, &sConfigInjected) != HAL_OK)  {    Error_Handler();  }  /* USER CODE BEGIN ADC2_Init 2 */  if(HAL_ADCEx_Calibration_Start(&hadc2,ADC_SINGLE_ENDED) != HAL_OK )  {    Error_Handler();  }  HAL_ADCEx_InjectedStart(&hadc2);  /* USER CODE END ADC2_Init 2 */}








使用特权

评论回复
沙发
stormwind123| | 2025-1-9 12:49 | 只看该作者
ADC2的配置可能不正确

使用特权

评论回复
板凳
classroom| | 2025-1-9 12:52 | 只看该作者
更新软件或固件

使用特权

评论回复
地板
laocuo1142| | 2025-1-9 14:00 | 只看该作者
如果触发源设置不正确,可能导致ADC2无法被正确触发进行转换。

使用特权

评论回复
5
flycamelaaa| | 2025-1-9 19:00 | 只看该作者
估计DMA配置不正确

使用特权

评论回复
6
powerantone| | 2025-1-9 20:00 | 只看该作者
检查ADC2的硬件连接是否正确,包括电源、地、信号线等。

使用特权

评论回复
7
stormwind123| | 2025-1-9 22:00 | 只看该作者
软件中的错误或bug可能导致ADC2的数据处理出现问题。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1531

主题

4683

帖子

6

粉丝