cancel
Showing results for 
Search instead for 
Did you mean: 

In CubeMX program for the ADC I want 4 ADC channels, but the MX program only lets me enter data for 3. How do I put in data for Rank 1?

KiptonM
Lead

I am trying to setup an ADC to read 4 different inputs. TempSensor, VRefint, Channel 0 and Channel 1. When I tell it number of conversions = 4 It lets me Fill in Rank 2, 3, and 4, but not Rank 1. I thought this worked before. 

0693W00000NrGcxQAF.pngI uninstalled the ST IDE, and MX programs and reinstalled.

Same issue. What am I doing wrong?

Did something get corrupted?

 STM32CubeMX - STM32 Device Configuration Tool

Version: 6.5.0-RC4

Build: 20220225-1913 (UTC)

1 ACCEPTED SOLUTION

Accepted Solutions
Aziz BRIGUI
ST Employee

Hello @KiptonM​,

Thank you for your fast response,

This is a known issue and has already been reported internally. It will be fixed as soon as possible. 

Internal ticket number: 121506 (This is an internal tracking number and is not accessible or usable by customers).

Beside the workaround you mentioned, you can also try deselecting the ADC channels and reselecting them then repeating the parameter configuration for ADC.

We apologize for the inconvenience.

Best regards,

Aziz


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

View solution in original post

11 REPLIES 11
KiptonM
Lead

Looking at the code generated it is as follows.

static void MX_ADC1_Init(void)
{
 
  /* USER CODE BEGIN ADC1_Init 0 */
 
  /* USER CODE END ADC1_Init 0 */
 
  ADC_ChannelConfTypeDef sConfig = {0};
 
  /* USER CODE BEGIN ADC1_Init 1 */
 
  /* USER CODE END ADC1_Init 1 */
 
  /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  */
  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
  hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;
  hadc1.Init.LowPowerAutoWait = DISABLE;
  hadc1.Init.LowPowerAutoPowerOff = DISABLE;
  hadc1.Init.ContinuousConvMode = DISABLE;
  hadc1.Init.NbrOfConversion = 4;
  hadc1.Init.DiscontinuousConvMode = ENABLE;
  hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIG_T3_TRGO;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
  hadc1.Init.DMAContinuousRequests = DISABLE;
  hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
  hadc1.Init.SamplingTimeCommon1 = ADC_SAMPLETIME_39CYCLES_5;
  hadc1.Init.SamplingTimeCommon2 = ADC_SAMPLETIME_160CYCLES_5;
  hadc1.Init.OversamplingMode = ENABLE;
  hadc1.Init.Oversampling.Ratio = ADC_OVERSAMPLING_RATIO_8;
  hadc1.Init.Oversampling.RightBitShift = ADC_RIGHTBITSHIFT_NONE;
  hadc1.Init.Oversampling.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
  hadc1.Init.TriggerFrequencyMode = ADC_TRIGGER_FREQ_HIGH;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_VREFINT;
  sConfig.Rank = ADC_REGULAR_RANK_2;
  sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_2;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_0;
  sConfig.Rank = ADC_REGULAR_RANK_3;
  sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_1;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
  /** Configure Regular Channel
  */
  sConfig.Channel = ADC_CHANNEL_1;
  sConfig.Rank = ADC_REGULAR_RANK_4;
  if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN ADC1_Init 2 */
 
  /** Configure Regular Channel
    */
    sConfig.Channel = ADC_CHANNEL_TEMPSENSOR;
    sConfig.Rank = ADC_REGULAR_RANK_1;
    sConfig.SamplingTime = ADC_SAMPLINGTIME_COMMON_2;
    if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
    {
      Error_Handler();
    }
  /* USER CODE END ADC1_Init 2 */
 
}

So I added a section in the user code to setup Rank 1.

That is all I can think of at the moment.

Aziz BRIGUI
ST Employee

Hello @KiptonM​,

Thank you for your feedback,

Could you please share an IOC file demonstrating the issue, that would be really helpful :) .

Best regards,

Aziz


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
KiptonM
Lead

Here it is attached.

Aziz BRIGUI
ST Employee

Hello @KiptonM​,

Thank you for your fast response,

This is a known issue and has already been reported internally. It will be fixed as soon as possible. 

Internal ticket number: 121506 (This is an internal tracking number and is not accessible or usable by customers).

Beside the workaround you mentioned, you can also try deselecting the ADC channels and reselecting them then repeating the parameter configuration for ADC.

We apologize for the inconvenience.

Best regards,

Aziz


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
KiptonM
Lead

I deselected the ADC channels saved it, closed the program. Started it again, Selected the channels, and reconfigured the ADC, and it is working now.

Thanks,

Aziz BRIGUI
ST Employee

Hello @KiptonM​,

Did you by any chance use the import project feature in CubeMX. We noticed that using that feature can cause the issue you mentioned. Do you confirm this ? and if not could you please specify a scenario to reproduce the "missing rank 1" behavior.

Your contribution will certainly help us to pinpoint the root cause.

Thanks,

Aziz


In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

I do not remember. It may have been an upgrade from 1.7 to 1.9.

All I know is that it had been working, and I realized I tried to change the order the first one disappeared.

Originally I read AN0, AN1, Temp Sensor, and VRef.

Since the Temperature and takes 5 microseconds to sample, I changed the order to read it first, so when I finished reading the 4 values, I had the most time before a new value came in.

So the new order was Temp Sensor, Vref, AN0, and AN1.

That was what I was doing when it appeared.

There is surely something weird going on.

I decided to go back and change the modes.

Discontinuous Conversion Mode is Enabled, but the MX program dos not have a pull down option to disable.

In the comment it says  Discontinuous Conversion Mode

Discontinuous Conversion Mode

* This parameter has automatically changed after your last modification.

0693W00000NrMGEQA3.png 

Scan Conversion Mode is Enabled, but it will not let me Disable. It is in the pull down menu but it is grayed out.

Attached is the .ioc file.

I decided to Press the Reset Configuration Button and reenter the values.

The choice for Discontinuous Mode is gone! It was between Continuous Conversion Mode and DMA Continuous Requests.

0693W00000NrMIFQA3.pngFortunately I am not interested in Discontinuous mode at the moment.

Thought you may want to know.