Page 1 of 1

Analogread sampletime issue

Posted: Tue Sep 20, 2022 5:39 pm
by serkanc
Hi,

I searched forum, tried everything I read. I'm usingg STM32F103RCT based custom board. I want to read analog values for PC0 and PC1.
I have created hal_conf_extra.h file

#ifndef HAL_CONF_EXTRA_H_
#define HAL_CONF_EXTRA_H_
#define SERIAL_RX_BUFFER_SIZE 256
#define SERIAL_TX_BUFFER_SIZE 256
#define ADC_SAMPLETIME ADC_SAMPLETIME_55CYCLES_5
#endif /* HAL_CONF_EXTRA_H_ */

In debug i watch the ADC1 SMPR1 register. They are always 0. According to datasheet 000: 1.5 cycles. I tried to change SMPR in setup. I have enabled RCC Clock for ADC1 and changed SMPR register for channel 10 and 11 to 101 for each channel 101: 55.5 cycles. It updated register succesfull. But when reading I reset it to 000 again.
I have system clock function in my sketch. It has PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4. I run the mcu 72MHZ. What can I do change the sampetime. Thanks

Re: Analogread sampletime issue

Posted: Tue Sep 20, 2022 6:04 pm
by fpiSTM
Use the build_opt.h

Re: Analogread sampletime issue

Posted: Tue Sep 20, 2022 7:36 pm
by serkanc
#define ADC_SAMPLINGTIME ADC_SAMPLETIME_55CYCLES_5;
semicolon does the trick. Not sampling time worked. But i defined in SystemClock Config PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV4
but I looked at the RCC register ADCPRE: ADC prescaler.. It it DIV2... should I define it with build_opt.h

Re: Analogread sampletime issue

Posted: Tue Sep 20, 2022 9:04 pm
by serkanc
I think something is wrong with core.
Arduino Ide doesnt take build_opt.h into account.
so added flags manually.
ADC_CLOCK_DIV_4 is undefined
so i tried to give a value to it. So it throws another error.
AdcHandle.Init.ClockPrescaler = ADC_CLOCK_DIV; /* (A)synchronous clock mode, input ADC clock divided */

this line AdcHandle Init doesnt have ClockPrescaler in struct definition....
in analog.cpp line 812.