2322 views|2 replies

1460

Posts

1

Resources
The OP
 

[NUCLEO-L452RE Review] + Simple Digital Voltmeter [Copy link]

With the help of the ADC inside the STM32L452 and an OLED screen, a simple digital voltmeter can be formed. The display effects are shown in Figures 1 to 3.

The channel used for A/D acquisition is ADC_CHANNEL_9 , and the pin occupied is PA4 .

Figure 1 Collection values in suspended state

Figure 2 Measured value when connected to GND

Figure 3. Measurement value of connecting VDD

The main program to achieve this display effect is:

int main(void)
{
 HAL_Init();
 SystemClock_Config();
 BSP_LED_Init(LED2);
 AdcHandle.Instance = ADCx;
 if (HAL_ADC_DeInit(&AdcHandle) != HAL_OK)
 {
 Error_Handler();
 }
 AdcHandle.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
 AdcHandle.Init.Resolution = ADC_RESOLUTION_12B;
 AdcHandle.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  AdcHandle.Init.ScanConvMode = DISABLE;
 AdcHandle.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
 AdcHandle.Init.LowPowerAutoWait = DISABLE;
 AdcHandle.Init.ContinuousConvMode = ENABLE;
 AdcHandle.Init.NbrOfConversion = 1;
 AdcHandle.Init.DiscontinuousConvMode = DISABLE;
 AdcHandle.Init.NbrOfDiscConversion = 1;
 AdcHandle.Init.ExternalTrigConv = ADC_SOFTWARE_START;
 AdcHandle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
 AdcHandle.Init.DMAContinuousRequests = DISABLE;
 AdcHandle.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
 AdcHandle.Init.OversamplingMode = ENABLE;
 AdcHandle.Init.Oversampling.Ratio = OVERSAMPLING_RATIO;
 AdcHandle.Init.Oversampling.RightBitShift = RIGHTBITSHIFT;
 AdcHandle.Init.Oversampling.TriggeredMode = TRIGGEREDMODE;
 AdcHandle.Init.Oversampling.OversamplingStopReset = OVERSAMPLINGSTOPRESET;
 if (HAL_ADC_Init(&AdcHandle) != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
 {
 Error_Handler();
 }
 sConfig.Channel = ADCx_CHANNEL;
 sConfig.Rank = ADC_REGULAR_RANK_1;
 sConfig.SamplingTime = ADC_SAMPLETIME_6CYCLES_5;
 sConfig.SingleDiff = ADC_SINGLE_ENDED;
 sConfig.OffsetNumber = ADC_OFFSET_NONE;
 sConfig.Offset = 0;
 if (HAL_ADC_ConfigChannel(&AdcHandle, &sConfig) != HAL_OK)
 {
 Error_Handler();
 }
 if (HAL_ADC_Start(&AdcHandle) != HAL_OK)
 {
 Error_Handler();
 }
 APP_OLED_Init();
 OLED_Init();
 OLED_Clear();
 OLED_ShowString(8,0,"STM32L452RE",16);
 OLED_ShowString(8,2,"OLED & ADC ",16);
 OLED_ShowCHinese(80,0,0);
 OLED_ShowCHinese(96,0,1);
 OLED_ShowCHinese(112,0,2);
 OLED_ShowString(60,6,"mV",16);
 while (1)
 {
 if (HAL_ADC_PollForConversion(&AdcHandle, 10) != HAL_OK)
 {
 Error_Handler();
 }
 uwConvertedValue = HAL_ADC_GetValue(&AdcHandle);
 OLED_ShowNum(10,4,uwConvertedValue,6,16);
 uwInputVoltage = uwConvertedValue * 3300;
 uwInputVoltage = uwInputVoltage / 0xFFF0;
 OLED_ShowNum(10,6,uwInputVoltage,5,16);
 HAL_Delay(500);
 }
}

This post is from stm32/stm8

Latest reply

Thanks for sharing!   Details Published on 2021-1-6 21:46
 

7462

Posts

2

Resources
2
 

Thanks for sharing!

This post is from stm32/stm8
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 

1460

Posts

1

Resources
3
 
freebsder posted on 2021-1-6 21:46 Thank you for sharing!

This post is from stm32/stm8
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list