STM32F1 ADC Dual regular simultaneous mode only, wrong position of ADC2 samples with DMA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-04 1: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]); //
}
- Labels:
-
ADC
-
DMA
-
STM32F1 Series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-04 1: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()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-04 1:52 AM
That sounds interesting. No I'm not using any Stop function. Have you any example?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-04 5: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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-04 5: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-07 12:58 AM
That's good. But if the buffer is composed of 5 elements? When the Half callback is called?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-11-08 3:03 AM
good question, i have no clue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-01-18 9:49 PM
:) best way to find out is to try it ! Did you do that ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2023-06-05 9: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?
