Posted on October 30, 2017 at 14:33I was able to get a reading on ADC2_IN4 using the STM32F303K8 on a STM32F303 Nucleo-32 evaluation/development board. I had found an example using ADC1_IN1 and was attempting to modify for
mailto:ADC@_IN4
. My issue was understanding the ADCx_SQR register. My read on this register it that it is a list of channels (IN1,IN2,...) pins, in a regular group, that will be read/converted in a particular order. So for ADC2_IN4, setup as the first (and only) pin, I had to set
ADC2_SQR1's SQ1 as a 0x4. The ADC2_SQR1's 'L' field describes the length or number of channels to convert and defaults to 0x00 or 1 conversion.
My converted the sample code from ADC1_IN1 to ADC2_IN4 and it now works. The code is listed below.
Thanks to all that read and thought about my question.
Randy
//
// clocks are already setup
//
GPIOA_MODER |= BIT15+BIT14; //make PA7, ADC2_IN4, analog
RCC_AHBENR |= BIT28; // turn on ADC clock
ADC12_CCR |= BIT17; // Set ADC clock = HCLK / 2=32MHz
ADC2_CR &= ~BIT0; // disable the ADC
// enable the ADC voltage regulator
ADC2_CR &= ~BIT29;
ADC2_CR |= BIT28;
// start ADC calibration cycle
ADC2_CR |= BIT31;
while (ADC2_CR & BIT31); // wait for calibration to complete
ADC2_CR |= BIT0; // enable the ADC
ADC2_SQR1 = (1 << 8); // Select ADC Channel 4, This is important and what I was missing
while(1) {
ADC2_CR |= BIT2; // start conversion
while (ADC2_CR & BIT2); // wait for end of conversion
int_var_V1 = ADC2_DR; //also a break point for debug
}