STM32 Learning 002_Firmware Library Introduction

Publisher:星尘散落Latest update time:2017-10-26 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:STM32 Reference address:STM32 Learning 002_Firmware Library Introduction

Previous article:STM32 clock configuration method
Next article:STM32 learning 003_STM32F10X clock configuration

Recommended ReadingLatest update time:2024-11-15 15:37

stm32 spi slave mode configuration solution
Target: SPI transmission between stm32 (battleship) and stm32 (mini) (battleship as slave, mini as master) Result: The pass was successful I won't write the code, you can use the one you searched online; But tip: I use (the master and slave chip selects are all software configured); Key points: The important thi
[Microcontroller]
Design of transient motion parameter storage test system for STM32
introduction Storage test technology is an effective method to record the parameters of moving objects under special conditions. The test data is first stored in the memory, and after the device is recovered, it communicates with the host computer through a specific interface to restore the data information. In the te
[Microcontroller]
Design of transient motion parameter storage test system for STM32
stm32 FSMC-External SRAM IS62WV51216
Pin Definition  FSMC configuration steps 1. Enable the corresponding pin GPIO clock  2. Configure the GPIO pin mode  3. Enable the FSMC clock  4. FSMC initialization  5. Memory block enable Example  #define Bank1_SRAM3_ADDR ((u32)(0x68000000)) //First address 0x60000000, each block 0x40000000 void SRAM_gpio_ini
[Microcontroller]
Use of STM32 external interrupts
Routine name: External interrupt experiment Author      : tkzsld (sky) Experimental hardware: Huoniu development board Hardware connection: indicator light connected to  PD9                   button connected to      PA8 Function description: This routine implements the input test of external interrupt, key press
[Microcontroller]
STM32 GPIO simple operation function
There are too many STM32 library functions, and they cannot distinguish upper and lower case, so I often remember them incorrectly. GPIO is easy to remember. ---Step 1--Mode Configuration void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);  RCC_APB2Perip
[Microcontroller]
Return to STM32 --- Misunderstanding of STM32 timer
It has been almost 3 years since I started using STM32. To my shame, I still don’t understand many things. It may also be because my English level needs to be improved and I cannot correctly understand the meaning of English. After all, our language thinking is different (just find an excuse, haha). I have been using
[Microcontroller]
Return to STM32 --- Misunderstanding of STM32 timer
Redefine the printf() function using the standard library in STM32
//Redefine function 1 PUTCHAR_PROTOTYPE {  /* Place your implementation of fputc here */  /* eg write a character to the USART */   USART_SendData(USART1, (uint8_t) ch);     /* Loop and wait until the sending is finished*/   while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)   {}     return ch; } //Redefine f
[Microcontroller]
Dual-core intelligent electro-hydraulic servo controller using DSP and STM32
  Most servo control systems use traditional hardware structures, and the control algorithms are relatively fixed. In addition, they cannot realize high-performance control algorithms under different working conditions, which makes it difficult to meet the needs of modern industry. At present, there is an urgent need
[Microcontroller]
Dual-core intelligent electro-hydraulic servo controller using DSP and STM32
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号