/* Unlock protected registers */
SYS_UnlockReg();
/* Enable clock source */
CLK_EnableXtalRC(CLK_PWRCON_OSC10K_EN_Msk|CLK_PWRCON_OSC22M_EN_Msk|CLK_PWRCON_XTL12M_EN_Msk);
/* Waiting for clock source ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC10K_STB_Msk|CLK_CLKSTATUS_OSC22M_STB_Msk|CLK_CLKSTATUS_XTL12M_STB_Msk);
/* Disable PLL first to avoid unstable when setting PLL */
CLK_DisablePLL();
/* Set PLL frequency */
CLK->PLLCON = (CLK->PLLCON & ~(0x000FFFFFul)) | 0x00004217ul;
/* Waiting for PLL ready */
CLK_WaitClockReady(CLK_CLKSTATUS_PLL_STB_Msk);
/* If the defines do not exist in your project, please refer to the related clk.h in the clk_h folder appended to the tool package. */
/* Set HCLK clock */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_PLL, CLK_CLKDIV_HCLK(1));
/* Enable IP clock */
CLK_EnableModuleClock(ISP_MODULE);
CLK_EnableModuleClock(TMR0_MODULE);
//CLK_EnableModuleClock(UART0_MODULE);
CLK_EnableModuleClock(UART1_MODULE);
CLK_EnableModuleClock(ADC_MODULE);
/* Set IP clock */
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HXT, MODULE_NoMsk);
//CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(UART1_MODULE, CLK_CLKSEL1_UART_S_PLL, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADC_S_HCLK, CLK_CLKDIV_ADC(2048));
/* Update System Core Clock */
/* User can use SystemCoreClockUpdate() to calculate SystemCoreClock. */
SystemCoreClockUpdate();
/* Lock protected registers */
SYS_LockReg();
/*---------------------------------------------------------------------------------------------------------*/
/* Init TIMER Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Open Timer0 frequency to 1 Hz in periodic mode, and enable interrupt */
TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 250);
TIMER_EnableInt(TIMER0);
/* Enable Timer0 NVIC */
NVIC_EnableIRQ(TMR0_IRQn);
/* Start Timer0 counting */
TIMER_Start(TIMER0);
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set P3 multi-function pins for UART0 RXD, TXD */
SYS->P3_MFP = SYS_MFP_P30_RXD0 | SYS_MFP_P31_TXD0;
GPIO_SetMode(P3,BIT6,GPIO_PMD_OUTPUT);
GPIO_SetMode(P0,BIT4,GPIO_PMD_OUTPUT);
GPIO_SetMode(P0,BIT5,GPIO_PMD_OUTPUT);
GPIO_SetMode(P0,BIT7,GPIO_PMD_OUTPUT);
/* Set P1 multi-function pins for UART1 RXD and TXD */
SYS->P1_MFP &= ~(SYS_MFP_P12_Msk | SYS_MFP_P13_Msk);
SYS->P1_MFP |= (SYS_MFP_P12_RXD1 | SYS_MFP_P13_TXD1);
/* Set P0 multi-function pins for UART1 RTS */
SYS->P0_MFP = SYS->P0_MFP & (~SYS_MFP_P01_Msk) | SYS_MFP_P01_RTS1;
/* Disable the P1.0 - P1.1 digital input path to avoid the leakage current */
GPIO_DISABLE_DIGITAL_PATH(P1, 0x3);
/* Configure the P1.0 - P1.3 ADC analog input pins */
SYS->P1_MFP &= ~(SYS_MFP_P10_Msk | SYS_MFP_P11_Msk);
SYS->P1_MFP |= SYS_MFP_P10_AIN0 | SYS_MFP_P11_AIN1 ;
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset UART1 module */
SYS_ResetModule(UART1_RST);
/* Configure UART1 and set UART1 Baudrate */
UART_Open(UART1, 9600);
/* Set RS485-Master as AUD mode */
/* Enable AUD mode to HW control RTS pin automatically */
/* You also can use GPIO to control RTS pin for replacing AUD mode*/
UART_SelectRS485Mode(UART1, UART_ALT_CSR_RS485_AUD_Msk, 44);
/* Set RTS pin active level as high level active */
UART1->MCR &= ~UART_MCR_LEV_RTS_Msk;
UART1->MCR |= UART_RTS_IS_LOW_LEV_ACTIVE;
/* Set UART parity as SPACE and ship baud rate setting */
UART_SetLine_Config(UART1, 9600, UART_WORD_LEN_8, UART_PARITY_NONE, UART_STOP_BIT_1);
/*设置接收超时时间为40,单位波特率*/
UART_SetTimeoutCnt(UART1, 127);
///*设置接收FIFO触发级别为8B*/
UART1->FCR &= ~UART_FCR_RFITL_Msk;
UART1->FCR |= UART_FCR_RFITL_8BYTES;
/*使能接收FIFO 阀值中断,和接收超时中断*/
UART_ENABLE_INT(UART1, (UART_IER_RDA_IEN_Msk | UART_IER_RTO_IEN_Msk));
NVIC_EnableIRQ(UART1_IRQn);
/*---------------------------------------------------------------------------------------------------------*/
/* Init ADC */
/*---------------------------------------------------------------------------------------------------------*/
/* Set the ADC operation mode as single, input mode as single-end and enable the analog input channel 0 */
ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END, ADC_ADCR_ADMD_SINGLE, 1<<0);
/* Power on ADC module */
ADC_POWER_ON(ADC);
/* clear the A/D interrupt flag for safe */
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);
/* Start A/D conversion */
ADC_START_CONV(ADC);
以上为初始化部分
下面为ADC单次采集,获取结果后再次启动采集,已获取多次结果累积。
以下函数上电后,有获取一次或数次结果,就无法再进入了。
void module_adc (void)
{
if (ADC_GET_INT_FLAG(ADC,ADC_ADF_INT))
{
ADC_CLR_INT_FLAG(ADC,ADC_ADF_INT);
glv_temp1 = ADC_GET_CONVERSION_DATA(ADC,0);
ADC_START_CONV(ADC);
}
}
函数入口判定试了,ADC_GET_INT_FLAG,ADC_IS_BUSY,ADC_IS_DATA_OVERRUN,ADC_IS_DATA_VALID都是进入一次或数次,然后就不再进入了。
找了一整天的问题,都没找出原因,请老师们帮帮忙,谢谢。
|
|