2021-09-05 06:56 AM
I'm trying to get ADC values from multiple channels of ADC1 of STM32F103C8T6 using DMA where conversion is triggered by TIM3 every 1ms. However, I'm not seeing the right values. I tried the polling mode and that worked fine. Here is the main function code so far and the settings in CubeMX. The full code is here. What am I missing?
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_SPI1_Init();
MX_TIM1_Init();
MX_I2C1_Init();
MX_USART1_UART_Init();
MX_DMA_Init();
MX_TIM2_Init();
MX_TIM3_Init();
/* USER CODE BEGIN 2 */
HAL_ADC_Start_DMA(&hadc1, (uint32_t*) adc1_values, 2);
HAL_TIM_Base_Start(&htim3);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
Solved! Go to Solution.
2021-09-05 01:45 PM
> MX_ADC1_Init();
> MX_DMA_Init();
You need to initialize DMA before the peripherals that use it. Sometimes CubeMX gets this correct, sometimes not.
No doubt if you check your newer working project, the order of initialization has changed.
2021-09-05 09:44 AM
I started a new project (through CubeIDE instead of the external CubeMX application) starting with just the ADC. That worked. I then kept enabling more and more peripherals and kept testing if they all work. Now it all works fine. Very strange!!
2021-09-05 01:45 PM
> MX_ADC1_Init();
> MX_DMA_Init();
You need to initialize DMA before the peripherals that use it. Sometimes CubeMX gets this correct, sometimes not.
No doubt if you check your newer working project, the order of initialization has changed.
2021-09-05 08:42 PM
Thank you. I didn't know this. Yes the new code has the correct init sequence. Is this a bug then?
2021-09-05 08:51 PM