armprogramming.comSTM32F4 Discovery Tutorials - GPIO - ARM Programming dịch - armprogramming.comSTM32F4 Discovery Tutorials - GPIO - ARM Programming Việt làm thế nào để nói

armprogramming.comSTM32F4 Discovery


armprogramming.com
STM32F4 Discovery Tutorials - GPIO - ARM Programming
by Sefa Veske · 27 January 2015

I try to explain GPIO for STM32F4xx family. I will use STM32F4 Discovery and Keil 5.13 version. The discovery board uses STM32F407VGT6 and including accelerometer, digital microphone, DAC, eight led and two push button. We can use STM32F4 Discovery reference manuel and datasheet, you can download in st website.

GPIO means

General Purpose Input Output

GPIO REGISTER

GPIO port mode register (GPIOx_MODER)

This 32 bit register which defines the operation mode. Each port indicated by the two pin. Each port can be selected as a digital input, digital output, alternative function or analog.

Port_mode_registerPort_mode_register_value

GPIO port output type register (GPIOx_OTYPER)

This register determine type of output pins to either push-pull or open drain. Reset value is push-pull. This is a 32 bit register but only first 16 bits are used.

port_output_type_registerpusppull

GPIO port output speed register (GPIOx_OSPEEDR)

This register define the output speed of the port. Port output speed can be adjusted in order to save power. Operation frequency for each pin is represented by two bits.

port_output_speed_reg

port_output_speed_reg_value

GPIO port pull-up/pull-down register (GPIOx_PUPDR)

This register define pull-up/pull-down resistor mode for the pins. Each port indicated by the two pin.

port_pupdr_reg pupd

GPIO port input data register (GPIOx_IDR)

This is a 32 bit register but only uses 16 bit. The register read-only and used for data-entry.input_data_reg

GPIO port output data register (GPIOx_ODR)

This is a 32 bit register but only uses 16 bit. These bits can be read and written by software. The values of the output port specifies by the output data register.output_data_reg

GPIO port bit set/reset register (GPIOx_BSRR)

This register is 32 bit. This is a write only register. Used for bit-level access to the output port. The first 16-bit are used to set pin value and the last 16 bit are used to reset pin value.bssr_reg

GPIO alternate function low register

Each pin can be used for different functions in addition to the digital inputs and outputs. There are two alternative function register;

GPIO alternate function low register
GPIO alternate function high register.

GPIO Code Example

I will use generally StdPeriph Libraries. stm32f4xx_gpio.h functions shown below;

/* Function used to set the GPIO configuration to the default reset state ****/
void GPIO_DeInit(GPIO_TypeDef* GPIOx);

/* Initialization and Configuration functions *********************************/
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/* GPIO Read and Write functions **********************************************/
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);

/* GPIO Alternate functions configuration function ****************************/
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);

I will make led example(use green and orange led) and Leds pcb drawing is shown below. I will use GPIOD for led example and GPIOD clock is activeted with AHB1 bus as shown below.

gpio_clc

led

You have to enable pin clock and GPIOD is on AHB1 bus. We can enable clock code;

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

You must select features of the general purpose input/output. Firstly we define a struct.

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitTypeDef has 5 features and gpio library struct;

typedef struct
{
uint32_t GPIO_Pin;

GPIOMode_TypeDef GPIO_Mode;

GPIOSpeed_TypeDef GPIO_Speed;

GPIOOType_TypeDef GPIO_OType;

GPIOPuPd_TypeDef GPIO_PuPd;

}GPIO_InitTypeDef;



GPIO Example;



#include "main.h"

#include "stm32f4xx.h"

#include "stm32f4xx_gpio.h"

GPIO_InitTypeDef GPIO_InitStructure;

void GPIO_Initialize(void);

int main(void)

{

GPIO_Initialize();

while (1)

{

GPIO_SetBits(GPIOD,GPIO_Pin_12| GPIO_Pin_13);

}

}

void GPIO_Initialize(void)

{

/* GPIOD Peripheral clock enable */

RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

/* Configure PD12 and PD13 in output pushpull mode */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12| GPIO_Pin_13;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.G
0/5000
Từ: -
Sang: -
Kết quả (Việt) 1: [Sao chép]
Sao chép!
armprogramming.comHướng dẫn khám phá STM32F4 - GPIO - cánh tay lập trìnhbởi Sefa Veske · 27 tháng 1 năm 2015Tôi cố gắng để giải thích GPIO cho gia đình STM32F4xx. Tôi sẽ sử dụng phiên bản STM32F4 Discovery và Keil 5.13. Hội đồng quản trị phát hiện sử dụng STM32F407VGT6 và bao gồm các gia tốc, microphone kỹ thuật số, DAC, tám dẫn và hai nút nhấn. Chúng tôi có thể sử dụng tài liệu tham khảo STM32F4 Discovery manuel và thông số kỹ thuật, bạn có thể tải về tại trang web st.GPIO có nghĩa là Đầu ra đầu vào mục đích chungGPIO ĐĂNG KÝGPIO cảng chế độ đăng ký (GPIOx_MODER)Này đăng ký 32 bit, xác định các chế độ hoạt động. Mỗi cổng được chỉ ra bởi hai pin. Mỗi cổng có thể được chọn như là một kỹ thuật số đầu vào, đầu ra kỹ thuật số, thay thế chức năng hoặc tương tự.Port_mode_registerPort_mode_register_valueGPIO cổng đầu ra loại đăng ký (GPIOx_OTYPER)Đăng ký này xác định loại ra chân hoặc đẩy-kéo hoặc mở cống. Đặt lại giá trị là đẩy-kéo. Đây là một đăng ký 32 bit nhưng chỉ đầu tiên 16 bit được sử dụng.port_output_type_registerpusppullTốc độ đầu ra cổng GPIO đăng ký (GPIOx_OSPEEDR)Đăng ký này xác định tốc độ đầu ra của cảng. Tốc độ đầu ra cổng có thể được điều chỉnh để tiết kiệm năng lượng. Tần số hoạt động cho mỗi pin được đại diện bởi hai bit.port_output_speed_regport_output_speed_reg_valueGPIO port pull-pick-up/kéo xuống đăng ký (GPIOx_PUPDR)Đăng ký này xác định điện trở pull-pick-up/thả xuống chế độ cho các chân. Mỗi cổng được chỉ ra bởi hai pin.port_pupdr_reg pupdGPIO cổng đầu vào dữ liệu đăng ký (GPIOx_IDR)Đây là một đăng ký 32 bit nhưng chỉ sử dụng 16 bit. Đăng ký chỉ đọc và được sử dụng cho dữ liệu-entry.input_data_regGPIO cổng đầu ra dữ liệu đăng ký (GPIOx_ODR)Đây là một đăng ký 32 bit nhưng chỉ sử dụng 16 bit. Những bit có thể được đọc và viết bằng phần mềm. Các giá trị của cổng đầu ra xác định bằng sản lượng dữ liệu register.output_data_regGPIO port bit bộ/thiết lập lại đăng ký (GPIOx_BSRR)Đăng ký này là 32 bit. Đây là một đăng ký duy nhất ghi. Sử dụng cho các bit cấp quyền truy cập vào cổng đầu ra. 16-bit đầu tiên được sử dụng để thiết lập mã pin giá trị và 16 bit cuối cùng được sử dụng để thiết lập lại pin value.bssr_regGPIO thay thế chức năng đăng ký thấpMỗi pin có thể được sử dụng cho các chức năng khác nhau ngoài các yếu tố đầu vào kỹ thuật số và kết quả đầu ra. Có hai thay thế chức năng đăng ký; GPIO thay thế chức năng đăng ký thấp GPIO thay thế chức năng đăng ký cao. GPIO mã ví dụTôi sẽ thường sử dụng thư viện StdPeriph. stm32f4xx_gpio.h chức năng hiển thị dưới đây;/ * Chức năng được sử dụng để thiết lập cấu hình GPIO để mặc định cài lại nước *** /void GPIO_DeInit (GPIO_TypeDef * GPIOx);/ * Khởi tạo và cấu hình các chức năng *** /void GPIO_Init (GPIO_TypeDef * GPIOx, GPIO_InitTypeDef * GPIO_InitStruct);void GPIO_StructInit (GPIO_InitTypeDef * GPIO_InitStruct);void GPIO_PinLockConfig (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin);/ * GPIO đọc và viết các chức năng *** /uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);/* GPIO Alternate functions configuration function ****************************/void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);I will make led example(use green and orange led) and Leds pcb drawing is shown below. I will use GPIOD for led example and GPIOD clock is activeted with AHB1 bus as shown below.gpio_clcledYou have to enable pin clock and GPIOD is on AHB1 bus. We can enable clock code;RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);You must select features of the general purpose input/output. Firstly we define a struct.GPIO_InitTypeDef GPIO_InitStructure;GPIO_InitTypeDef has 5 features and gpio library struct;typedef struct{ uint32_t GPIO_Pin; GPIOMode_TypeDef GPIO_Mode; GPIOSpeed_TypeDef GPIO_Speed; GPIOOType_TypeDef GPIO_OType; GPIOPuPd_TypeDef GPIO_PuPd; }GPIO_InitTypeDef; GPIO Example; #include "main.h"#include "stm32f4xx.h"#include "stm32f4xx_gpio.h"GPIO_InitTypeDef GPIO_InitStructure;void GPIO_Initialize(void);int main(void){ GPIO_Initialize(); while (1) { GPIO_SetBits(GPIOD,GPIO_Pin_12| GPIO_Pin_13); }}void GPIO_Initialize(void){/* GPIOD Peripheral clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); /* Configure PD12 and PD13 in output pushpull mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12| GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.G
đang được dịch, vui lòng đợi..
Kết quả (Việt) 2:[Sao chép]
Sao chép!

armprogramming.com
STM32F4 Discovery Hướng dẫn - GPIO - ARM Lập trình
bởi Sefa Veske · 27 Tháng một 2015 Tôi cố gắng giải thích cho GPIO STM32F4xx gia đình. Tôi sẽ sử dụng STM32F4 Discovery và Keil 5.13 phiên bản. Hội đồng quản trị phát hiện sử dụng STM32F407VGT6 và bao gồm gia tốc, microphone kỹ thuật số, DAC, tám lãnh đạo và hai nút nhấn. Chúng tôi có thể sử dụng tài liệu tham khảo STM32F4 manuel và datasheet Discovery, bạn có thể tải về tại trang web st. GPIO nghĩa Mục đích chung đầu vào đầu ra GPIO REGISTER chế độ cổng GPIO đăng ký (GPIOx_MODER) 32 bit đăng ký này trong đó xác định các chế độ hoạt động. Mỗi cổng được chỉ ra bởi hai pin. Mỗi cổng có thể được lựa chọn như là một đầu vào kỹ thuật số, đầu ra kỹ thuật số, chức năng thay thế hoặc tương tự. Port_mode_registerPort_mode_register_value GPIO loại đầu ra cổng đăng ký (GPIOx_OTYPER) này đăng ký xác định loại của các chân đầu ra hoặc là push-pull hoặc cống mở. Giá trị đặt lại là push-pull. Đây là 32 bit đăng ký nhưng chỉ có 16 bit đầu tiên được sử dụng. Port_output_type_registerpusppull GPIO đăng ký tốc độ đầu ra cổng (GPIOx_OSPEEDR) này đăng ký xác định tốc độ đầu ra của các cổng. Tốc độ đầu ra cổng có thể được điều chỉnh để tiết kiệm điện. Tần số hoạt động cho mỗi pin được đại diện bởi hai bit. Port_output_speed_reg port_output_speed_reg_value GPIO cổng kéo lên / kéo xuống đăng ký (GPIOx_PUPDR) này đăng ký xác định chế độ điện trở kéo lên / kéo xuống cho các chân. Mỗi cổng được chỉ ra bởi hai pin. Port_pupdr_reg pupd GPIO dữ liệu đầu vào cổng đăng ký (GPIOx_IDR) Đây là một 32 bit đăng ký nhưng chỉ sử dụng 16 bit. Việc đăng ký chỉ đọc và sử dụng cho dữ liệu entry.input_data_reg GPIO dữ liệu đầu ra cổng đăng ký (GPIOx_ODR) Đây là một 32 bit đăng ký nhưng chỉ sử dụng 16 bit. Các bit có thể được đọc và được viết bằng phần mềm. Các giá trị của các cổng đầu ra xác định bởi các dữ liệu đầu ra register.output_data_reg cổng GPIO bit đặt / thiết lập lại đăng ký (GPIOx_BSRR) đăng ký này là 32 bit. Đây là một ghi chỉ đăng ký. Được sử dụng để truy cập chút cấp đến cổng ra. 16-bit đầu tiên được sử dụng để thiết lập giá trị pin và 16 bit cuối cùng được sử dụng để thiết lập lại pin value.bssr_reg GPIO chức năng thay thế thấp đăng ký Mỗi pin có thể được sử dụng cho các chức năng khác nhau, thêm vào các yếu tố đầu vào và đầu ra số. Có hai chức năng đăng ký thay thế; GPIO thay thế chức năng thấp đăng ký GPIO chức năng thay thế đăng ký cao. GPIO Mã số Ví dụ tôi sẽ sử dụng thường StdPeriph Libraries. chức năng stm32f4xx_gpio.h hình dưới đây; / * Chức năng sử dụng để thiết lập cấu hình GPIO với trạng thái reset mặc định **** / trống GPIO_DeInit (GPIO_TypeDef * GPIOx); / * Khởi tạo và cấu hình các chức năng ********** *********************** / trống GPIO_Init (GPIO_TypeDef * GPIOx, GPIO_InitTypeDef * GPIO_InitStruct); khoảng trống GPIO_StructInit (GPIO_InitTypeDef * GPIO_InitStruct); làm mất hiệu lực GPIO_PinLockConfig (GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin); / * GPIO đọc và Viết chức năng ************************************** ******** / uint8_t GPIO_ReadInputDataBit (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin); uint16_t GPIO_ReadInputData (GPIO_TypeDef * GPIOx); uint8_t GPIO_ReadOutputDataBit (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin); uint16_t GPIO_ReadOutputData (GPIO_TypeDef * GPIOx); khoảng trống GPIO_SetBits ( GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin); khoảng trống GPIO_ResetBits (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin); khoảng trống GPIO_WriteBit (GPIO_TypeDef * GPIOx, uint16_t GPIO_Pin, BitAction BitVal); khoảng trống GPIO_Write (GPIO_TypeDef * GPIOx, uint16_t PortVal); khoảng trống GPIO_ToggleBits (GPIO_TypeDef * GPIOx , uint16_t GPIO_Pin); / * GPIO thay thế chức năng chức năng cấu hình **************************** / trống GPIO_PinAFConfig (GPIO_TypeDef * GPIOx, uint16_t GPIO_PinSource , uint8_t GPIO_AF); tôi sẽ làm ví dụ dẫn (sử dụng màu xanh lá cây và màu da cam đã dẫn) và vẽ Leds pCB được hiển thị dưới đây. Tôi sẽ sử dụng GPIOD ví dụ dẫn và đồng hồ GPIOD được activeted với xe buýt AHB1 như hình dưới đây. Gpio_clc dẫn Bạn phải kích hoạt đồng hồ pin và GPIOD là trên xe buýt AHB1. Chúng ta có thể cho phép mã đồng hồ; RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE); Bạn phải chọn tính năng của các mục đích chung đầu vào / đầu ra. Trước hết chúng ta định nghĩa một cấu trúc. GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitTypeDef có 5 tính năng và thư viện gpio struct; typedef struct { uint32_t GPIO_Pin; GPIOMode_TypeDef GPIO_Mode; GPIOSpeed_TypeDef GPIO_Speed; GPIOOType_TypeDef GPIO_OType; GPIOPuPd_TypeDef GPIO_PuPd; } GPIO_InitTypeDef; GPIO Ví dụ; #include "main.h" # bao gồm "stm32f4xx.h" #include "stm32f4xx_gpio.h" GPIO_InitTypeDef GPIO_InitStructure; làm mất hiệu lực GPIO_Initialize (void); int main (void) { GPIO_Initialize (); while (1) { GPIO_SetBits (GPIOD, GPIO_Pin_12 | GPIO_Pin_13); } } trống GPIO_Initialize (void) { / * GPIOD đồng hồ ngoại vi cho phép * / RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOD, ENABLE); / * Cấu PD12 và PD13 trong chế độ pushpull đầu ra * / GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.G






























































































































































đang được dịch, vui lòng đợi..
 
Các ngôn ngữ khác
Hỗ trợ công cụ dịch thuật: Albania, Amharic, Anh, Armenia, Azerbaijan, Ba Lan, Ba Tư, Bantu, Basque, Belarus, Bengal, Bosnia, Bulgaria, Bồ Đào Nha, Catalan, Cebuano, Chichewa, Corsi, Creole (Haiti), Croatia, Do Thái, Estonia, Filipino, Frisia, Gael Scotland, Galicia, George, Gujarat, Hausa, Hawaii, Hindi, Hmong, Hungary, Hy Lạp, Hà Lan, Hà Lan (Nam Phi), Hàn, Iceland, Igbo, Ireland, Java, Kannada, Kazakh, Khmer, Kinyarwanda, Klingon, Kurd, Kyrgyz, Latinh, Latvia, Litva, Luxembourg, Lào, Macedonia, Malagasy, Malayalam, Malta, Maori, Marathi, Myanmar, Mã Lai, Mông Cổ, Na Uy, Nepal, Nga, Nhật, Odia (Oriya), Pashto, Pháp, Phát hiện ngôn ngữ, Phần Lan, Punjab, Quốc tế ngữ, Rumani, Samoa, Serbia, Sesotho, Shona, Sindhi, Sinhala, Slovak, Slovenia, Somali, Sunda, Swahili, Séc, Tajik, Tamil, Tatar, Telugu, Thái, Thổ Nhĩ Kỳ, Thụy Điển, Tiếng Indonesia, Tiếng Ý, Trung, Trung (Phồn thể), Turkmen, Tây Ban Nha, Ukraina, Urdu, Uyghur, Uzbek, Việt, Xứ Wales, Yiddish, Yoruba, Zulu, Đan Mạch, Đức, Ả Rập, dịch ngôn ngữ.

Copyright ©2025 I Love Translation. All reserved.

E-mail: