Analogread sampletime issue

Post here first, or if you can't find a relevant section!
Post Reply
serkanc
Posts: 5
Joined: Fri Feb 14, 2020 8:07 am

Analogread sampletime issue

Post 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
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Analogread sampletime issue

Post by fpiSTM »

Use the build_opt.h
serkanc
Posts: 5
Joined: Fri Feb 14, 2020 8:07 am

Re: Analogread sampletime issue

Post 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
serkanc
Posts: 5
Joined: Fri Feb 14, 2020 8:07 am

Re: Analogread sampletime issue

Post 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.
Post Reply

Return to “General discussion”