Skip to main content
Associate III
April 28, 2023
Question

STM32G030K6T6 ADC_DMA

  • April 28, 2023
  • 13 replies
  • 3966 views

Hi,

I'm trying to configure the ADC DMA with STM32G030K6T6. But Analog value is not came.

below I given my code and i don't know where i made a mistake if any one know help me.

void ADC_Config(void)
{
	RCC->APBENR2 |= RCC_APBENR2_ADCEN; // ADC clock enable
	RCC->AHBENR |= RCC_AHBENR_DMA1EN; // DMA1 clock enable
	
	ADC1->CR |= ADC_CR_ADEN; // ADC enable
	ADC1->CFGR2 |= (1<<30); // 01: PCLK/2 (Synchronous clock mode)
	ADC1->CFGR1 |= (ADC_CFGR1_CONT | ADC_CFGR1_DMAEN | ADC_CFGR1_CHSELRMOD | ADC_CFGR1_DMACFG); // 1: Continuous conversion mode & Direct memory access enable & Direct memory access configuration
	
	ADC1->SMPR |= ADC_SMPR_SMP1_1; // Sampling time selection 1 (010: 7.5 ADC clock cycles)
	ADC1->CHSELR |= (ADC_CHSELR_CHSEL0 | ADC_CHSELR_CHSEL1 | ADC_CHSELR_CHSEL2); // Channel-x selection (Channel-x selection)
	
	ADC1->CR |= ADC_CR_ADEN; // ADC enable
	
	DMA1_Channel1->CPAR = (uint32_t)&(ADC1->DR); // peripheral Address
	DMA1_Channel1->CMAR = (uint32_t)Aout; // Memory Address
	DMA1_Channel1->CNDTR = 3; // No Of Data
	DMA1_Channel1->CCR |= (DMA_CCR_MINC | DMA_CCR_MSIZE_0 | DMA_CCR_PSIZE_0| DMA_CCR_CIRC | DMA_CCR_TEIE | DMA_CCR_TCIE); // Msize,Psize,CIRC,MINC
	DMA1_Channel1->CCR |= DMA_CCR_EN; // DMA enable
	
	NVIC_EnableIRQ(DMA1_Channel1_IRQn);
	NVIC_SetPriority(DMA1_Channel1_IRQn,0);
	
	ADC1->CR |= ADC_CR_ADEN; // ADC enable
}

This topic has been closed for replies.

13 replies

Senior III
April 28, 2023

First you should configure whole DMA, then ADC​.

​On the other hand you duplicate adc enabling. Line 13 and the last one​

Dudo
Senior III
May 3, 2023

Did you resolve the issue?

@Sudhakar.R​ ​

Dudo
Associate III
May 4, 2023

@Kamil Duljas​ 

thank you for your comment. i tring but output is not came.

Senior III
May 4, 2023

Do you still resolve it?​

Dudo
Associate III
May 5, 2023

@Kamil Duljas​ 

yes. i trying to resolve the issue. but i don't know where i made a mistake. if you know guide me

Senior III
May 5, 2023

I used built-in temperature sensor for test but you can replace channels in line 15 and comment line 16 if you don't use temperature sensor.

It should works:

uint32_t Aout = 0;
 
 	RCC->APBENR2 |= RCC_APBENR2_ADCEN; // ADC clock enable
 	RCC->AHBENR |= RCC_AHBENR_DMA1EN; // DMA1 clock enable
 	DMA1_Channel1->CPAR = (uint32_t)&(ADC1->DR); // peripheral Address
 	DMA1_Channel1->CMAR =(uint32_t)&Aout; // Memory Address
 	DMA1_Channel1->CNDTR = 1; // No Of Data
 	DMA1_Channel1->CCR |= (DMA_CCR_MINC | DMA_CCR_MSIZE_0 | DMA_CCR_PSIZE_0| DMA_CCR_CIRC | DMA_CCR_TEIE | DMA_CCR_TCIE); // Msize,Psize,CIRC,MINC
 	DMA1_Channel1->CCR |= DMA_CCR_EN; // DMA enable
 
 	//ADC1->CR |= ADC_CR_ADEN; // ADC enable
 	ADC1->CFGR2 |= (1<<30); // 01: PCLK/2 (Synchronous clock mode)
 	ADC1->CFGR1 |= (ADC_CFGR1_CONT | ADC_CFGR1_DMAEN | ADC_CFGR1_CHSELRMOD | ADC_CFGR1_DMACFG); // 1: Continuous conversion mode & Direct memory access enable & Direct memory access configuration
 	ADC1->SMPR |= ADC_SMPR_SMP1_1; // Sampling time selection 1 (010: 7.5 ADC clock cycles)
 	ADC1->CHSELR |= (ADC_CHSELR_CHSEL12); // Channel-x selection (Channel-x selection)
 	ADC1_COMMON->CCR |= ADC_CHANNEL_TEMPSENSOR;
 ADC1->ISR &= ~(ADC_FLAG_EOC | ADC_FLAG_EOS | ADC_FLAG_OVR);
 	//ADC1->CR |= ADC_CR_ADEN; // ADC enable
 
 
 
 	NVIC_EnableIRQ(DMA1_Channel1_IRQn);
 	NVIC_SetPriority(DMA1_Channel1_IRQn,0);
 
 	ADC1->CR |= ADC_CR_ADEN; // ADC enable
 	ADC1->CR |=ADC_CR_ADSTART;

Dudo
Associate III
May 8, 2023

thank you and it's very useful for me.

Senior III
May 8, 2023

please select best answer if my answer works for you

Dudo
Associate III
May 8, 2023

hi @Kamil Duljas​ 

I replace the channel 12 to 1 in line 15 and I comment the line 16. still output is not came.

Senior III
May 8, 2023

First try run my example because it's hardware agnostic. Independent against external devices. When my examples will be valid, then try run on other channels

Dudo
Associate III
May 8, 2023

I use the same code output is came in ADC->DR only.but output is not came in Aout variable.

Senior III
May 8, 2023

Show me all code related to this variable Aout

Dudo
waclawek.jan
Super User
May 8, 2023

How is DMAMUX set?

JW

Associate III
May 8, 2023

I use stm32cubeide for STM32G030K6T6 Microcontroller, HAL_ADC_Start_DMA(&hadc1, Aout, 3) is not working outside(user code begin 2) the while loop. In bulepill board, this comment is working outside(user code begin 2) & inside the while loop. In STM32G030K6T6 Microcontroller, why this comment is not working outside(user code begin 2) the while loop?