STM32 serial port register library function configuration method

Publisher:daasddlaLatest update time:2018-12-17 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. References


      "STM32F1 Development Guide - Library Function Version" - 5.3 usart serial port folder introduction

                                    - Chapter 9 Serial Port Experiment


      "STM32 Chinese Reference Manual V10" - Chapter 25 Universal Synchronous Asynchronous Receiver Transmitter (USART)


2. Basic principles of serial communication


        Commonly used serial port related registers


           USART_SR status register


           USART_DR data register


           USART_BRR baud rate register

           

   Serial port operation related registers (entry parameters omitted):


      void USART_Init(); //Serial port initialization: baud rate, data word length, parity check, hardware flow control and transmit and receive enable

            void USART_Cmd(); //Enable serial port

            void USART_ITConfig(); //Enable related interrupts


            void USART_SendData(); //Send data to the serial port, DR

            uint16_t USART_ReceiveData(); //Receive data and read the received data from DR


            FlagStatus USART_GetFlagStatus(); //Get the status flag

            void USART_ClearFlag(); //Clear status flag

            ITStatus USART_GetITStatus(); //Get interrupt status flag

            void USART_ClearITPendingBit(); //Clear interrupt status flag


   Status Register (USART_SR)



      FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);


   Data register (USART_DR)

      

      

      void USART_SendData(USART_TypeDef* USARTx, uint16_t Data);

            uint16_t USART_ReceiveData(USART_TypeDef* USARTx);


Baud Rate Register (USART_BRR)

     

     

     void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct);


   Baud rate calculation method

     

     

Hardware Connection

PA9, PA10 (serial port 1) are connected to the USB serial port circuit

       

       

3. General steps for serial port configuration

  

  ①Serial port clock enable, GPIO clock enable: RCC_APB2PeriphClockCmd();


        ②Serial port reset: USART_DeInit(); This step is not necessary


        ③GPIO port mode setting: GPIO_Init(); mode is set to GPIO_Mode_AF_PP


        ④Serial port parameter initialization: USART_Init();


        ⑤ Enable interrupts and initialize NVIC (this step is required only if interrupts need to be enabled)

              NVIC_Init();

              USART_ITConfig();


        ⑥ Enable the serial port: USART_Cmd();


        ⑦Write interrupt handling function: USARTx_IRQHandler();


        ⑧Serial port data transmission and reception:

        void USART_SendData(); //Send data to the serial port, DR

        uint16_t USART_ReceiveData(); //Receive data and read the received data from DR


        ⑨Serial port transmission status acquisition:


        FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG);


        void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint16_t USART_IT);


Keywords:STM32 Reference address:STM32 serial port register library function configuration method

Previous article:STM32 serial port basic configuration (register version) notes
Next article:STM32F103 USART serial port simple implementation

Recommended ReadingLatest update time:2024-11-16 13:55

STM32 USB interrupt description
The STM32 USB module can generate three types of interrupts: USB wake-up interrupt, USB high priority interrupt and USB low priority interrupt. The STM32 reference manual does not explain in detail which events these three interrupts correspond to. The following are the explanations:   1) USB wake-up interrupt: The
[Microcontroller]
STM32 FSMC-SRAM routine
The SRAM uses the 55ns IS62WV51216, and the timing requirements of the IS62WV51216 for reading and writing need to be analyzed first. Read Timing   By analyzing the timing diagram, the following information can be extracted (the high and low byte bits and the enable bit are not analyzed because the FSMC access m
[Microcontroller]
STM32 FSMC-SRAM routine
stm32: write data to flash
1. To write data to the flash, first page the data according to the write address and the number of data bytes, then call the page write function to write it to the flash. 2. Data paging function code:      2.1 Function parameters:             pbuff: data pointer written to flash             addr: address to
[Microcontroller]
STM32 GPIO and the first STM32 program (marquee)
Today let's talk about GPIO. For a novice like me, GPIO is just like how to open the door before I learn to drive. From this, we can see the importance of learning STM32. Well, without further ado, let me summarize that there are 7 groups of IO ports in the STM32F103ZE development board, each group of IO ports has 16
[Microcontroller]
The relationship between the frequency of the STM32 timer output square wave and PSC and CNT
1. The maximum system clock frequency of STM32F103 is 72MHZ  2. The maximum CNT count value of the STM32F103 timer TIM is 65535  3. The value of the pre-scaling coefficient PSC of the timer TIM of STM32F103 = 72M / timer counting frequency Because the maximum value of CNT is 65535, there is a problem here, when th
[Microcontroller]
stm32 hardware IIC use
In many posts, I saw that many people use simulated I2C when using I2C devices, because ST designed it to be difficult to use in order to circumvent patents! I also tried the officially generated I2C today, using the I2C generated by CUBEMX. I also encountered some minor problems after the generation. I posted it here
[Microcontroller]
stm32 hardware IIC use
STM32 Series Part 11 - Timer
STM32 has a total of 8 timers: Timer Type Number of digits model Special application scenarios Advanced timer TIME1, TIME8 16-bit Up, Down, Up/Down PWM click control General timer TIME2~TIME5 16-bit Up, Down, Up/Down Timing counting, PWM output, input capture, output comparison Basic timer TIME6, TIME7 16-bit Up
[Microcontroller]
STM32 Series Part 11 - Timer
STM32 USB design microcontroller program
First, let's take a look at the working process of USB. When a USB device is connected to the host, the host begins to enumerate the USB device and sends a command to the USB device to obtain the relevant description information of the USB device, including device description (device descriptor), configuration
[Industrial Control]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号