MCU_S3C2410之UART分析
寄存器分析
本文引用地址:http://m.butianyuan.cn/article/201611/316923.htm代碼分析
///////////////////////////////////////////////////////////////////////UART 初始化/////////////////////////////////////////////////////////////////////////////////////
voidUart_Init(int pclk,int baud)
{
int i;
if(pclk == 0)
pclk = PCLK; //APB IS USED FOR APB
rUFCON0 = 0x0;//關(guān)閉UART0的FIFO
rUFCON1 = 0x0;//關(guān)閉UART1的FIFO
rUFCON2 = 0x0;//關(guān)閉UART2的FIFO
rUMCON0 = 0x0;//關(guān)閉UART0自動(dòng)流控制AFC (一般不進(jìn)行握手協(xié)議控制)
rUMCON1 = 0x0;//關(guān)閉UART1自動(dòng)流控制AFC (UART2沒有自動(dòng)流控制功能)
//UART0
rULCON0 = 0x3; //Normal,No parity,1 stop bit,8 bits da
rUCON0 = 0x245;
Transmit MODE:發(fā)送模式有請(qǐng)求中斷發(fā)送和請(qǐng)求DMA發(fā)送
TX interrupt Type :當(dāng)發(fā)送保持寄存器為空時(shí)(Non-FIFO MODE)或達(dá)到TX FIFO觸發(fā)水平時(shí)觸發(fā)中斷的電平類型
(TX FIFO觸發(fā)水平:00 = Empty 01 = 4-byte 10 = 8-byte 11 = 12-byte in UFCONn)
Receive MODE 接收模式有請(qǐng)求中斷讀取和請(qǐng)求DMA讀取
RX interrupt Type :當(dāng)接收保持寄存器為空時(shí)(Non-FIFO MODE)或達(dá)到RX FIFO觸發(fā)水平時(shí)觸發(fā)中斷的電平類型(RX FIFO觸發(fā)水平:00 = 4-byte 01 = 8-byte 10 = 12-byte 11 = 16-byte in UFCONn)
rUBRDIV0=( (int)(pclk/16/baud) -1 );
//UART1
rULCON1 = 0x3;
rUCON1 = 0x245;
rUBRDIV1=( (int)(pclk/16/baud) -1 );
//UART2
rULCON2 = 0x3;
rUCON2 = 0x245;
rUBRDIV2=( (int)(pclk/16/baud) -1 );
for(i=0;i<100;i++);
}
總結(jié)UART的控制寄存器:有ULCON、UCON、UFCON、UMCON、UBRDIV
///////////////////////////////////////////////////////////////////////UART 初始化////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////UART 發(fā)送////////////////////////////////////////////////////////////////////////////////////
voidUart_SendByte(int da
{
if(whichUart==0)
{
if(da
{
while(!(rUTRSTAT0 & 0x2));
non FIFO=1 Byte BUFFER REGISTER(HOLDING REGISTER)+SHIFTER REGISTER
FIFO mode = 16 Byte BUFFER REGISTER(FIFO REGISTER)+SHIFTER REGISTER
Delay(10); //because the slow response of hyper_terminal
WrUTXH0( );
}
while(!(rUTRSTAT0 & 0x2)); //Wait until THR is empty.
Delay(10);
WrUTXH0(da
}
else if(whichUart==1)
{
if(da
{
while(!(rUTRSTAT1 & 0x2));
Delay(10); //because the slow response of hyper_terminal
rUTXH1 = ;
}
while(!(rUTRSTAT1 & 0x2)); //Wait until THR is empty.
Delay(10);
rUTXH1 = da
}
else if(whichUart==2)
{
if(da
{
while(!(rUTRSTAT2 & 0x2));
Delay(10); //because the slow response of hyper_terminal
rUTXH2 = ;
}
while(!(rUTRSTAT2 & 0x2)); //Wait until THR is empty.
Delay(10);
rUTXH2 = da
}
}
///////////////////////////////////////////////////////////////////////UART 發(fā)送////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////UART 接收////////////////////////////////////////////////////////////////////////////////////
charUart_Getch(void)
{
if(whichUart==0)
{
while(!(rUTRSTAT0 & 0x1)); //Receive da
return RdURXH0();
}
else if(whichUart==1)
{
while(!(rUTRSTAT1 & 0x1)); //Receive da
return RdURXH1();
}
else if(whichUart==2)
{
while(!(rUTRSTAT2 & 0x1)); //Receive da
return RdURXH2();
}
}
///////////////////////////////////////////////////////////////////////UART 接收////////////////////////////////////////////////////////////////////////////////////
總結(jié)UART有狀態(tài)寄存器UTRSTAT、UERSTAT、UFSTAT、UMSTAT
有數(shù)據(jù)寄存器UTXH和URXH
評(píng)論