2022-01-26 11:10 AM
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).
Further down in the manual a note re: differential channels:
The 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?
2022-01-26 12:18 PM
I have it working now and can answer my own question for others who may have same issue:
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);