1. Working principle of serial port:
1. From the above serial port circuit, we can know that the specific process is as follows:
Send: write data - > buffer - > shifter - > TXDn - > RSTXDn - > PC
Receive: PC---》RSRXDn---》RXDn--->shifter--->buffer--->get data
2. As can be seen from the above figure,
The buffer has two modes, FIFO mode and Non-FIFO mode.
If FIFO mode is used, the FIFO Register needs to be configured so that 64 bytes of buffer are available.
If Non-FIFO mode is used, there is no need to configure the FIFO Register, but only one byte of buffer is available.
3. The specific process of making a serial port module:
<1>. From the serial port circuit diagram, we can know that we should first configure the corresponding pins to the corresponding functional mode. Here we can see that the corresponding pin is GPH.
<2>. From the user manual we need to configure the corresponding registers one by one.
Here we use the Non-FIFO mode first. After browsing, we can obtain the following information:
First: We need to configure the frame format settings (ULCON0).
Second: We need to configure the working mode (UCON0). (The working mode includes DMA interrupt polling mode. We use the polling mode here first).
Third: We need to configure the baud rate.
Note: For the status register, we do not need to configure it unless there are special requirements.
So in summary: for the serial port module, we need to do the following 4 steps:
1. Pin settings
2. Frame format settings
3. Working mode setting (DMA interrupt polling)
4. Baud rate setting.
The following is the source code based on the mini2440 serial port module:
/************************************************
NAME : UART.C
DESC :
Revision: 2015.8.18 ver 0.0
************************************************/
#include "uart.h"
#include #include /*********************************************** Function name : uart_init Description: uart initialization Input parameter : none Return : none Others : uart init *************************************************/ void uart_init() { //1. Configure the corresponding bits of sending and receiving of serial port 0 in GPHCON rGPHCON &= ~(0xf<<4); rGPHCON |=(0xa<<4); //2. Set how many data bits can be transmitted at a time rULCON0 |= (0x3<<0); //3. Configure the serial port controller to set the sending and receiving mode. Sending is DMA mode and receiving is polling mode. rUCON0 |= (0x9<<0); //rUCON0 = 0<<12|0<<10|0<<4|1<<2|1; //4. Set the baud rate rUBRDIV0 = (int)(PCLK/(BAUDRATE*16)) - 1; } /*********************************************** Function name : getc Description: Receive data Input parameter : none Return : char Others : none *************************************************/ unsigned char uart_getc(void) { unsigned char ret; while((rUTRSTAT0 & (1<<0))==0); right = rURXH0; if(ret == 'r') right = 'n'; return right; } /*********************************************** Function name : myputc Description: Send data Input parameter : char Return : none Others : none *************************************************/ void myputc(unsigned char ch) { if(ch=='n') myputc('r'); while((rUTRSTAT0 & 2) == 0); rUTXH0 = ch; } /*********************************************** Function name : send_string Description: Send string Input parameter : char * Return : none Others : none *************************************************/ void uart_puts(const char *str) { while(*str) { myputc(*str); str++; } myputc ( ' n ' ) ; } /*********************************************** Function name : mygets Description: Receive string Input parameter : char * Return : none Others : none *************************************************/ void mygets(char *str) { S32 i=0; U8 ch; while((ch=uart_getc())!='n') { if(ch=='b') { if(i>0) { myputc('b'); myputc(' '); myputc('b'); i--; } } else { str[i++] = ch; myputc ( ch ) ; } } str[i]=''; myputc ( ' n ' ) ; } /*********************************************** Function name : uart_printf Description: Send message Input parameter : char *fmt.... Return : none Others : none *************************************************/ void uart_printf(char *fmt,...) //Function with variable parameters { va_list ap; //Initialize the pointer to the variable parameter list char string[256]; va_start(ap,fmt); //Pay the address of the first variable parameter to ap, that is, ap points to the beginning of the variable parameter list vsprintf(string,fmt,ap); //Convert the variable parameters pointed to by parameters fmt and ap into a formatted string and put it in the string array. It has the same function as sprintf(), but the parameter types are different. uart_puts(string); //Send the formatted string from the development board serial port va_end(ap); //ap is set to 0, which is not very useful, but is mainly for program robustness }
Previous article:About mini2440 interrupt configuration
Next article:About the configuration of mini2440 key interrupt
- Popular Resources
- Popular amplifiers
- 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)
- Learn ARM development (4)
- Learn ARM development (6)
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
- 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?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- My knowledge of computers
- Sampling rate of MCU ADC
- Let’s talk about the first big event in 2019...
- Wifi controlled LED screen
- IIoT opens up more possibilities beyond the factory floor
- Recommended one: [Lingsheng] MCU code automatic generator (automatic programming tool)
- Learning 3D visualization scene hierarchy from scratch (1)
- What are the differences and connections between compilers and integrated development environments?
- [RISC-V MCU CH32V103 Review] ---Advanced Wiki---Practical debugging methods
- LLC resonant converter classic literature or books, personal test feedback!