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!
Previous article:List of commonly used ARM assembly instructions
Next article:MICRO2440 Interrupt Learning
- Popular Resources
- Popular amplifiers
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Unboxing the imxm8plus development board from PHYTEC
- EEWORLD University ---- OpenCV 3 with Python 3 Tutorial
- Siemens 230RC opens for 3 seconds and closes for 3 seconds
- [Environmental Expert's Smart Watch] Part 10: Status Light and Mode Switching
- Disassembly of 3.0 expansion dock, PD to HDMI conversion chip Bridgestone PS176HDMQFN48GTR2-B0 schematic diagram reference
- Stack Overflow Technology from Entry to Mastery
- Has anyone used HEW to compile?
- Three issues about LDO load regulation, linear regulation and voltage drop
- How to release the object is part of a locked union
- Lighting capacitor