2022-11-04 01:31 AM
Hello,
I'm facing issues withering the "Dual regular simultaneous mode" on STM32F103C8T.
Basically a timer shall trigger both ADC to convert (for each ADC) 5 channels.
What I've observed is that samples from ADC1 are ok, but samples from ADC2 have wrong position into the buffer. Can you please help me understanding if my configuration si correct or not?
#define MAX_ADC_CHANNELS 10
#define ADC1_RESULT(DATA) \
((DATA) & 0x0000FFFF)
#define ADC2_RESULT(DATA) \
((DATA) >> 16)
uint32_t ADCfromDMA[MAX_ADC_CHANNELS/2] = {0x00000000};
void ADCInit(uint8_t id, char* task_name)
{
HAL_ADCEx_Calibration_Start(&hadc1);
HAL_ADCEx_Calibration_Start(&hadc2);
HAL_TIM_Base_Start(&htim3);
HAL_ADC_Start(&hadc2);
HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t *)ADCfromDMA, MAX_ADC_CHANNELS/2);
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *AdcHandle)
{
/*Read adc values upper & lower from DMA*/
ADCRawData[0] = ADC1_RESULT(ADCfromDMA[0]); //ok
ADCRawData[1] = ADC2_RESULT(ADCfromDMA[0]); //ok
ADCRawData[2] = ADC1_RESULT(ADCfromDMA[1]); //ok
ADCRawData[3] = ADC2_RESULT(ADCfromDMA[1]); //ok
ADCRawData[4] = ADC1_RESULT(ADCfromDMA[2]); //
ADCRawData[5] = ADC2_RESULT(ADCfromDMA[2]); //
ADCRawData[6] = ADC1_RESULT(ADCfromDMA[3]); //
ADCRawData[7] = ADC2_RESULT(ADCfromDMA[3]); //
ADCRawData[8] = ADC1_RESULT(ADCfromDMA[4]); //
ADCRawData[9] = ADC2_RESULT(ADCfromDMA[4]); //
}
2022-11-04 01:47 AM
a similar thing happened to me.
I wasnt giving the DMA enough time to fill the buffer.
Are you using HAL_ADCEx_MultiModeStop_DMA()?
2022-11-04 01:52 AM
That sounds interesting. No I'm not using any Stop function. Have you any example?
2022-11-04 05:18 AM
i dont have any example on hand but you should be able to debug it yourself.
Is the DMA in circular mode?
Also triplecheck the size of the variables DMA expects matches the one you are using
2022-11-04 05:20 AM
Yes, now is working in circular mode. Actually I have not completely understand how callbacks works for the DMA. Like Half and Complete. Any hint?
2022-11-07 12:48 AM
even ifthe buffer is treated as circular, it has beginning and end.
When the DMA reaches the ened of the buffer it will trigger transaction Complete Calback.
When the DMA reaches mid point of the buffer it will trigger transaction Half way Callback.
Both are usefull just for your core to work more in sync with DMA, doing time critical stuff.
2022-11-07 12:58 AM
That's good. But if the buffer is composed of 5 elements? When the Half callback is called?
2022-11-08 03:03 AM
good question, i have no clue
2023-01-18 09:49 PM
:) best way to find out is to try it ! Did you do that ?
2023-06-05 09:59 PM
Hi, I need help with the ioc settings and I didn't understand the first two defines. Can you please help me with this?