// STM32 Nucleo-L031K6 HAL Blink + printf() example
// Simulation: https://wokwi.com/projects/367244067477216257
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stm32l0xx_hal.h>
#define ADC_CHANNEL ADC_CHANNEL_0
int main(void)
{
HAL_Init();
// Configure ADC
ADC_HandleTypeDef hadc;
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.ScanConvMode = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
HAL_ADC_Init(&hadc);
// Configure PA0 as analog input
ADC_ChannelConfTypeDef sConfig;
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = ADC_REGULAR_GROUP;
hadc.Init.SamplingTime = ADC_SAMPLETIME_19CYCLES_5;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
while (1)
{
uint16_t adc_value;
HAL_ADC_Start(&hadc);
HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
adc_value = HAL_ADC_GetValue(&hadc);
printf("adc val:%d\n ", adc_value);
HAL_Delay(100);
}
return 0;
}
Loading
st-nucleo-l031k6
st-nucleo-l031k6