mirror of
https://github.com/xiaozhou233/RiverWaterQualityMonitoring.git
synced 2026-12-05 13:05:53 +08:00
封装ADC工具
This commit is contained in:
1 parent
6082aa1ec7
commit
5af7a0b4a2
2 files changed
+45
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* adc_utils.h
|
||||||
|
*
|
||||||
|
* Created on: 2026年7月1日
|
||||||
|
* Author: xiaozhou233
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ADC_UTILS_H
|
||||||
|
#define ADC_UTILS_H
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
// Read ADC value
|
||||||
|
uint16_t ADC_Read(ADC_HandleTypeDef *hadc);
|
||||||
|
|
||||||
|
// Convert ADC value to millivolts
|
||||||
|
uint32_t ADC_ToMilliVolt(uint16_t adc);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* adc_utils.c
|
||||||
|
*
|
||||||
|
* Created on: 2026年7月1日
|
||||||
|
* Author: xiaozhou233
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "adc_utils.h"
|
||||||
|
|
||||||
|
uint16_t ADC_Read(ADC_HandleTypeDef *hadc)
|
||||||
|
{
|
||||||
|
HAL_ADC_Start(hadc);
|
||||||
|
|
||||||
|
HAL_ADC_PollForConversion(hadc, HAL_MAX_DELAY);
|
||||||
|
|
||||||
|
uint16_t value = HAL_ADC_GetValue(hadc);
|
||||||
|
|
||||||
|
HAL_ADC_Stop(hadc);
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ADC_ToMilliVolt(uint16_t adc)
|
||||||
|
{
|
||||||
|
return ((uint32_t)adc * 3300 + 2047) / 4095;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user