ST意法半导体
直播中

高桂清

7年用户 994经验值
私信 关注
[问答]

使用STM32L011F4读取2通道ADC没有问题吧

我正在尝试使用 STM32L011F4 读取 2 通道 ADC。
我在cubemx中的ADC和DMA设置如下
我的问题是 DMA 只返回最后一个通道的低 8 位。
  • uint16_t ADC_Reads[2] = {0};
  •         while (1)
  •         {
  •                 HAL_ADC_Start_DMA(&hadc,(uint32_t *)ADC_Reads,2);
  •                 HAL_Delay(1000);
  •         }
当我在 DMA IRQ 处理程序中编写以下代码时,我可以读取这些值。
  • uint16_t ADCReads[2];
  • char i=0;
  • void DMA1_Channel1_IRQHandler(void)
  • {
  •   /* USER CODE BEGIN DMA1_Channel1_IRQn 0 */
  • ADCReads = hadc.Instance->DR;
  •         i = 1-i;
  •   /* USER CODE END DMA1_Channel1_IRQn 0 */
  •   HAL_DMA_IRQHandler(&hdma_adc);
  •   /* USER CODE BEGIN DMA1_Channel1_IRQn 1 */
  •   /* USER CODE END DMA1_Channel1_IRQn 1 */
  • }

EWARM 实时观看屏幕如下所示




回帖(1)

尤两畅

2022-12-8 11:12:03
When DMA is used, the MX_DMA_Init shall always be called before any other HAL_***_Init (where *** is any peripheral with a HW dependency on DMA init code).

A regression was detected in the previous STM32CubeMX version 6.3.0 (STM32CubeIDE Version: 1.7.0 ) generating a wrong order of initialization functions.
This issue was fixed in the latest STM32CubeMX version 6.4.0. Thus, newly created project with this version will generate the correct initialization functions order.

Because the calling order is saved into the ioc file, the misplacement call to MX_DMA_Init() remains the same when trying to migrate automatically an old project from a buggy old version to the fixed version. The order stays the same and the generated code will be unfunctional.

For any old ioc file created by any STM32CubeMX version up to 6.3.0 included, hereafter some steps to overcome this misbehavior:
  • Open the saved .ioc file (already created with 6.3.0 version) with any text editor installed in your machine and delete the line: ProjectManager.functionlistsort=....
1.jpg
  • After saving the modification, re-open the .ioc file with latest CubeMX version 6.4.0 ( STM32CubeIDE Version: 1.8.0).
  • Through Project Manager view > Advanced Settings tab, make sure that the initialization functions are correctly ordered and re-generate your project:
2.jpg
举报

更多回帖

发帖
×
20
完善资料,
赚取积分