21ic问答首页 - HC32L110的ADC通道AdcAVccDiV3Input不能中断问题
HC32L110的ADC通道AdcAVccDiV3Input不能中断问题
yjsmcu2023-01-04
//使用\HC32L110_DDL_Rev1.1.5\example\adc\adc_cont_irq_sw范例改
/******************************************************************************
* Include files
******************************************************************************/
#include "adc.h"
#include "gpio.h"
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
static uint32_t u32AdcResultAcc;
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
void AdcContIrqCallback(void)
{
//中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
Adc_GetAccResult(&u32AdcResultAcc);
Adc_ClrAccResult();
// Adc_ClrContIrqState();
}
void AdcRegIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrRegIrqState();
}
void AdcHhtIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrHhtIrqState();
}
void AdcLltIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrLltIrqState();
}
/**
******************************************************************************
** \brief Main function of project
**
** \return uint32_t return value, if needed
**
** This sample
**
******************************************************************************/
int32_t main(void)
{
stc_adc_cfg_t stcAdcCfg;
stc_adc_cont_cfg_t stcAdcContCfg;
stc_adc_irq_t stcAdcIrq;
stc_adc_irq_calbakfn_pt_t stcAdcIrqCalbaks;
DDL_ZERO_STRUCT(stcAdcCfg);
DDL_ZERO_STRUCT(stcAdcContCfg);
DDL_ZERO_STRUCT(stcAdcIrq);
DDL_ZERO_STRUCT(stcAdcIrqCalbaks);
Clk_SwitchTo(ClkRCL);
Clk_SetRCHFreq(ClkFreq24Mhz);
Clk_SwitchTo(ClkRCH);
Clk_SetPeripheralGate(ClkPeripheralGpio, TRUE); //GPIO 外设时钟使能
if (Ok != Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE)) //ADCBGR 外设时钟使能
{
return Error;
}
//Gpio_SetAnalog(2, 4, TRUE);
//ADC配置
Adc_Enable();
M0P_BGR->CR_f.BGR_EN = 0x1u; //BGR必须使能
M0P_BGR->CR_f.TS_EN = 0x0u; //内置温度传感器,视使用需求
delay100us(1);
stcAdcCfg.enAdcOpMode = AdcContMode; //连续采样模式
stcAdcCfg.enAdcClkSel = AdcClkSysTDiv1; //PCLK
stcAdcCfg.enAdcSampTimeSel = AdcSampTime8Clk; //8个采样时钟
// stcAdcCfg.enAdcRefVolSel = RefVolSelInBgr2p5; //参考电压:内部2.5V(avdd>3V,SPS<=200kHz)
stcAdcCfg.enAdcRefVolSel = RefVolSelAVDD; //参考电压:AVDD
stcAdcCfg.bAdcInBufEn = TRUE;
//stcAdcCfg.bAdcInBufEn = FALSE; //电压跟随器如果使能,SPS采样速率 <=200K
stcAdcCfg.enAdcTrig0Sel = AdcTrigDisable; //ADC转换自动触发设置
stcAdcCfg.enAdcTrig1Sel = AdcTrigDisable;
Adc_Init(&stcAdcCfg);
stcAdcIrq.bAdcIrq = TRUE; //转换完成中断函数入口配置使能
stcAdcIrq.bAdcRegCmp = FALSE;
stcAdcIrq.bAdcHhtCmp = FALSE;
stcAdcIrq.bAdcLltCmp = FALSE;
stcAdcIrqCalbaks.pfnAdcContIrq = AdcContIrqCallback; //转换完成中断入口函数
stcAdcIrqCalbaks.pfnAdcRegIrq = AdcRegIrqCallback;
stcAdcIrqCalbaks.pfnAdcHhtIrq = AdcHhtIrqCallback;
stcAdcIrqCalbaks.pfnAdcLltIrq = AdcLltIrqCallback;
Adc_ConfigIrq(&stcAdcIrq, &stcAdcIrqCalbaks); //转换中断入口函数配置
Adc_EnableIrq(); //中断使能
Adc_CmpCfg(&stcAdcIrq); //结果比较中断使能/禁止配置
stcAdcContCfg.enAdcContModeCh = AdcAVccDiV3Input; //通道0 P24
stcAdcContCfg.u8AdcSampCnt = 0x09u; //P24 连续累加次数(次数 = 0x09+1)
stcAdcContCfg.bAdcResultAccEn = TRUE; //累加使能
Adc_ConfigContMode(&stcAdcCfg, &stcAdcContCfg);
while(1)
{
Adc_Start(); //ADC开始转换
delay1ms(1000);
}
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "adc.h"
#include "gpio.h"
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
static uint32_t u32AdcResultAcc;
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
void AdcContIrqCallback(void)
{
//中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
Adc_GetAccResult(&u32AdcResultAcc);
Adc_ClrAccResult();
// Adc_ClrContIrqState();
}
void AdcRegIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrRegIrqState();
}
void AdcHhtIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrHhtIrqState();
}
void AdcLltIrqCallback(void)
{
// 中断标志位判断和清零,已在库函数中处理Adc_IRQHandler();
// Adc_ClrLltIrqState();
}
/**
******************************************************************************
** \brief Main function of project
**
** \return uint32_t return value, if needed
**
** This sample
**
******************************************************************************/
int32_t main(void)
{
stc_adc_cfg_t stcAdcCfg;
stc_adc_cont_cfg_t stcAdcContCfg;
stc_adc_irq_t stcAdcIrq;
stc_adc_irq_calbakfn_pt_t stcAdcIrqCalbaks;
DDL_ZERO_STRUCT(stcAdcCfg);
DDL_ZERO_STRUCT(stcAdcContCfg);
DDL_ZERO_STRUCT(stcAdcIrq);
DDL_ZERO_STRUCT(stcAdcIrqCalbaks);
Clk_SwitchTo(ClkRCL);
Clk_SetRCHFreq(ClkFreq24Mhz);
Clk_SwitchTo(ClkRCH);
Clk_SetPeripheralGate(ClkPeripheralGpio, TRUE); //GPIO 外设时钟使能
if (Ok != Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE)) //ADCBGR 外设时钟使能
{
return Error;
}
//Gpio_SetAnalog(2, 4, TRUE);
//ADC配置
Adc_Enable();
M0P_BGR->CR_f.BGR_EN = 0x1u; //BGR必须使能
M0P_BGR->CR_f.TS_EN = 0x0u; //内置温度传感器,视使用需求
delay100us(1);
stcAdcCfg.enAdcOpMode = AdcContMode; //连续采样模式
stcAdcCfg.enAdcClkSel = AdcClkSysTDiv1; //PCLK
stcAdcCfg.enAdcSampTimeSel = AdcSampTime8Clk; //8个采样时钟
// stcAdcCfg.enAdcRefVolSel = RefVolSelInBgr2p5; //参考电压:内部2.5V(avdd>3V,SPS<=200kHz)
stcAdcCfg.enAdcRefVolSel = RefVolSelAVDD; //参考电压:AVDD
stcAdcCfg.bAdcInBufEn = TRUE;
//stcAdcCfg.bAdcInBufEn = FALSE; //电压跟随器如果使能,SPS采样速率 <=200K
stcAdcCfg.enAdcTrig0Sel = AdcTrigDisable; //ADC转换自动触发设置
stcAdcCfg.enAdcTrig1Sel = AdcTrigDisable;
Adc_Init(&stcAdcCfg);
stcAdcIrq.bAdcIrq = TRUE; //转换完成中断函数入口配置使能
stcAdcIrq.bAdcRegCmp = FALSE;
stcAdcIrq.bAdcHhtCmp = FALSE;
stcAdcIrq.bAdcLltCmp = FALSE;
stcAdcIrqCalbaks.pfnAdcContIrq = AdcContIrqCallback; //转换完成中断入口函数
stcAdcIrqCalbaks.pfnAdcRegIrq = AdcRegIrqCallback;
stcAdcIrqCalbaks.pfnAdcHhtIrq = AdcHhtIrqCallback;
stcAdcIrqCalbaks.pfnAdcLltIrq = AdcLltIrqCallback;
Adc_ConfigIrq(&stcAdcIrq, &stcAdcIrqCalbaks); //转换中断入口函数配置
Adc_EnableIrq(); //中断使能
Adc_CmpCfg(&stcAdcIrq); //结果比较中断使能/禁止配置
stcAdcContCfg.enAdcContModeCh = AdcAVccDiV3Input; //通道0 P24
stcAdcContCfg.u8AdcSampCnt = 0x09u; //P24 连续累加次数(次数 = 0x09+1)
stcAdcContCfg.bAdcResultAccEn = TRUE; //累加使能
Adc_ConfigContMode(&stcAdcCfg, &stcAdcContCfg);
while(1)
{
Adc_Start(); //ADC开始转换
delay1ms(1000);
}
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
赞0
评论
2023-02-12
赞0
评论
2023-02-12
赞0
评论
2023-02-01
赞0
评论
2023-02-01
赞0
评论
2023-02-01
赞0
评论
2023-02-01
赞0
评论
2023-02-01
赞0
评论
2023-02-01
赞0
评论
2023-01-04
您需要登录后才可以回复 登录 | 注册