Use of library functions

Source: Internet
Author: User

Use of library functions

After learning the STM32 for more than a week, I started to use it from lighting up a lamp to interrupting the timing. I found some usage methods for the ST database. Now I will make a summary:

 

1. initialize the struct

A. Define a struct of the xxx-InitTypeDef type. For example, the GPIO-InitStructure of the gpio-InitTypeDef type is used to configure GPIO;

B. Write specific control parameters to these struct members as required, such as GPIO_initStructure.GPIO_Pin = GPIO_Pin_13;

C. use struct as input parameters to call the corresponding peripheral library function xxx-Init () to write control parameters to registers;

 

2. Data Input and Output

A, first through the input parameters to the function to determine the use of peripherals, such as using (GPIOA, GPIO-Pin-5), select the PA5 pin for control;

B. Write or read data operations, such as the function GPIO_WriteBit (GPIOA, 2010GPIO_Pin-5, Bit_RESE), is a write 1 operation on PA5;

C. To Receive external data, call the Read or Receive function to Read the return value of the function to obtain external input data.

 

3. Status bit and flag bit

When we need to know the working status of some peripherals during the program running process, a series of Mark checking functions will be involved:

A. The PPP_GetFlagStatus function is used to check whether a flag of the PPP device is set, for example, TIM _ GetFlagStatus;

B. The function named PPP_ClearFlag is used to clear the peripheral PPP flag, for example, TIM _ ClearFlag;

C. The PPP_GetITStatus function is used to determine whether the interruption from the peripheral PPP occurs, for example, TIM _ GetITStatus;

D. The function named PPP_ClearITPendingBit is used to clear the tag bit of the peripheral PPP interrupt to be processed, for example, TIM _ ClearITPendingBit.

 

Summary:

The official ST database has many common features. Here, we will make a simple classification and summary of the main common functions of peripherals:

 

Function Name Function Input parameters Return Value
XXX-Init () Initialize peripherals

XXX-inirTypeDef type struct

Void

XXX-DeInit ()

Initialize peripherals in the system default form Name of the peripheral to be initialized Void

XXX-StructInit ()

Fill in the initialization struct with the default data XXX-InitTypeDef type struct to be filled by default Void

XXX-SendData ()

Use peripherals to send data

XXX peripheral name; data to be sent

Void

XXX-ReceiveData ()

Obtain the data received by the peripherals.

XXX peripheral name

Returns the received data.

XXX _ GetFlagStatus ()

Detect peripheral event flags Time flag name to be checked SET or RESET

XXX _ GetITStatus ()

Check interrupt mark Indicates the interrupt flag to be checked. SET or RESET

XXX _ ClearFlag ()

Clear event flag Event flag name to be cleared Void

XXX _ ClearITPendingBit ()

Clear the suspended interrupt flag Indicates the interrupt flag to be detected. Void

XXX_ITConfig ()

Set peripheral interruption XXX receives peripherals accordingly; select an interrupt for enabling peripherals Void

XXX_Cmd ()

Enable or disable peripherals Configure the peripheral name; ENABLE or DISABLE Void

XXX _ DMACmd ()

Whether DMA requests can be used outside of Configuration Configure the peripheral name; select the DMA request to be configured; ENABLE or DISABLE Void

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.