Implementation of S3C2440 serial communication

Publisher:创新思维Latest update time:2020-02-08 Source: eefocusKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Purpose

Due to project requirements, it is necessary to realize the communication between the S3C2440 serial port and the PC. Through the serial port communication examples in the experiment manual, understand the working principle of the serial port and implement a simple serial port communication experiment. Prepare for further use of serial port programming to achieve more complex functions.


Experimental effect: Press any key on the PC, and the character will be transmitted to 2440 through the serial port. 2440 will return to the PC through the serial port, and the character will be displayed in the DNW terminal or hyperterminal.


2. Experimental Principle

PC <-------> S3C2440 development board

The S3C2440 UART provides three independent asynchronous serial I/O ports, each of which can operate in interrupt and DMA modes, and the highest baud rate they support is 115.2Kbps. Each UART channel contains two 64-byte FIFOs, which provide data reception and transmission respectively.


Each UART contains a baud rate generator, a receiver, a transmitter, and a control unit. The baud rate generator uses MCLK as the clock source. The transmitter and receiver contain a 64-byte FIFO register and a shift register. When sending data, the data is first written to the FIFO, then copied to the transmit shift register, and then shifted out from the data output port (TxDn) in sequence. The received data is also shifted from the receive port (RxDn) to the shift register, and then copied to the FIFO.


1. Data sending operation

The format of the data transmission frame is programmable and contains a start bit, 5 to 8 data bits, an optional parity bit and 1 or 2 stop bits, which can be set by the linear controller (ULCONn).

2. Data receiving operation

As with data transmission, the framing of data reception is programmable. The receiver can detect overrun errors, parity errors, framing errors, and break conditions, each of which will cause an error flag to be set.

3. Baud rate generator

The baud rate generator of each UART provides the serial shift clock for transmission. The clock source of the baud rate generator can be selected from the internal system clock of the S3C2440 or UEXTCLK. The baud rate is determined by dividing the clock source (PCLK, FCLK, or UEXTCLK) by 16 and the 16-bit divisor specified by the UART baud rate divisor register (UBRDIVn). The value of UBRDIVn can be determined as follows:

UBRDIVn = (int)(UART clock/(bps*16)) – 1

(UART clock is PCLK, FCLK or UEXTCLK) The divisor range is 1 to (216-1).

For example, if the baud rate is 115200bps and the UART is 40MHz, then UBRDIVn is:

UBRDIVn =(int)(40000000/(115200*16))-1

              = (int)(21.7) – 1

              = 22 – 1

              = 21

3. Code Implementation

Main program part: serial.c

#define ULCON0 (*(volatile unsigned *)0X50000000) //UART line control register
#define UCON0 (*(volatile unsigned *)0X50000004) //UART control register
#define UFCON0 (*(volatile unsigned *)0X50000008) //FIFO control register
#define UTRSTAT0 (*(volatile unsigned*)0X50000010) //UART status register
#define UBRDIV0 (*(volatile unsigned *)0X50000028) //Baud rate
#define UTXH0 (*(volatile unsigned *)0X50000020) //Send data register 8 bits
#define URXH0 (*(volatile unsigned *)0X50000024) //Receive data register 8 bits

int TSmain()
{
char buf;

	ULCON0 &=0XFFFFFF00;     
	ULCON0 |= 0X03; //1 start bit, 8 data bits
	UCON0 = 0X0805; //Serial port clock PCLK, query mode
	UBRDIV0 = 0X1A; //Baud rate 115200
while(1)
	{  
if(UTRSTAT0 & 0X01) //Is the reception completed? =1 End
		{
			buf=URXH0; //Read data
while(!(UTRSTAT0 & 0X04));//Is sending allowed? =1: Allowed
			UTXH0=buf;
		} 
	}

return 0;
}
Bootloader section
	AREA |DATA|,CODE,READONLY
	ENTRY
	ldr r13,=0x1000
	IMPORT TSmain
	b TSmain
	END

 

Analysis of the above program:

First, define each register in macro, for example, the address 0X50000000 is the UART line control register, 0X50000004 is the UART control register, and so on. Enter the TSmain() function, define the char type variable buf, which is used to receive characters from the PC. Then clear the lower 8 bits of the ULCON0 register, set the lower 8 bits to 03, that is, the frame transmission mode is 1 start bit, 8 data bits, the serial port register is set to 0x0805, indicating that the serial port clock source is PCLK, query mode, for the setting of the UBRDIV0 register, indicating that the baud rate is 115200.


Next, enter the while(1) statement to check whether the lowest bit of the UTRSTAT0 register is 1. If it is 1, it means that the reception is complete. The content in URXH0 is placed in buf. Check whether the second bit of the UTRSTAT0 register is 1. If it is 1, it means that data sending is allowed. The data in buf is placed in the UTXH0 register to complete simple serial port communication. 


4. Experimental Summary

Through this program, we can understand the implementation principle of S3C2440 serial communication, especially the settings of each register and the meaning of each bit, which will pave the way for accessing NAND Flash through serial communication in the next step!

Keywords:S3C2440 Reference address:Implementation of S3C2440 serial communication

Previous article:List of commonly used ARM assembly instructions
Next article:MICRO2440 Interrupt Learning

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号