cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474 ADC in continuous regular scanning mode with injection fails due to injection channels being internally tied to ground

CHossack
Associate III

I am trying to set up my NUCLEO-G474RE board to perform ADC regular scanning mode using DMA with 4 channels and also discontinuous injection with 2 channels as shown below.

0693W000007EvA4QAK.jpgBut when I run my code the injected channels always return zero or one, even if I connect their channel to 3.3V. It seems to be sampling the injected channels but for some reason instead of being connected to the actual pins their are tied low internally.

I’ve use STM32CUBEMX to set up my NUCLEO-G474RE board as follows.

  • ADC Configuration
    • IN1/2/5/6/7/8 set to “Single Ended�?
  • “DMA Settings�? Tab
    • Add DMA Request, Mode = “Circular�?
  • “NVIC Settings�? Tab
    • Enable “DMA1 channel global interrupt�?
    • Enable “ADC1 and ADC2 global interrupt�?
  • “Parameter Settings�? Tab
    • “ADC_Settings�?
      • “Continuous Conversion Mode = Enable
      • “DMA Continuous Requests�? = Enable
    • “ADC_Regular_ConversionMode�?
      • “Number of Conversions�? = 4
      • Rank 1, Channel = Channel 5, Sampling Time = 640.5 Cycles
      • Rank 2, Channel = Channel 6, Sampling Time = 640.5 Cycles
      • Rank 3, Channel = Channel 7, Sampling Time = 640.5 Cycles
      • Rank 4, Channel = Channel 8, Sampling Time = 640.5 Cycles
    • ADC_Injection_ConversionMode
      • Enable Inject Conversions = “Enable�?
      • “Number of Conversions�? = 2
      • “External Trigger Conversion Source�? = Timer 2 Capture Compare 1 event�?
      • “Injected Conversion Mode�? = “Discontinuous Mode�?
      • Rank 1, Channel = Channel 1
      • Rank 2, Channel = Channel 2
    • TIM2
      • “Clock Source�? = Internal Clock
      • Channel1 = “PWM Generation No Output�?
      • “Parameter Settings�? Tab
        • “Counter Period�? = 170000000 (1second @ 170MHz)
        • “PWM Generation Channel 1�?
          • “Pulse�? = 100000000

I then hit the “GENERATE CODED�? button and make the following code changes to main.c

/* USER CODE BEGIN 0 */
volatile int16_t ADCxConvertedDataAdc[4];
/* USER CODE END 0 */
:
:
  /* USER CODE BEGIN 2 */
  HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);
  HAL_ADCEx_InjectedStart_IT(&hadc1);
  HAL_ADC_Start_DMA(&hadc1, (uint32_t*)ADCxConvertedDataAdc, 4);
  HAL_TIM_PWM_Start_IT(&htim2, TIM_CHANNEL_1);
  /* USER CODE END 2 *

If I comment out “HAL_ADC_Start_DMA�? I can see my inject channels sampling random values every second as configured from TIM2.

0693W000007EvFxQAK.jpg 

But when I run with “HAL_ADC_Start_DMA�? I can see the 4 random values being continuous being sampled, but now my injected values only report zero, or sometimes ones.

0693W000007EvHyQAK.jpgI've include my ioc and source code as well as a zip file.

Hopefully I'm just doping something stupid in my code to initialise the ADC and it's not a bug in the ADC module.

cheers

Chris

2 REPLIES 2
Igor Cesko
ST Employee

Hi CHossack (Community Member) ,

This is limitation of STM32G4 ADC in Rev Y only (your chip has Rev Y). See please STM32G4 devices erratasheets for workaround (chapter: "2.7.8 ADC channel 0 converted instead of the required ADC channel").

In STM32G4 Rev X is this limitation removed.

Regards

Igor

CHossack
Associate III

hi Igor,

thank you for your help.

cheers

Chris