cancel
Showing results for 
Search instead for 
Did you mean: 

Reading from CDR only provides values for ADC1 and not ADC2 in Dual Regular Simultaneous Mode

kl4971tse
Associate II
Posted on November 23, 2016 at 01:25

Hello All!

I am currently trying to sample from 2 ADCs in dual regular simultaneous mode using the STM What's appears to be happening is that only the ADC1 values are being saved in to the memory location (ADC1ConvertedValues) and none of the ADC2 values. I confirmed this by using a function generator at 1 Hz and 2V on ADC1 which produced the right output for ADC1, but no related 0 values for ADC2. However, when I input a sine wave on the ADC2 pin, a subtle response is measured in ADC1 and an incorrect response for ADC2. When I read over the HAL_ADCEx_MultiModeStart_DMA function and it should be using the DMA to send the values in the CDR into the ADC1ConvertedValues where the first 16 bits should be ADC1 while the lower 16 bits should be ADC2. Due to the tests, I'm suspecting that there's cross talk between the ADC1 and ADC2 pins, and only the ADC1 values are properly being read. I'm working on the STM32F303K8 with ADC1 on PA0 and ADC2 on PA4. Would anyone have any thoughts where I have gone wrong? Thank you for your help!

//Initialize
if(HAL_ADC_Start(&hadc2) != HAL_OK)
return 0; 
if(HAL_ADCEx_MultiModeStart_DMA(&hadc1, ADC1ConvertedValues, 4096) != HAL_OK)
return 0;
/* ADC1 init function */
static void MX_ADC1_Init(void)
{
ADC_MultiModeTypeDef multimode;
ADC_ChannelConfTypeDef sConfig;
/**Common config 
*/
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = ENABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc1.Init.LowPowerAutoWait = DISABLE;
hadc1.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
/**Configure the ADC multi-mode 
*/
multimode.Mode = ADC_DUALMODE_REGSIMULT;
multimode.DMAAccessMode = ADC_DMAACCESSMODE_12_10_BITS;
multimode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_1CYCLE;
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK)
{
Error_Handler();
}
/**Configure Regular Channel 
*/
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}
/* ADC2 init function */
static void MX_ADC2_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
/**Common config 
*/
hadc2.Instance = ADC2;
hadc2.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
hadc2.Init.Resolution = ADC_RESOLUTION_12B;
hadc2.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc2.Init.ContinuousConvMode = ENABLE;
hadc2.Init.DiscontinuousConvMode = DISABLE;
hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc2.Init.NbrOfConversion = 1;
hadc2.Init.DMAContinuousRequests = ENABLE;
hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc2.Init.LowPowerAutoWait = DISABLE;
hadc2.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
if (HAL_ADC_Init(&hadc2) != HAL_OK)
{
Error_Handler();
}
/**Configure Regular Channel 
*/
sConfig.Channel = ADC_CHANNEL_2;
sConfig.Rank = 1;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
{
Error_Handler();
}
}

1 REPLY 1
kl4971tse
Associate II
Posted on November 27, 2016 at 01:38

Simple mistake: the increment in the DMA was set at half word instead of word therefore all the slave values were being overwritten. This isn't automatically set within the cube when regular simultaneous mode is chosen.