diff options
Diffstat (limited to 'tests/adc-power')
-rw-r--r-- | tests/adc-power/adc-power.c | 9 | ||||
-rw-r--r-- | tests/adc-power/main-stm32l4-disco.c | 9 |
2 files changed, 15 insertions, 3 deletions
diff --git a/tests/adc-power/adc-power.c b/tests/adc-power/adc-power.c index 2d7f310..9b6df07 100644 --- a/tests/adc-power/adc-power.c +++ b/tests/adc-power/adc-power.c @@ -39,7 +39,7 @@ #define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP #define SEPARATE_VREF 0 #elif defined(STM32L4) -#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_47DOT5CYC +#define SAMPLE_TIME_BASIC ADC_SMPR_SMP_247DOT5CYC #define SAMPLE_TIME_TEMP ADC_SMPR_SMP_247DOT5CYC #define SAMPLE_TIME_VREF SAMPLE_TIME_TEMP #else @@ -68,6 +68,11 @@ void adc_power_init(void) ADC_CR(ADC1) &= ~ADC_CR_DEEPPWD; RCC_CCIPR |= 3 << 28; // system clock as adc clock. (with CKMODE == 0) adc_enable_regulator(ADC1); + + ADC_CR(ADC1) &= ~ADC_CR_ADCALDIF; + ADC_CR(ADC1) |= ADC_CR_ADCAL; + while (ADC_CR(ADC1) & ADC_CR_ADCAL); + #else rcc_periph_clock_enable(RCC_ADC1); @@ -137,7 +142,7 @@ void adc_power_task_up(void) { * I mean, we're going to do some conversions right? */ adc_set_single_conversion_mode(ADC1); TIM_CNT(TIMER) = 0; - unsigned int v1 = read_adc_naiive(1); + unsigned int v1 = read_adc_naiive(1); // 8 for l4! unsigned int v5 = read_adc_naiive(5); unsigned int temp_adc = read_adc_naiive(ADC_CHANNEL_TEMP); unsigned int vref_adc = read_adc_naiive(ADC_CHANNEL_VREF); diff --git a/tests/adc-power/main-stm32l4-disco.c b/tests/adc-power/main-stm32l4-disco.c index ad21fcb..aebcb69 100644 --- a/tests/adc-power/main-stm32l4-disco.c +++ b/tests/adc-power/main-stm32l4-disco.c @@ -45,9 +45,16 @@ int main(void) LED_DISCO_RED_PIN); /* ADC 1 channels 1 and 5 */ - gpio_mode_setup(GPIOC, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); + // This is the reset state, so not really necessary. + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO0); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO1); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO2); + gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO3); gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO5); + // This is NOT the reset state! very important! + GPIO_ASCR(GPIOA) |= GPIO0 | GPIO1 | GPIO2 | GPIO3 | GPIO5; + adc_power_init(); while (1) { adc_power_task_up(); |