对UART3(D12 D13)如下配置时:
void UART3_Init()
{
/*---------------------------------------------------------------------------------------------------------*/
/* Init UART */
/*---------------------------------------------------------------------------------------------------------*/
/* Reset UART module */
SYS_ResetModule(UART3_RST);
/* Configure UART0 and set UART0 baud rate */
UART_Open(UART3, 115200);
/* Enable UART RDA/THRE/Time-out interrupt */
UART_EnableInt(UART3, (UART_INTEN_RDAIEN_Msk));
}
如果配置PWM1:
void PWM1_FunctionInit(void)
{
// PWM1_ClockInit();
// PWM1_IOInit();
/*
Configure PWM0 channel 0 init period and duty.
Period is PLL / (prescaler * (CNR + 1))
Duty ratio = (CMR + 1) / (CNR + 1)
Period = 72 MHz / (2 * (199 + 1)) = 180000 Hz
Duty ratio = (99 + 1) / (199 + 1) = 50%
*/
// PWM0 channel 0 frequency is 180000Hz, duty 50%,
PWM_ConfigOutputChannel(PWM1, 2, 50, 20);
PWM_ConfigOutputChannel(PWM1, 3, 50, 20);
// Enable output of PWM0 channel 0
PWM_EnableOutput(PWM1, PWM_CH_2_MASK);
PWM_EnableOutput(PWM1, PWM_CH_3_MASK);
//Start
PWM_Start(PWM1, PWM_CH_2_MASK);
PWM_Start(PWM1, PWM_CH_3_MASK);
}
会导致UART3产生一次假中断,发生了中断,进入了服务函数,但没有接收任何数据。
如果配置
PWM1_IOInit();
的话,还会导致UART3出BUG,无法发送接收:
void PWM1_IOInit(void)
{
//retarget, this is unsafe
SYS->GPD_MFPH = SYS_GPD_MFPH_PD15MFP_PWM1_CH3 | SYS_GPD_MFPH_PD14MFP_PWM1_CH2;
}
以本人拙见认为这是由于D14、D15同时也是UART的nRTS、nCTS脚,芯片逻辑设计有BUG,导致PWM1配置会影响UART,因此电路板设置应尽可能避开把UART3和PWM1同时使用的情况。(我测试的程序还同时使用了UART0,但没有产生任何的问题)
|