stm32 - ordinary serial port (receive query and interrupt combined)

Publisher:春水碧于天Latest update time:2018-06-09 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Serial port experiment

1. Before doing any experiment, import the target file into the library file, then import the header file in the main function, and write the path in FWLIB. Of course, the serial port is no exception.

                                                                   

2. After importing the file, the second step is also port initialization (the function of the initialization statement has been explained later)

                            

After initialization is complete, remember to call in the main function

3. Send data using the serial port

                                    

Use USART_SendData(USART1,'9'); to send a byte of data, printf(); can also be used to send a string. When using printf, remember to add it to the main() function

#include "stdio.h" header file, otherwise an error will be reported. Of course, the previous knowledge learned in C language can also be applied to the project, because this is originally written in C language

4. There are two ways to send data to the serial port and let the serial port receive and display it on the serial port.

(1) Query method

                                        

The first statement is to check whether the data has been sent, if not, continue to wait

The second statement receives data from the serial port USART_ReceiveData (USART1) and assigns it to the variable USART1_RE defined by us.

The third statement is to increase the received data by one and then output USART_SendData()

(2) Interrupt mode

                                            

Of course, before writing any method, you need to initialize the port USART_ITConfig(USART1, USART_IT_RXNE, DISABLE); // Enable serial port receive interrupt

                         

Recommended serial port tools

                       

The following is a simpler use

                              


Keywords:stm32 Reference address:stm32 - ordinary serial port (receive query and interrupt combined)

Previous article:stm32 uart clear interrupt timing
Next article:STM32 self-study serial port interrupt mode

Recommended ReadingLatest update time:2024-11-23 07:25

Using 12M external crystal oscillator with stm32 under IAR
The system defaults to using an 8M external crystal oscillator, and three places need to be modified:  The first step is to open stm32f10x.h and change define HSE_VALUE ((uint32_t)8000000) /! Value of the External oscillator in Hz / change into: define HSE_VALUE ((uint32_t)12000000) /! Value of the External osci
[Microcontroller]
STM32 learning notes (VII) timer interrupt
#include "timer.h" #include "led.h" //////////////////////////////////////////////////////////////////////////////////   //This program is for learning purposes only and may not be used for any other purpose without the author's permission. //Mini STM32 development board //General timer driver code     //Atom on poi
[Microcontroller]
STM32 learning notes (VII) timer interrupt
stm32 serial port interrupt receives a frame of data
I recently used the serial port of stm32. It was very tiring to interrupt the reception of characters one by one. I searched the Internet and found a good post. I would like to share it with you. The original post address is: http://www.51hei.com/bbs/dpj-39885-1.html Thanks again to the original poster for sharing. Fo
[Microcontroller]
stm32 serial port interrupt receives a frame of data
STM32_keil compiled memory size analysis
Program Size: Code=28784 RO-data=6480 RW-data=60 ZI-data=3900 Meaning 1. Code: The size of the FLASH space occupied by the program, stored in FLASH. 2. RO-data: Read-only-data, program-defined constants, stored in FLASH. 3. RW-data: Read-write-data, initialized variables, stored in SRAM. 4. ZI-data: Zero-Init-data,
[Microcontroller]
STM32_keil compiled memory size analysis
The importance of parallel capacitors at the power supply end of STM32 microcontroller
As shown in the figure, the author soldered a STM32F207VET6 board using a TQFP (32-100PIN) 0.55MM to direct plug adapter board. The board leads out the SWD debug interface (only PA13 and PA14 are occupied), USART1 serial port pins, and a touch sensor and buzzer module are inserted. The function to be achieved is: af
[Microcontroller]
Related configuration of PWM frequency capture in STM32
Let me first talk about frequency capture in general. According to my personal understanding, frequency capture uses a counter. When a timer interrupt occurs (it should be when the Autoreload register in the figure below is full), two values ​​are recorded in two adjacent timer interrupts. The difference between the c
[Microcontroller]
Use of STM32 serial port + DMA2
uint8_t UART4_Rx_buffer ,UART4_Rx_num;     void UART4_Config(void)   {       GPIO_InitTypeDef GPIO_InitStructure;                    USART_InitTypeDef USART_InitStructure;       NVIC_InitTypeDef NVIC_InitStructure;       DMA_InitTypeDef DMA_InitStructure;                  // NVIC_PriorityGroupConfig(NVIC_PriorityGrou
[Microcontroller]
How to write interrupt program in STM32+IAR+uC/OS environment
First, let's talk about a few key functions: bsp_int.c provides several key interrupt operation functions: void    BSP_IntDis                (CPU_DATA    int_id)                  //Disable the specified interrupt void    BSP_IntDisAll        (void)                                                             
[Microcontroller]
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号