About the serial
For developers of embedded devices, the beginning of a lot of equipment are not available, unable to get the program running, the debugger takes a lot of time and effort, so the role of the serial port for debugging embedded programs is obvious, when the serial port can not be used, may only a slight indication of the program running with the light off to led after with serial port, you can get more debugging information. S3C6410 serial port and other equipment used are similar, the initial configuration after the serial port can send and receive the data. First, look at the serial block diagram of the chip Manual:
serial transmission data signal lines, the TXDn signal lines, data signal lines receiving RXDn, as shown above, these two signal lines are connected to the transmit shift register and a receive shift register, serial addition further comprising a FIFO module is used to send and receive data 64Bytes two. In addition to a control unit in addition to generating module and the baud rate, corresponding parts are connected to the upper peripheral bus system.
Serial register
First look at the relevant register:
S3C6410 has UART0,1,2,3 four serial ports, above only lists the relevant register in serial-0, several other serial register descriptions and this, like, let's say in detail below:
###### ULCONx: serial data formatting data length, the stop bit length, parity bits
UCONx: serial control clock source selection register, transmit and receive mode
UFCONx: FIFO Control Register Set Enable FIFO trigger level
UTRSTATx: transmitting and receiving status register
UERSTATx: frame error status register error, parity errors
UFSTATx: FIFO Status Register
UTXx: transmit data register data to be transmitted it threw
URXx: receiving data register to obtain the data received from the register
UBRDIV: baud rate divisor value register
UDIVSLOT: baud rate divisor value fractional part (I'm from the name ...)
Serial port initialization
Serial port initialization tasks to be done mainly in the following:
- Configuring GPIO pin function is related to the serial port functions
- Provided ULCONx serial data format to set the register, the data bit length, stop bit length, parity bits, etc.
- Set the serial port control register UCONx, serial clock source select, send and receive data modes: an interrupt, polling, interrupts the DMA
- Set the baud rate frequency division number register and fractional part of the division value of the baud rate register
- FIFO control register set, whether the FIFO is enabled and the like
###### baud rate is set
baud rate divisor value:
DIV_VAL = (the PCLK / (bps 16)) -. 1
EG:
the PCLK = 66.5M = 66.5 million
bps baud rate = 115200
DIV_VAL = (66500000/115200 16) -1 = 35.078
UBRDIVn = 35
fractional part of 0.078
UDIVSLOTn 1 divided by the number of = 0.078 16
UDIVSLOTn the number of 1s = 1 = 1.248
according to the table, so that a value of 0x0080 UDIVSLOTn;
Code
void uart_init(void)
{
GPACON &= ~0xff;
GPACON |= 0x22;
ULCON0 = 0x3; /* 数据位:8, 无较验, 停止位: 1, 8n1 */
UCON0 = 0x5; /* 使能UART发送、接收 */
UFCON0 = 0x01; /* FIFO ENABLE */
UMCON0 = 0;
/* 波特率 */
/* DIV_VAL = (PCLK / (bps x 16 ) ) - 1
* bps = 115200
* DIV_VAL = (66000000 / (115200 x 16 ) ) - 1
* = 35.08
*/
UBRDIV0 = (int)(PCLK/(BOUD*16)-1);
/* x/16 = 0.08
* x = 1
*/
UDIVSLOT0 = 0x1;
}
void putc(unsigned char c)
{
while (UFSTAT0 & (1<<14)); /* 如果TX FIFO满,等待 */
UTXH0 = c; /* 写数据 */
}
unsigned char getc(void)
{
unsigned char ret;
while ((UFSTAT0 & 0x7f) == 0); /* 如果RX FIFO空,等待 */
ret = URXH0; /* 取数据 */
if((ret == 0x0d) || (ret == 0x0a))
{
putc(0x0d);
putc(0x0a);
}
else
{
putc(ret);
}
return ret;
}
void uart_send_string(char *str)
{
while(*str)
{
putc(*str++);
}
putc(0x0d);
putc(0x0a);
}
Reprint please indicate the original content Chai Kun-yan and the source http://ykzhai.top/2016/08/15/ Development / Embedded / s3c6410 / 15-uboot-study- serial port initialization /