本帖最后由 zhangyang86 于 2010-11-21 23:56 编辑
运行新唐给的串口例程,有个地方有疑问;
发现 中断不停的发生,发生之后(u32IntStatus & DRVUART_THREINT)一直是为true的,
这是为什么???
谁知道,我大致看了一下串口的知识,没发现哪里有这样的说明!
按我的理解,当发送FIFO为空,也就是发送FIFO里面的数据消费之后这个中断发生,为什么会一直中断呢?
有谁能帮助讲解一下??
/*---------------------------------------------------------------------------------------------------------*/
/* */
/* Copyright(c) 2009 Nuvoton Technology Corp. All rights reserved. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
#include <stdio.h>
#include "Driver\DrvUART.h"
#include "Driver\DrvGPIO.h"
#include "Driver\DrvSYS.h"
#define RXBUFSIZE 1024
/*---------------------------------------------------------------------------------------------------------*/
/* Global variables */
/*---------------------------------------------------------------------------------------------------------*/
volatile uint8_t comRbuf[RXBUFSIZE];
volatile uint16_t comRbytes = 0; /* Available receiving bytes */
volatile uint16_t comRhead = 0;
volatile uint16_t comRtail = 0;
volatile int32_t g_bWait = TRUE;
uint8_t u8SendData[12] ={0};
uint8_t u8RecData[RXBUFSIZE] ={0};
int32_t w_pointer =0;
volatile int32_t r_pointer = 0;
int32_t IsRS485ISR_TX_PORT = FALSE;
int32_t IsRS485ISR_RX_PORT = FALSE;
/*---------------------------------------------------------------------------------------------------------*/
/* Define functions prototype */
/*---------------------------------------------------------------------------------------------------------*/
void UART_INT_HANDLE(uint32_t u32IntStatus);
/*---------------------------------------------------------------------------------------------------------*/
/* UART Callback function */
/*---------------------------------------------------------------------------------------------------------*/
void UART_INT_HANDLE(uint32_t u32IntStatus)
{
uint8_t bInChar[1]={0xFF};
if(u32IntStatus & DRVUART_RDAINT)
{
/* Get all the input characters */
while(UART0->ISR.RDA_IF==1)
{
/* Get the character from UART Buffer */
DrvUART_Read(UART_PORT0,bInChar,1);
if(bInChar[0] == '0')
{
g_bWait = FALSE;
}
/* Check if buffer full */
if(comRbytes < RXBUFSIZE)
{
/* Enqueue the character */
comRbuf[comRtail] = bInChar[0];
comRtail = (comRtail == (RXBUFSIZE-1)) ? 0 : (comRtail+1);
comRbytes++;
}
}
}
else if(u32IntStatus & DRVUART_THREINT)
{
uint16_t tmp;
tmp = comRtail;
if(comRhead != tmp)
{
bInChar[0] = comRbuf[comRhead];
DrvUART_Write(UART_PORT0,bInChar,1);
comRhead = (comRhead == (RXBUFSIZE-1)) ? 0 : (comRhead+1);
comRbytes--;
}
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* UART Function Test */
/*---------------------------------------------------------------------------------------------------------*/
void UART_FunctionTest()
{
/* Enable Interrupt and install the call back function */
DrvUART_EnableInt(UART_PORT0, (DRVUART_RLSINT | DRVUART_THREINT | DRVUART_RDAINT),UART_INT_HANDLE);
while(g_bWait);
/* Disable Interrupt */
DrvUART_DisableInt(UART_PORT0,DRVUART_RLSINT | DRVUART_THREINT | DRVUART_RDAINT);
g_bWait =TRUE;
}
/*---------------------------------------------------------------------------------------------------------*/
/* UART Test Sample */
/* Test Item */
/* It sends the received data to HyperTerminal. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t main()
{
// int8_t item;
STR_UART_T sParam;
/* SYSCLK =>12Mhz*/
UNLOCKREG();
SYSCLK->PWRCON.XTL12M_EN = 1;
/* Run 48Mhz */
DrvSYS_Open(48000);
/* Set UART Pin */
DrvGPIO_InitFunction(E_FUNC_UART0);
/* UART Setting */
sParam.u32BaudRate = 19200;
sParam.u8cDataBits = DRVUART_DATABITS_8;
sParam.u8cStopBits = DRVUART_STOPBITS_1;
sParam.u8cParity = DRVUART_PARITY_NONE;
sParam.u8cRxTriggerLevel= DRVUART_FIFO_1BYTES;
/* Set UART Configuration */
if(DrvUART_Open(UART_PORT0,&sParam) != E_SUCCESS)
{
return FALSE;
}
DrvGPIO_Open(E_PORT3,E_PIN6,E_IO_OUTPUT) ;
DrvGPIO_ClrBit(E_PORT3,E_PIN6);
DrvSYS_Delay(500000);
DrvGPIO_SetBit(E_PORT3,E_PIN6);
DrvSYS_Delay(500000);
do
{
DrvSYS_Delay(500000);
DrvGPIO_SetBit(E_PORT3,E_PIN6);
DrvSYS_Delay(500000);
DrvGPIO_ClrBit(E_PORT3,E_PIN6);
UART_FunctionTest();
}while(g_bWait);
}
} |