本帖最后由 assman 于 2022-3-3 16:12 编辑
我是用1.2版的,是没有遇到什么问题,CAN0、CAN1收发正常,提供给各位参考
/*---------------------------------------------------------------------------------------------------------*/
/* Init System Clock */
/*---------------------------------------------------------------------------------------------------------*/
/* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
/* Enable CAN module clock */
CLK_EnableModuleClock(CAN0_MODULE);
CLK_EnableModuleClock(CAN1_MODULE);
/*---------------------------------------------------------------------------------------------------------*/
/* Init I/O Multi-function */
/*---------------------------------------------------------------------------------------------------------*/
/* Set GPB multi-function pins for UART0 RXD and TXD */
SYS->GPB_MFP &= ~(SYS_GPB_MFP_PB0_Msk | SYS_GPB_MFP_PB1_Msk);
SYS->GPB_MFP |= SYS_GPB_MFP_PB0_UART0_RXD | SYS_GPB_MFP_PB1_UART0_TXD;
/* Set PD multi-function pins for CANTX0, CANRX0 */
SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD6_Msk | SYS_GPD_MFP_PD7_Msk);
SYS->GPD_MFP |= SYS_GPD_MFP_PD6_CAN0_RXD | SYS_GPD_MFP_PD7_CAN0_TXD;
/* Set PD multi-function pins for CANTX1, CANRX1 */
SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD14_Msk | SYS_GPD_MFP_PD15_Msk);
SYS->GPD_MFP = SYS_GPD_MFP_PD14_CAN1_RXD | SYS_GPD_MFP_PD15_CAN1_TXD;
SYS->ALT_MFP2 &= ~(SYS_ALT_MFP2_PD14_Msk | SYS_ALT_MFP2_PD15_Msk);
SYS->ALT_MFP2 = SYS_ALT_MFP2_PD14_CAN1_RXD | SYS_ALT_MFP2_PD15_CAN1_TXD;
/* Enable CAN transceiver for Nuvoton board */
PE->PMD = (GPIO_PMD_OUTPUT << 2*2) | (GPIO_PMD_OUTPUT << 3*2); // for CAN0
PE2 = 0;
PE3 = 0;
GPIO_SetMode(PE,BIT4,GPIO_PMD_OUTPUT); // for CAN1
GPIO_SetMode(PE,BIT6,GPIO_PMD_OUTPUT);
PE4 = 0;
PE6 = 0;
|
|