STM32F407 ADC Issue
Hello all,
I'm using STM32F407 ADC1 with DMA enabled for sampling on 4 channels at same time, the configuration for these 4 channels are all same with DIV4 clock and 12Bit Resolution, but only 3 of them are working fine, and one channel always returns 4095 to sample the square 60HZ waveform, occasionally it returns some small number 0 ~ 10.
Here is the code for ADC1 configuration:
ADC_ChannelConfTypeDef sConfig = {0};
/** 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_DIV4;
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 = ADC1_CHANNEL_NUM;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK) {
LOGE("Failed to call HAL_ADC_Init hadc1");
return -1;
}
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_4;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
LOGE("Failed to call HAL_ADC_ConfigChannel hadc1");
return -1;
}
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_6;
sConfig.Rank = 2;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
LOGE("Failed to call HAL_ADC_ConfigChannel hadc1");
return -1;
}
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = 3;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
LOGE("Failed to call HAL_ADC_ConfigChannel hadc1");
return -1;
}
/** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
*/
sConfig.Channel = ADC_CHANNEL_9;
sConfig.Rank = 4;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
LOGE("Failed to call HAL_ADC_ConfigChannel hadc1");
return -1;
}
The failed channel is CHANNEL_6. Could anyone give me some clue about some errors in the code?
Just FYI, the system Clock is set to 160MHZ, and PCLK2 is 80MHZ.
Any feedback will be appreciated.