STM32 Running Lights

Source: Internet
Author: User
Tags bit set

void Led_init (void)

Gpio_inittypedef gpio_initstructure;

Rcc_apb2periphclockcmd (Rcc_apb2periph_gpioa, ENABLE); Enable PA Port Clock

(RCC Clock You can not see first )

GPIO 's library functions

The main use in library functions is as follows:

Gpio_init

Gpio_structinit

Gpio_setbit

Gpio_resetbit Other According to the needs of the use!

function Gpio_init

This is set to 0

Gpio_initstructure.gpio_pin = Gpio_pin_8; led0-->pa.8 Port Configuration

Gpio_initstructure.gpio_mode = gpio_mode_out_pp; Push-Pull output

Gpio_initstructure.gpio_speed = Gpio_speed_50mhz;

Gpio_init (Gpioa, &gpio_initstructure);

Gpio_setbits (Gpioa,gpio_pin_8); pa.8 Output High

GPIO Configuration

led0=0; A bit band operation Gpio_resetbits (Gpioa,gpio_pin_8) is used;

#define LED0 Paout (8)//pa8

#define PAOUT (N) bit_addr (gpioa_odr_addr,n)//output

-bit operation

#define Bitband (addr, Bitnum) ((Addr & 0xf0000000) +0x2000000+ ((addr &0xfffff) <<5) + (BITNUM<<2))

#define MEM_ADDR (ADDR) * ((volatile unsigned long *) (ADDR))

#define BIT_ADDR (ADDR, Bitnum) mem_addr (Bitband (ADDR, Bitnum))

Tell you what the register looks like?

The following table is important and must be understood!

Gpio Register Description

Port Configuration Low Register (GPIOX_CRL) (x=a. E

Port Configuration High Register (GPIOX_CRH) (x=a. E

Note that the mode[1:0]>00 is output mode, Gpio_mode_ain = 0x0,

Example Child

Gpio_initstructure.gpio_mode = gpio_mode_out_pp; Push-Pull output

GPIO_MODE_OUT_PP = 0x10, PA8 's

Rate

typedef enum

{

Gpio_speed_10mhz = 1,

Gpio_speed_2mhz,

Gpio_speed_50mhz

}gpiospeed_typedef;

#define IS_GPIO_SPEED (speed) = = Gpio_speed_10mhz) | | (speed) = = Gpio_speed_2mhz) | | \

(speed) = = Gpio_speed_50mhz))

Way

typedef enum

{Gpio_mode_ain = 0x0,

gpio_mode_in_floating = 0x04,

GPIO_MODE_IPD = 0x28,

Gpio_mode_ipu = 0x48,

Gpio_mode_out_od = 0x14,

GPIO_MODE_OUT_PP = 0x10,

Gpio_mode_af_od = 0x1C,

GPIO_MODE_AF_PP = 0x18

}gpiomode_typedef;

#define IS_GPIO_MODE (Mode) ((mode) = = Gpio_mode_ain) | | (MODE) = = gpio_mode_in_floating) | | \

(MODE) = = GPIO_MODE_IPD) | | (MODE) = = Gpio_mode_ipu) | | \

(MODE) = = Gpio_mode_out_od) | | (MODE) = = gpio_mode_out_pp) | | \

(MODE) = = Gpio_mode_af_od) | | (MODE) = = gpio_mode_af_pp))

Port Input data Register (GPIOX_IDR) (x=a). E

Port Output Data Register (GPIOX_ODR) (x=a. E

Port bit set/clear register (GPIOX_BSRR) (x=a): E

Port bit Clear Register (GPIOX_BRR) (x=a). E

STM32 Running Lights

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.