cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 U575 ADC1 differential channel configuration

Tvoge.1
Associate II

I am having some difficulty configuring STM32U575 ADC1 for Differential inputs.

The reference manual and auto-generated code seem to have conflicting information:

The ADC1 Connectivity diagram from Reference Manual (below) indicates configuring Channel [3] as differential will use ADC_IN3 to VINP (+ve) and ADC_IN4 to VINN (-ve).

0693W00000JNRSdQAP.pngFurther down in the manual a note re: differential channels:

0693W00000JNRRzQAP.pngThe Caution note conflicts with connectivity diagram. It would suggest that when Channel 3 is configured for differential mode, then the +ve goes to VINP[3] and the -ve would go to input VINN[2].

The auto generated LL code from the IDE is another story.

The ADC init function first initializes ADC1_IN3 and ADC1_IN4. (matches the ADC connectivity diagram....so far so good)

  /**ADC1 GPIO Configuration
  PC2   ------> ADC1_IN3
  PC3   ------> ADC1_IN4
  PA2   ------> ADC1_IN7
  PA3   ------> ADC1_IN8
  PA4   ------> ADC1_IN9
  PA5   ------> ADC1_IN10
  PA6   ------> ADC1_IN11
  PA7   ------> ADC1_IN12
  PB0   ------> ADC1_IN15
  PB1   ------> ADC1_IN16
  PB2   ------> ADC1_IN17  */
 
  // GPIO pins Port C
  GPIO_InitStruct.Pin = LL_GPIO_PIN_2|LL_GPIO_PIN_3;  // Configure input pins to ADC1_IN3 and ADC1_IN4
  GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
  GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
  LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

Further down in init, the channel is configured as differential input. Note that the differential mode is written to the register for ADC1_IN4. This (according to connection diagram) would be the -ve input.

 	  //Configure Injected Channel
  LL_ADC_INJ_SetSequencerRanks(ADC1, LL_ADC_INJ_RANK_1, LL_ADC_CHANNEL_4);
  LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_4, LL_ADC_SAMPLINGTIME_12CYCLES);
  LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_4, LL_ADC_DIFFERENTIAL_ENDED);

Documented for helper macro LL_ADCAetChannelSingleDiff() has this note:

/*

 *        In differential mode: Differential measurement is carried out

 *        between the selected channel 'i' (positive input) and

 *        channel 'i+1' (negative input). Only channel 'i' has to be

 *        configured, channel 'i+1' is configured automatically.

This note would indicate that the configuration should be applied to the +ve input....so the initialization code would not be correct.

Can anyone confirm if the connectivity diagram from the reference manual is correct?

1 REPLY 1
Tvoge.1
Associate II

I have it working now and can answer my own question for others who may have same issue:

  • The ADC1 Connectivity Diagram (Figure 149 in the stm32u575 ref manual) is correct. Use that as your guide.
  • The Caution note in section 29.4.7 of the manual is not correct.
  • Do not rely on the Cube IDE LL auto-generated code for ADC1 initialization with differential inputs...some problems there. Initializes the -ve channel instead of the +ve and also fails to initialize the PCSEL register for the channel.

So then, to correctly initialize Channel [3] for differential input:

 /**ADC1 GPIO Configuration

 PC2  ------> ADC1_IN3 (+ve input)

 PC3  ------> ADC1_IN4 (-ve input)

 // GPIO pins Port C - Configure input pins to ADC1_IN3 and ADC1_IN4

 GPIO_InitStruct.Pin = LL_GPIO_PIN_2|LL_GPIO_PIN_3;

 GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;

 GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;

 LL_GPIO_Init(GPIOC, &GPIO_InitStruct);

// Configure Injected Channel 3 for differential, initialize the +ve input only.

// The -ve channel is automatically configured.

 LL_ADC_INJ_SetSequencerRanks(ADC1, LL_ADC_INJ_RANK_1, LL_ADC_CHANNEL_3);

 LL_ADC_SetChannelSamplingTime(ADC1, LL_ADC_CHANNEL_3, LL_ADC_SAMPLINGTIME_12CYCLES);

 LL_ADC_SetChannelSingleDiff(ADC1, LL_ADC_CHANNEL_3, LL_ADC_DIFFERENTIAL_ENDED);

// don't forget this step

 LL_ADC_SetChannelPreselection(ADC1, LL_ADC_CHANNEL_3);