就是使用这个hc32l110的ADC模块来进行电压数据采集,然后把数据通过uart在串口上打印。但是不知道为什么我写的代码在获取电压数据,打印出来一直为0,电路是没什么问题的。
#include "ddl.h"
#include "uart.h"
#include "bt.h"
#include "lpm.h"
#include "gpio.h"
#include "adc.h"
#define T1_PORT (3)
#define T1_PIN (3)
static uint16_t u16ScanResult[8];
uint8_t u8Rx**=0;
uint8_t Check**=0;
uint8_t u8RxData[3]={0x11,0x22,0X33};
void AdcContIrqCallback(void)
{
Adc_GetScanResult(0,&u16ScanResult[0]);
M0P_ADC->CR0_f.STATERST = 1u;
M0P_BT1->ICLR_f.TFC = 0;
}
void RxIntCallback(void)
{
u8RxData[2]=M0P_UART1->SBUF;
u8Rx** = 1;
}
void ErrIntCallback(void)
{
}
void AdcRegIrqCallback(void)
{
}
void AdcHhtIrqCallback(void)
{
}
void AdcLltIrqCallback(void)
{
}
int32_t main(void)
{
uint16_t timer=0;
uint32_t pclk=0;
uint16_t u16ArrData2;
uint16_t u16InitCntData2;
stc_adc_cfg_t stcAdcCfg ;
stc_adc_scan_cfg_t stcAdcScanCfg ;
stc_adc_irq_t stcAdcIrq ;
stc_adc_irq_calbakfn_pt_t stcAdcIrqCalbaks;
stc_bt_config_t stcBtConfig ;
stc_uart_config_t stcConfig ;
stc_uart_irq_cb_t stcUartIrqCb ;
stc_uart_multimode_t stcMulti ;
stc_uart_baud_config_t stcBaud ;
DDL_ZERO_STRUCT(stcAdcCfg);
DDL_ZERO_STRUCT(stcAdcScanCfg);
DDL_ZERO_STRUCT(stcAdcIrq);
DDL_ZERO_STRUCT(stcAdcIrqCalbaks);
DDL_ZERO_STRUCT(stcUartIrqCb);
DDL_ZERO_STRUCT(stcMulti);
DDL_ZERO_STRUCT(stcBaud);
DDL_ZERO_STRUCT(stcBtConfig);
Clk_SwitchTo(ClkRCL);
Clk_SetRCHFreq(ClkFreq24Mhz);
Clk_SwitchTo(ClkRCH);
Gpio_SetAnalog(2, 4, TRUE);
Adc_Enable();
M0P_BGR->CR_f.BGR_EN = 0x1u;
M0P_BGR->CR_f.TS_EN = 0x0u;
delay100us(1);
stcAdcCfg.enAdcOpMode = AdcScanMode;
stcAdcCfg.enAdcClkSel = AdcClkSysTDiv1;
stcAdcCfg.enAdcSampTimeSel = AdcSampTime8Clk;
stcAdcCfg.enAdcRefVolSel = RefVolSelAVDD;
stcAdcCfg.bAdcInBufEn = FALSE;
stcAdcCfg.enAdcTrig0Sel = AdcTrigTimer2;
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);
stcAdcScanCfg.u8AdcScanModeCh = ADC_SCAN_CH1_EN;
stcAdcScanCfg.u8AdcSampCnt = 0x1;
Adc_ConfigScanMode(&stcAdcCfg, &stcAdcScanCfg);
Gpio_InitIO(T1_PORT,T1_PIN,GpioDirIn);
Gpio_InitIO(0,3,GpioDirOut);
Gpio_SetIO(0,3,1);
Gpio_InitIOExt(3,5,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_InitIOExt(3,6,GpioDirOut,TRUE,FALSE,FALSE,FALSE);
Gpio_SetFunc_UART1TX_P35();
Gpio_SetFunc_UART1RX_P36();
Clk_SetPeripheralGate(ClkPeripheralBt,TRUE);
Clk_SetPeripheralGate(ClkPeripheralUart1,TRUE);
if (Ok != Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE))
{
return Error;
}
stcUartIrqCb.pfnRxIrqCb = RxIntCallback;
stcUartIrqCb.pfnTxIrqCb = NULL;
stcUartIrqCb.pfnRxErrIrqCb = ErrIntCallback;
stcConfig.pstcIrqCb = &stcUartIrqCb;
stcConfig.bTouchNvic = TRUE;
stcConfig.enRunMode = UartMode3;
stcMulti.enMulti_mode = UartNormal;
stcConfig.pstcMultiMode = &stcMulti;
stcBaud.bDbaud = 0u;
stcBaud.u32Baud = 2400U;
stcBaud.u8Mode = UartMode3;
pclk = Clk_GetPClkFreq();
timer=Uart_SetBaudRate(UARTCH1,pclk,&stcBaud);
stcBtConfig.enMD = BtMode2;
stcBtConfig.enCT = BtTimer;
Bt_ClearIntFlag(TIM1);
Bt_EnableIrq(TIM1);
Bt_Init(TIM1, &stcBtConfig);
Bt_ARRSet(TIM1,timer);
Bt_Cnt16Set(TIM1,timer);
Uart_Init(UARTCH1, &stcConfig);
Uart_EnableIrq(UARTCH1,UartRxIrq);
Uart_ClrStatus(UARTCH1,UartRxFull);
Uart_EnableFunc(UARTCH1,UartRx);
stcBtConfig.enGateP = BtPositive;
stcBtConfig.enGate = BtGateDisable;
stcBtConfig.enPRS = BtPCLKDiv256;
stcBtConfig.enTog = BtTogDisable;
stcBtConfig.enCT = BtTimer;
stcBtConfig.enMD = BtMode2;
Bt_Init(TIM2, &stcBtConfig);
Bt_ClearIntFlag(TIM2);
Bt_EnableIrq(TIM2);
u16ArrData2 = 0x10000 - 9375;
u16InitCntData2 = 0x10000 - 9375;
Bt_ARRSet(TIM2, u16ArrData2);
Bt_Cnt16Set(TIM2, u16InitCntData2);
Bt_Run(TIM2);
Bt_Run(TIM1);
while(1)
{
Adc_Start();
Check** = 0;
u8RxData[1] = (u16ScanResult[1] >> 8 );
u8RxData[0] = (u16ScanResult[1] & 0xFF);
if(u8Rx**)
{
u8Rx** = 0;
if(Uart_CheckEvenOrOdd(UARTCH1,Even,u8RxData[2])!=Ok)
{
Check** = 1;
}
else
{
Uart_SetTb8(UARTCH1,Even,u8RxData[0]);
Uart_SendData(UARTCH1,u8RxData[0]);
Uart_SetTb8(UARTCH1,Even,u8RxData[1]);
Uart_SendData(UARTCH1,u8RxData[1]);
Uart_SetTb8(UARTCH1,Even,u8RxData[2]);
Uart_SendData(UARTCH1,u8RxData[2]);
}
}
}
}
|
|