感謝你得回覆
不過目前 我int0 無法觸發
int1 可以正常觸發 使用的是nano103 48PIN MCU
我的程式如下,實在查不出 為何int0 無法用pb8觸發
void Clock_init(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
//must set to defual first, ontherwise the Port F can't be set
/* Enable External XTAL (4~24 MHz) */
CLK_EnableXtalRC(CLK_PWRCTL_HXTEN_Msk);
/* Enable External LXT (32 KHz) */
CLK->PWRCTL |= CLK_PWRCTL_LXTEN_Msk; //
CLK_EnableXtalRC(CLK_PWRCTL_HIRC0FSEL_Msk); //run 16Mhz
CLK_WaitClockReady(CLK_STATUS_LIRCSTB_Msk|CLK_STATUS_HIRC0STB_Msk);
CLK->CLKSEL0 = CLK->CLKSEL0 & ~CLK_CLKSEL0_HIRCSEL_Msk;
/* Switch HCLK clock source to XTAL */
CLK->CLKSEL0 = (CLK->CLKSEL0 &~ CLK_CLKSEL0_HCLKSEL_Msk) | (CLK_CLKSEL0_HCLKSEL_HXT);
CLK_EnableXtalRC(CLK_PWRCTL_LIRCEN_Msk|CLK_PWRCTL_HIRC0EN_Msk|CLK_PWRCTL_MIRCEN_Msk);
//// /* Enable clock source */
CLK_EnableXtalRC(CLK_PWRCTL_LIRCEN_Msk|CLK_PWRCTL_HIRC0EN_Msk|CLK_PWRCTL_MIRCEN_Msk);
/* Waiting for clock source ready */
CLK_WaitClockReady(CLK_STATUS_LIRCSTB_Msk|CLK_STATUS_HIRC0STB_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_HCLKSEL_HIRC, CLK_HCLK_CLK_DIVIDER(1));
/* Enable IP clock */
/* UART0 */
CLK_EnableModuleClock(UART0_MODULE);
CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HIRC, CLK_UART0_CLK_DIVIDER(1));
/************int0 *************************/
SYS->GPB_MFPH &= ~( SYS_GPB_MFPH_PB8MFP_Msk );
SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB8MFP_INT0);
/************int1 *************************/
SYS->GPB_MFPH &= ~( SYS_GPB_MFPH_PB15MFP_Msk );
SYS->GPB_MFPH |= (SYS_GPB_MFPH_PB15MFP_INT1);
SystemCoreClockUpdate();
/* Lock protected registers */
SYS_LockReg();
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPB multi-function pins for UART0 RXD and TXD */
SYS->GPB_MFPL &= ~(SYS_GPB_MFPL_PB0MFP_Msk | SYS_GPB_MFPL_PB1MFP_Msk); //clear pb0 & pb1 bit
SYS->GPB_MFPL |= (SYS_GPB_MFPL_PB0MFP_UART0_RXD | SYS_GPB_MFPL_PB1MFP_UART0_TXD); //PB0 & PB1 UAR0
}
void EINT0_IRQHandler(void)
{
printf("int0 trigger \r");
/* For PB.8, clear the INT flag */
PB->INTSRC = BIT8;
//NVIC_EnableIRQ(EINT0_IRQn);
}
void EINT1_IRQHandler(void)
{
//printf("int1 trigger \r");
/* For PB.15, clear the INT flag */
PB->INTSRC = BIT15;
NVIC_EnableIRQ(EINT1_IRQn);
}
int main(void)
{
Clock_init();
//int0
GPIO_SetMode(PB, BIT8, GPIO_PMD_INPUT);
GPIO_EnableEINT0(PB, 8, GPIO_INT_FALLING);
NVIC_EnableIRQ(EINT0_IRQn);
//int1
GPIO_SetMode(PB, BIT15, GPIO_PMD_INPUT);
GPIO_EnableEINT0(PB, 15, GPIO_INT_FALLING);
NVIC_EnableIRQ(EINT1_IRQn);
GPIO_SET_DEBOUNCE_TIME(GPIO_DBCLKSRC_HCLK, GPIO_DBCLKSEL_1);
GPIO_ENABLE_DEBOUNCE(PB, BIT8);
UART_Open(UART0, 115200);
printf("\n\nCPU @ %dHz\n", SystemCoreClock);
while(1)
{
// printf("test start \r\n");
}
}
|