cancel
Showing results for 
Search instead for 
Did you mean: 

Multichannel ADC using DMA not working on STM32F429ZI-Disco1

MFaro
Associate
static void MX_ADC1_Init(void)
{
 
  /* USER CODE BEGIN ADC1_Init 0 */
 
  /* USER CODE END ADC1_Init 0 */
 
  ADC_ChannelConfTypeDef sConfig;
 
  /* USER CODE BEGIN ADC1_Init 1 */
 
  /* USER CODE END ADC1_Init 1 */
  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) 
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.ScanConvMode = 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 = 3;
  hadc1.Init.DMAContinuousRequests = ENABLE;
  hadc1.Init.EOCSelection = DISABLE;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = 1;
  sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. 
  */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = 2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  */
  sConfig.Channel = ADC_CHANNEL_2;
  sConfig.Rank = 3;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */
 
  /* USER CODE END ADC1_Init 2 */
 
}
 
int main(void)
{
 
  HAL_Init();
 
 
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_DMA2D_Init();
  MX_FMC_Init();
  MX_GFXSIMULATOR_Init();
  MX_I2C3_Init();
  MX_SPI5_Init();
  MX_TIM1_Init();
  MX_USART1_UART_Init();
  MX_ADC1_Init();
  MX_CRC_Init();
 
 
 // osKernelStart();
 
 
 
 
  HAL_ADC_Start_DMA(&hadc1, (uint32_t *) ADC_Data,3);
 
  while (1)
  {
 
 
	  sprintf(tx_data, "%d", ADC_Data[0]);
	  sprintf(tx_data_2, "%d", ADC_Data[1]);
	 sprintf(tx_data_3, "%d", ADC_Data[2]);
	
	  HAL_UART_Transmit(&huart1,(uint8_t*)(&tx_data), 13,10);
	 HAL_UART_Transmit(&huart1,(uint8_t*)(&tx_data_2), 13,10);
	  HAL_UART_Transmit(&huart1,(uint8_t*)(&tx_data_3), 13,10);
	  HAL_Delay(500);
	 
 
 
 
 
	  }
 
 
}
 

Hi Guys,

I am trying to use Multi-Channel ADC using DMA using STM32F429ZI-DISCO1. What I am doing in above code is to get data from Channel 0,1,2 and send that to UART where I can see the ADC value. But I am only getting data from Channel 0. None of other channels are working. I have tried many approaches suggested on youtube lectures but couldn't solve the problem.

Regards

0 REPLIES 0