S3C2440的串口比较简单,基本上就是波特率、数据位、校验位、通道号、停止位配置OK即可
//===================================================================
// File Name : 2440lib.c
// Function : S3C2410 PLL,Uart, LED, Port Init
// Date : March 20, 2002
// Version : 0.0
// History
// 0.0 : Programming start (February 20,2002) -> SOP
//===================================================================
//#define GLOBAL_CLK 1//hzh
#include "UART.h"
//***************************[ UART ]******************************
static int whichUart=0;
static char str[30];
void __irq UART_INT (void);
/*************************************************************************************
***函数名:Uart_Init()
***功能:串口初始化,波特率 115200 8位数据位,无校验位,1位停止位
***参数:ch 串口通道号
***返回:无
*************************************************************************************/
void Uart_Init(int pclk,int baud)
{
int i;
if(pclk == 0)
pclk = PCLK;
//*** PORT H GROUP
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : CLKOUT1 CLKOUT0 UCLK nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10 , 10 10 , 11 11 , 10 10 , 10 10 , 10 10
rGPHCON = 0x00aaaa;
rGPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
rUFCON0 = 0x0; //UART channel 0 FIFO control register, FIFO disable
rUFCON1 = 0x0; //UART channel 1 FIFO control register, FIFO disable
rUFCON2 = 0x0; //UART channel 2 FIFO control register, FIFO disable
rUMCON0 = 0x0; //UART chaneel 0 MODEM control register, AFC disable
rUMCON1 = 0x0; //UART chaneel 1 MODEM control register, AFC disable
//UART0
rULCON0 = 0x3; //Line control register : Normal,,No parity1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
rUCON0 = 0x245; // Control register
rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 ); // Baud rate divisior register 0
//UART1
rULCON1 = 0x3; //不采用红外线传输模式,无奇偶校验位,1个停止位,8个数据位
rUCON1 = 0x245; //发送中断为电平方式,接收中断为边沿方式,禁止超时中断,允许产生错误状态中断,禁止回送模式,禁止中止 //信号,传输模式为中断请求模式,接收模式也为中断请求模式。
rUBRDIV1=( (int)(pclk/16./baud+0.5) -1 );
//UART2
rULCON2 = 0x3; //不采用红外线传输模式,无奇偶校验位,1个停止位,8个数据位
rUCON2 = 0x245; //发送中断为电平方式,接收中断为边沿方式,禁止超时中断,允许产生错误状态中断,禁止回送模式,禁止中止 //信号,传输模式为中断请求模式,接收模式也为中断请求模式。
rUBRDIV2=( (int)(pclk/16./baud+0.5) -1 );
for(i=0;i<100;i++);
}
/*************************************************************************************
***函数名:Uart_Select()
***功能:串口选择。函数里面的whichUart在后面的函数中有引用,决定用哪个UART。
***参数:ch 串口通道号
***返回:无
********************