mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 03:27:45 +08:00
adc
This commit is contained in:
@@ -1,5 +1,53 @@
|
||||
//
|
||||
// Created by tuxmonkey on 2025/10/28.
|
||||
//
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_adc.c
|
||||
* @brief : bsp adc functions
|
||||
* @author : TuxMonkey
|
||||
* @date : 2025/11/22
|
||||
* @version : v1.0
|
||||
******************************************************************************
|
||||
* @attention : Pay attention to enable the adc
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "bsp_adc.h"
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "bsp_adc.h"
|
||||
#include "adc.h"
|
||||
|
||||
/**
|
||||
* @brief ADC sampling voltage array
|
||||
*/
|
||||
__attribute__((section (".AXI_SRAM"))) uint16_t ADC_Voltage_Val[2];
|
||||
|
||||
/**
|
||||
* @brief Configures the ADC.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void BSP_ADC_Init(void)
|
||||
{
|
||||
|
||||
HAL_ADCEx_Calibration_Start(&hadc1, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) ADC_Voltage_Val, 2);
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief USER get current voltage.
|
||||
* @param None
|
||||
* @retval Voltage
|
||||
*/
|
||||
float USER_ADC_Voltage_Update(void)
|
||||
{
|
||||
|
||||
float Voltage;
|
||||
Voltage = (ADC_Voltage_Val[0] * 3.3f / 65535) * 11.0f;
|
||||
return Voltage;
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,8 +1,34 @@
|
||||
//
|
||||
// Created by tuxmonkey on 2025/10/28.
|
||||
//
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : bsp_adc.h
|
||||
* @brief : The header file of bsp_adc.h
|
||||
* @author : TuxMonkey
|
||||
* @date : 2025/11/22
|
||||
* @version : v1.0
|
||||
******************************************************************************
|
||||
* @attention : Pay attention to config the clock source of the advanced TIM
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef TRONONEH7_SCAFFOLD_BSP_ADC_H
|
||||
#define TRONONEH7_SCAFFOLD_BSP_ADC_H
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef BSP_ADC_H
|
||||
#define BSP_ADC_H
|
||||
|
||||
#endif //TRONONEH7_SCAFFOLD_BSP_ADC_H
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "adc.h"
|
||||
|
||||
/* Externs ---------------------------------------------*/
|
||||
void BSP_ADC_Init(void);
|
||||
|
||||
float USER_ADC_Voltage_Update(void);
|
||||
#endif //BSP_ADC_H
|
||||
|
||||
Reference in New Issue
Block a user