STM32 programming using library functions
The library function is a function library packaged by the STM32 manufacturer to facilitate user programming.
USART Library Functions
The USART library function includes three initialization functions: 1-default value initialization, 2-normal initialization, and 3-structure class initialization. Generally, we choose the third initialization method.
Step 1: Configure the enable bit (including baud rate, data bit, stop bit, check bit)
First define a structure variable: USART_InitTypeDef USART_InitStructure,
Then, according to the relevant configuration parameters of the structure, configure the parameters actually required.
USART_InitStructure.USART_BaudRate = 9600; //Set the baud rate to 9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //Data length is 8 bits USART_InitStructure.USART_StopBits
= USART_StopBits_1; //1 stop bit
USART_InitStructure.USART_Parity = USART_Parity_No; //No parity bit
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //Turn off data flow control
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; //Optional transmit and receive mode
USART_Init(USART1, &USART_InitStructure); //Assign values to structure members
USART_Cmd(USART1 ,ENABLE); //USART1 enable
After configuring the USART1 function, you can call this function to send and display it in the USART1# window.
u8 i ,data = 'A'; //define variables
//Use the for loop to display 20 consecutive characters
for(i=0;i<20;i++)
{
USART_SendData(USART1,data);
data++;
while( USART_GetFlagStatus(USART1,USART_FLAG_TC) == RESET) ; ; //Judge the TXE/TC bit in the USART_SR register
}
At this point, you can compile the program. If the compilation is successful, you can perform Debug.
Previous article:STM32 clock configuration method
Next article:STM32 learning 003_STM32F10X clock configuration
Recommended ReadingLatest update time:2024-11-15 15:37
- Popular Resources
- Popular amplifiers
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
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- 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
- Is there any chip that can convert analog signal (potentiometer and DC voltage) into PWM dimming signal?
- Infrared thermometer
- Reading notes of the good book "Operational Amplifier Parameter Analysis and LTspice Application Simulation" 01 cover page
- The difference between ordinary diode and Zener diode
- Why not promote the monopoly of shared bicycles?
- Violent disassembly of TMS320F28379D
- New WiFi 6E and WiFi 7 standards: markets and applications
- 【Jiajiabao】 esp32s2 lvgl running
- [AB32VG1 development board review] Light up RGB_LED
- I would like to ask you why there is this yellow grid when the copper is laid. I saw someone else's board