在main函数中调用UART0Ini,就实现自动发送数据
现在发送前16BYTE数据成功,然后就进不了U0THR空的中断~~~
大家帮看一下,问题出在哪?是不是通常情况下很少用中断方式来发送数据?
/*********UART mode config struct********/
typedef struct _UARTMode
{
uint8 nDataBits;//frame data length in bits,5/6/7/8
uint8 nStopBits;//stop bits,1/2
uint8 Parity;//0:no parity,1:odd parity,2:even parity
}UARTMode;
/*****Pointing to the byte to send next******/
uint8* pCur;
/*****Position of the byte to send next******/
uint16 nPos;
/*****Flag to tell that buffer needs to be freshed again******/
uint8 bEmpty;
uint8 pBuf[BLOCKSIZE];
/*****Initialize the buffer for send*****/
void BufIni()
{
uint16 nCnt;
for(nCnt=0;nCnt <BLOCKSIZE;nCnt++)
pBuf[nCnt] = (nCnt > > 1);
bEmpty = 0;
}
//配置IO端口,选通UART0
void InitIOport()
{
PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x00000005;
}
//设置中断寄存器
void IRQConf()
{
VICIntSelect = 0x00000000;
VICVectCntl0 = 0x20 | 6;
VICVectAddr = (uint32)IRQ_UART0_Send;
VICIntEnable = 0x00000040;
U0FCR = 0x81;
U0IER = 0x02;
}
//设置波特率
void SetBaud(uint32 nBaud)
{
uint32 temp;
U0LCR = 0x80;
temp = (Fpclk > > 4) / nBaud;
U0DLM = temp > > 8;
U0DLL = temp & 0xff;
}
//设置串口工作方式
void SetUART0Mode(UARTMode stUART0M)
{
uint8 Ctrl;
Ctrl = stUART0M.nDataBits - 5;
if(stUART0M.nStopBits == 2)
Ctrl |= 0x04;
if(0 != stUART0M.Parity)
{
Ctrl |= 0x08;
stUART0M.Parity --;
}
Ctrl |= (stUART0M.Parity < < 4);
U0LCR = Ctrl;
U0FCR = 0x81;
}
//初始发送16字节数据
void SendBuf()
{
uint8 i;
pCur = pBuf;
for(i=0;i <16;i++)
{
U0THR = *pCur;
pCur ++;
}
nPos += 16;
if(nPos > = 512)
{
nPos = 0;
pCur = pBuf;
bEmpty = 1;
}
}
/*****irq func. for sending data from UART0,using FIFO mode******/
void __irq IRQ_UART0_Send()
{
uint8 i;
if(bEmpty == 1)
return;
if(0x02 == (U0IIR & 0x0f))
{
for(i=0;i <8;i++)
{
U0THR = *pCur;
pCur ++;
}
nPos += 8;
if(nPos > = 512)
{
nPos = 0;
pCur = pBuf;
bEmpty = 1;
}
}
VICVectAddr = 0x00;
}
//UART0初始化和开始发送数据
void UART0_Ini()
{
UARTMode stMode;
BufIni();
InitIOport();
SetBaud(115200);
stMode.nDataBits = 8;
stMode.nStopBits = 1;
stMode.Parity = 0;
SetUART0Mode(stMode);
IRQConf();
SendBuf();
}