I want to sample one (of six) ADC channel for 2 ms in blocking mode. How hard can it be?
I using STM32CubeIDE and STM32L03.
I don't understand how to make a simple sample of a ADC channel (in blocking mode). I had config the Cube to generate a ADC_Init() that contains my 6 Analog In channels.
I want to have a function that goes like this: uint16_t AD_Read(unit32_t channel) { ... }
I make a ADC_Start and then HAL_Polling() and then get the ADC value. Doing that for 20 samples. But where do I set what ADC channel I want to read? Is it the rank member I set before I calling HAL_ADC_Start() or what? The first channel in ADC_Init has this "rank" member set.
The config I tried to keep as simple as I could. No group scanning or continuous scanning and no interrupt.
The ADC_Init
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = DISABLE;
hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION_10B;
hadc.Init.SamplingTime = ADC_SAMPLETIME_19CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
plus six ADC-channel where the first has sConfig.rank = ADC_RANK_CHANNEL_NUMBER
