在新唐的NUC131系列芯片数据手册看到UART5的串口超时中断是要设置超时计数器中断使能位TIME_OUT_EN还有RX超时中断使能位TOUT_IEN,还要把定时溢出中断比较器TOIC设值,值设为0x32;
因为数据是隔50ms来24位,所以打算用串口超时中断确定那50ms,虽然用定时器也可以,但是为什么不可以,请求大神们看看!
串口初始化都在UART5_INT()函数那里,程序执行了PB12会闪烁,如果超时函数执行了那么PF5也应该要亮暗,但是PF5就是没有亮,跟公司的大佬想了两个一直没想出个所以然。
#include <stdio.h>
#include "NUC131.h"
#define PLL_CLOCK 50000000
#define RXBUFSIZE 1024
int32_t main(void);
void UART5_HANDLE(void);
void SYS_Init(void)
{
/* Enable Internal RC 22.1184MHz clock */
CLK_EnableXtalRC(CLK_PWRCON_OSC22M_EN_Msk);
/* Waiting for Internal RC clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_OSC22M_STB_Msk);
/* Switch HCLK clock source to Internal RC and HCLK source divide 1 */
CLK_SetHCLK(CLK_CLKSEL0_HCLK_S_HIRC, CLK_CLKDIV_HCLK(1));
/* Enable external XTAL 12MHz clock */
CLK_EnableXtalRC(CLK_PWRCON_XTL12M_EN_Msk);
/* Waiting for external XTAL clock ready */
CLK_WaitClockReady(CLK_CLKSTATUS_XTL12M_STB_Msk);
/* Set core clock as PLL_CLOCK from PLL */
CLK_SetCoreClock(PLL_CLOCK);
/* Enable UART module clock */
CLK_EnableModuleClock(UART2_MODULE);
CLK_EnableModuleClock(UART5_MODULE);
/* Enable peripheral clock */
CLK_EnableModuleClock(TMR0_MODULE);
/* Peripheral clock source */
CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0_S_HCLK, 0);
/* Select UART module clock source */
CLK_SetModuleClock(UART2_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
CLK_SetModuleClock(UART5_MODULE, CLK_CLKSEL1_UART_S_HXT, CLK_CLKDIV_UART(1));
/* Init I/O Multi-function */
SYS->GPA_MFP &= ~(SYS_GPA_MFP_PA12_Msk);
SYS->GPA_MFP |= (SYS_GPA_MFP_PA12_UART5_RXD);
SYS->ALT_MFP4 |= (SYS_ALT_MFP4_PA12_UART5_RXD);
SYS->GPD_MFP &= ~(SYS_GPD_MFP_PD15_Msk);
SYS->GPD_MFP |= (SYS_GPD_MFP_PD15_UART2_TXD);
}
void UART5_Init()
{
/* Reset UART5 module */
SYS_ResetModule(UART5_RST);
/* Configure UART5 and set UART5 Baudrate */
UART_SetLine_Config(UART5, 4800, UART_WORD_LEN_8, UART_PARITY_EVEN, UART_STOP_BIT_1);
//UART_EnableInt(UART5, UART_IER_RDA_IEN_Msk);
UART_EnableInt(UART5, UART_IER_RDA_IEN_Msk);
UART5->IER |= (UART_IER_TOUT_IEN_Msk);
UART5->IER |= (UART_IER_TIME_OUT_EN_Msk);
UART5->TOR = (UART5->TOR & ~UART_TOR_TOIC_Msk) | (0x32);
}
void UART2_Init()//Init UART2 for RS232
{
/* Reset UART1 module */
SYS_ResetModule(UART2_RST);
/* Configure UART1 and set UART1 Baudrate */
UART_Open(UART2, 4800);
}
int main(void)
{
/* Unlock protected registers */
SYS_UnlockReg();
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
/* Lock protected registers */
SYS_LockReg();
UART5_Init();
UART2_Init();
/* CODE */
GPIO_SetMode(PB, BIT12, GPIO_PMD_OUTPUT);
GPIO_SetMode(PF, BIT5, GPIO_PMD_OUTPUT);
GPIO_SetMode(PC, BIT0, GPIO_PMD_OUTPUT);
PF5 = 1;
PC0 = 1;
PB12 = 1;
while(1)
{
PB12= ~PB12;
TIMER_Delay(TIMER0, 500000);
}
}
void UART5_IRQHandler()
{
UART5_HANDLE();
}
void UART5_HANDLE()
{
uint8_t u8InChar = 0xFF;
uint32_t u32IntSts = UART5->ISR;
u8InChar=(u32IntSts & UART_ISR_TOUT_IF_Msk);
if(u32IntSts & UART_ISR_TOUT_INT_Msk)
{
PF5 = ~PF5;
TIMER_Delay(TIMER0, 500000);
}
else if(u32IntSts & UART_ISR_RDA_INT_Msk)
{
while(UART_IS_RX_READY(UART5))
{
u8InChar = UART_READ(UART5);
}
}
}
|