cancel
Showing results for 
Search instead for 
Did you mean: 

STM32h7 Multichannel ADC DMA is not working.

MDeva.1
Associate II

Hi,

I am try to read four ADC Channels of ADC3 using DMA method. But I did not get the data.

Below is my programming

static void MX_ADC3_Init(void)

{

 ADC_ChannelConfTypeDef sConfig = {0};

 hadc3.Instance = ADC3;

 hadc3.Init.Resolution = ADC_RESOLUTION_16B;

 hadc3.Init.ScanConvMode = ADC_SCAN_ENABLE;

 hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc3.Init.LowPowerAutoWait = DISABLE;

 hadc3.Init.ContinuousConvMode = ENABLE;

 hadc3.Init.NbrOfConversion = 4;

 hadc3.Init.DiscontinuousConvMode = DISABLE;

 hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;

 hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;

 hadc3.Init.OversamplingMode = DISABLE;

 if (HAL_ADC_Init(&hadc3) != HAL_OK)

 {

  Error_Handler();

 }

 sConfig.Channel = ADC_CHANNEL_0;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_810CYCLES_5;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

 sConfig.OffsetSignedSaturation = DISABLE;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfig.Channel = ADC_CHANNEL_1;

 sConfig.Rank = ADC_REGULAR_RANK_2;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfig.Channel = ADC_CHANNEL_14;

 sConfig.Rank = ADC_REGULAR_RANK_3;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sConfig.Channel = ADC_CHANNEL_15;

 sConfig.Rank = ADC_REGULAR_RANK_4;

 if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 }

#define SIZE 3

uint16_t ADC_INT[SIZE];

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hadc)

{

 if(hadc3.Instance == ADC3)

INTADC=1;

}

SCB_InvalidateDCache_by_Addr((uint32_t*)(((uint32_t)ADC_INT) & ~(uint32_t)0x1F), SIZE+32);

  HAL_ADC_Start_DMA(&hadc3,(uint32_t*)ADC_INT, SIZE);

while(1)

if(INTADC==1)

{

float OUTPUT1=0,OUTPUT2=0,OUTPUT3=0,OUTPUT5=0;

printf("IN ADC");

for(int i=0;i<=3;i++)

{

printf("ADC_INP[i]=%d\n\r",ADC_INT[i]);

}

ADC1_val=ADC_INT[0];

ADC2_val=ADC_INT[1];

ADC3_val=ADC_INT[2];

ADC5_val=ADC_INT[3];

ADC1_val=ADC1_val >> 2;

OUTPUT1=(3.3/4095)*ADC1_val;

printf("ADC1=%f\n\r",OUTPUT1);

ADC2_val=ADC2_val >> 2;

OUTPUT2=(3.3/4095)*ADC2_val;

printf("ADC2=%f\n\r",OUTPUT2);

ADC3_val=ADC3_val >> 2;

OUTPUT3=(3.3/4095)*ADC3_val;

printf("ADC3=%f\n\r",OUTPUT3);

ADC5_val=ADC5_val >> 2;

OUTPUT5=(3.3/4095)*ADC5_val;

printf("ADC5=%f\n\r",OUTPUT5);

}

When I call the SCB_Invalidate function before or after start ADC DMA the program gets stuck. I enable the DCACHE and ICACHE why programmed is get stuck. My ADC is 16bit.

3 REPLIES 3
Aymen ABBES
ST Employee

Hello @MDeva.1​  ,

First of all let me thank you for posting.

Could you please provide the MCU you are using, the project you are working on or your *.ioc file and the CubeMx and CubeIDE version so I be able to investigate the issue.

Kind regards,

Aymen

I am sharing the cubemx file

Main.c File