cancel
Showing results for 
Search instead for 
Did you mean: 

Can the ADC regular channel and injected channel of STM32G4 not be used at the same time? Is this a bug?

one V
Associate III

 I use cubemx (6.0.0) to generate ADC1 configuration code, for example, ADC1 channels 1, 2, and 3 are injection channels, and TIM1 channel 4 is used to trigger, and ADC1’s 4, 5 are Regular channel. STM32F4 can work very well. But STM32G4 does not work, the regular channel does not run.

8 REPLIES 8
TDK
Guru

Only one conversion can happen at a time. But depending on your triggers, injected channels may be converted during the same sequence as regular channels. For example, this is from the RM:

Auto-injection mode

If the JAUTO bit in the ADC_CFGR register is set, then the channels in the injected group

are automatically converted after the regular group of channels. This can be used to convert

a sequence of up to 20 conversions programmed in the ADC_SQRy and ADC_JSQR

registers.

If you feel a post has answered your question, please click "Accept as Solution".
one V
Associate III

Thank you very much for your reply. I know the related principles of ADC injection mode and regular channel mode.STM32F4 can work very well. But STM32G4 does not .

LDoes
Associate II

I've got an STM32G474 running both regular and injected channels on all ADCs without any problems. Have you enabled both ADCx->ADSTART and ADCx->JADSTART?

Take a look at the errata - maybe you are running into that?

one V
Associate III

This is my ioc file, can you help me see where the configuration is wrong? Or can you generate a keil project and run it?

Thank you very much! 

I can't tell from only the .ioc if all of your code is correct, but some things do stand out. You have set the number of discontinuous conversions to 5 while you only have 2 channels selected in your sequence. Furthermore you have enabled the DMA which slightly complicates things because I can't see how you handle those interrupts.

In your main.c, do you call both HAL_ADC_Start()/HAL_ADC_Start_DMA() and HAL_ADCEx_InjectedStart()/HAL_ADCEx_InjectedStart_IT()?

Can you verify using a debugger that ADC1->DR remains empty?

one V
Associate III

I called the following function: HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);HAL_ADCEx_InjectedStart_IT(&hadc1); HAL_ADC_Start_DMA(&hadc1, adc_regular_val, 2);  and uint32_t adc_regular_val[2];

Hmm, I think that is the correct way to do it.

Can you take a look at the solution in https://community.st.com/s/question/0D50X0000BUlAzpSQF/haladcstartdma-example-always-get-value-0 ?