2015-07-21 05:44 AM
Hello all,
I am writing an application on a STM32F4 which reads from two sensors. I do it with two ADC3 channels with DMA. I use HAL_DRIVERSI write on a buffer several readings from three sensors by calling:HAL_ADC_Start(&hadc3);HAL_ADC_Start_DMA(&hadc3, (uint32_t*)ADC1ConvertedValues, 18);In ''void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)''I call: HAL_ADC_Stop_DMA(&hadc3);and then HAL_ADC_Start_DMA(&hadc3, (uint32_t*)ADC1ConvertedValues, 18);when I need another sensor reading.The problem is that ADC1ConvertedValues[] has always the same information (only the first readings are ok). The others make no effect in ADC1ConvertedValues[].Any idea why?Many thanks in advance.Some code of important functions:void MX_ADC3_Init(void){ ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc3.Instance = ADC3; hadc3.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2; hadc3.Init.Resolution = ADC_RESOLUTION12b; hadc3.Init.ScanConvMode = ENABLE; hadc3.Init.ContinuousConvMode = ENABLE; hadc3.Init.DiscontinuousConvMode = DISABLE; hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc3.Init.NbrOfConversion = 3; hadc3.Init.DMAContinuousRequests = DISABLE; hadc3.Init.EOCSelection = EOC_SINGLE_CONV; HAL_ADC_Init(&hadc3); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_9; sConfig.Rank = 1; sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; HAL_ADC_ConfigChannel(&hadc3, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_14; sConfig.Rank = 2; HAL_ADC_ConfigChannel(&hadc3, &sConfig); /**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time. */ sConfig.Channel = ADC_CHANNEL_15; sConfig.Rank = 3; HAL_ADC_ConfigChannel(&hadc3, &sConfig);}void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc){ GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC3) { /* USER CODE BEGIN ADC3_MspInit 0 */ /* USER CODE END ADC3_MspInit 0 */ /* Peripheral clock enable */ __ADC3_CLK_ENABLE(); /**ADC3 GPIO Configuration PF3 ------> ADC3_IN9 PF4 ------> ADC3_IN14 PF5 ------> ADC3_IN15 */ GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOF, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc3.Instance = DMA2_Stream0; hdma_adc3.Init.Channel = DMA_CHANNEL_2; hdma_adc3.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc3.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc3.Init.MemInc = DMA_MINC_ENABLE; hdma_adc3.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_adc3.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc3.Init.Mode = DMA_CIRCULAR; hdma_adc3.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_adc3.Init.FIFOMode = DMA_FIFOMODE_DISABLE; HAL_DMA_Init(&hdma_adc3); __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc3); /* USER CODE BEGIN ADC3_MspInit 1 */ /* USER CODE END ADC3_MspInit 1 */ }} #stm32f4 #adc #dma2015-07-22 12:00 AM
Hello,
The problem is that after HAL_ADC_Stop_DMA is executed invoid HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc){ HAL_ADC_Stop_DMA(&hadc3);}next calls to HAL_ADC_Start_DMA(&hadc3, (uint32_t*)ADC1ConvertedValues, 18);do not fire the ADC/DMA work so that the interrupt HAL_ADC_ConvCpltCallback is never called again.Any idea why ?Best Regards,Jorge