女人被狂躁到高潮视频免费无遮挡,内射人妻骚骚骚,免费人成小说在线观看网站,九九影院午夜理论片少妇,免费av永久免费网址

當(dāng)前位置:首頁(yè) > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] 一、總覽HAL層里的庫(kù)函數(shù)和大家熟悉的stm32lib基本上是一致的。一般來(lái)說(shuō)一個(gè)cpu外設(shè)的操作函數(shù)分成兩部分,分別是init和operation。來(lái)看一個(gè)cube里的例子:static GPIO_InitTypeDef GPIO_InitStruct;in

一、總覽

HAL層里的庫(kù)函數(shù)和大家熟悉的stm32lib基本上是一致的。一般來(lái)說(shuō)一個(gè)cpu外設(shè)的操作函數(shù)分成兩部分,分別是init和operation。

來(lái)看一個(gè)cube里的例子:

static GPIO_InitTypeDef GPIO_InitStruct;


int main(void)

{

/* This sample code shows how to use GPIO HAL API to toggle LED2 IO

in an infinite loop. */


/* STM32F103xB HAL library initialization:

- Configure the Flash prefetch

- Systick timer is configured by default as source of time base, but user

can eventually implement his proper time base source (a general purpose

timer for example or other time source), keeping in mind that Time base

duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and

handled in milliseconds basis.

- Set NVIC Group Priority to 4

- Low Level Initialization

*/

HAL_Init();


/* Configure the system clock to 64 MHz */

SystemClock_Config();


/* -1- Enable GPIO Clock (to be able to program the configuration registers) */

LED2_GPIO_CLK_ENABLE();


/* -2- Configure IO in output push-pull mode to drive external LEDs */

GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;


GPIO_InitStruct.Pin = LED2_PIN;

HAL_GPIO_Init(LED2_GPIO_PORT, &GPIO_InitStruct);


/* -3- Toggle IO in an infinite loop */

while (1)

{

HAL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);

/* Insert delay 100 ms */

HAL_Delay(100);

}

}

注釋里的內(nèi)容說(shuō)明了之前一篇文章里的提到的HAL_INIT()函數(shù)的作用。


在使用GPIO前要先初始化GPIO的時(shí)鐘,因?yàn)樵S多外設(shè)都被設(shè)計(jì)成時(shí)序邏輯電路,所以必須要為外設(shè)提供時(shí)鐘源,否則外設(shè)的電路狀態(tài)就不會(huì)改變。


GPIO時(shí)鐘源設(shè)定后,通過(guò)GPIO_initTypeDef結(jié)構(gòu)體,初始化指定Pin腳的模式、速度、初始輸出。


最后調(diào)用 HAL_GPIO_TogglePin()和HAL_Delay()將GPIO定時(shí)取反以達(dá)到使驅(qū)動(dòng)的led閃爍的效果。


二、GPIO的初始化


GPIO_InitTypeDef結(jié)構(gòu)體用于對(duì)一個(gè)或者一組GPIO來(lái)進(jìn)行初始化,它的四個(gè)成員分別是,Pin、Mode、Pull、Speed。


GPIO_InitTypeDef原型:

/**

* @brief GPIO Init structure definition

*/

typedef struct

{

uint32_t Pin; /*!< Specifies the GPIO pins to be configured.

This parameter can be any value of @ref GPIO_pins_define */


uint32_t Mode; /*!< Specifies the operating mode for the selected pins.

This parameter can be a value of @ref GPIO_mode_define */


uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.

This parameter can be a value of @ref GPIO_pull_define */


uint32_t Speed; /*!< Specifies the speed for the selected pins.

This parameter can be a value of @ref GPIO_speed_define */

}GPIO_InitTypeDef;


Pin

#define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */

#define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */

#define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */

#define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */

#define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */

#define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */

#define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */

#define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */

#define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */

#define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */

#define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */

#define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */

#define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */

#define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */

#define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */

#define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */

#define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */


選擇多個(gè)Pin的時(shí)候,可以用位選的宏定義相或得到。

Mode

#define GPIO_MODE_INPUT ((uint32_t)0x00000000) /*!< Input Floating Mode */

#define GPIO_MODE_OUTPUT_PP ((uint32_t)0x00000001) /*!< Output Push Pull Mode */

#define GPIO_MODE_OUTPUT_OD ((uint32_t)0x00000011) /*!< Output Open Drain Mode */

#define GPIO_MODE_AF_PP ((uint32_t)0x00000002) /*!< Alternate Function Push Pull Mode */

#define GPIO_MODE_AF_OD ((uint32_t)0x00000012) /*!< Alternate Function Open Drain Mode */

#define GPIO_MODE_AF_INPUT GPIO_MODE_INPUT /*!< Alternate Function Input Mode */


#define GPIO_MODE_ANALOG ((uint32_t)0x00000003) /*!< Analog Mode */


#define GPIO_MODE_IT_RISING ((uint32_t)0x10110000) /*!< External Interrupt Mode with Rising edge trigger detection */

#define GPIO_MODE_IT_FALLING ((uint32_t)0x10210000) /*!< External Interrupt Mode with Falling edge trigger detection */

#define GPIO_MODE_IT_RISING_FALLING ((uint32_t)0x10310000) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */


#define GPIO_MODE_EVT_RISING ((uint32_t)0x10120000) /*!< External Event Mode with Rising edge trigger detection */

#define GPIO_MODE_EVT_FALLING ((uint32_t)0x10220000) /*!< External Event Mode with Falling edge trigger detection */

#define GPIO_MODE_EVT_RISING_FALLING ((uint32_t)0x10320000) /*!< External Event Mode with Rising/Falling edge trigger detection */


GPIO的模式理解起來(lái)有點(diǎn)復(fù)雜。

GPIO可以被用作中斷源(GPIO_MODE_IT)和事件源(GPIO_MODE_EVT),這以后再敘述。

GPIO也可以用來(lái)接收模擬量(GPIO_MODE_ANALOG)。

如果GPIO原本是一個(gè)復(fù)用I/O,比如可以被作為串口模塊使用,要用GPIO_MODE_AF_x來(lái)設(shè)置。

GPIO可以被設(shè)置成輸入或者輸出。

當(dāng)被設(shè)置成輸出時(shí),有open-drain和push-pull兩者模式。我覺(jué)得理解這兩種模式對(duì)于像我一樣的模電知識(shí)較薄弱的人來(lái)說(shuō)有點(diǎn)困難。而且此類(lèi)知識(shí)的理解需要做實(shí)驗(yàn)來(lái)輔助,在沒(méi)有實(shí)驗(yàn)環(huán)境的情況下,還要學(xué)習(xí)電路仿真軟件的使用,學(xué)習(xí)成本較高,就不做敘述,直接說(shuō)結(jié)論了:

push-pull模式,速度快,但功耗大。

open-drain模式,功耗低,同時(shí)有線(xiàn)與功能。如果此模式芯片內(nèi)部沒(méi)有上拉電路,需要外接上拉電阻。


Pull


#define GPIO_NOPULL ((uint32_t)0x00000000) /*!< No Pull-up or Pull-down activation */

#define GPIO_PULLUP ((uint32_t)0x00000001) /*!< Pull-up activation */

#define GPIO_PULLDOWN

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

樹(shù)莓派,(英語(yǔ):Raspberry Pi,簡(jiǎn)寫(xiě)為RPi,別名為RasPi / RPI)是為學(xué)習(xí)計(jì)算機(jī)編程教育而設(shè)計(jì),只有信用卡大小的微型電腦,其系統(tǒng)基于Linux。隨著Windows 10 IoT的發(fā)布,用戶(hù)可以用上運(yùn)行...

關(guān)鍵字: 樹(shù)莓派 gpio gpio編程

串行外設(shè)接口(SPI)是微控制器和外圍IC(如傳感器、ADC、DAC、移位寄存器、SRAM等)之間使用最廣泛的接口之一。本文先簡(jiǎn)要說(shuō)明SPI接口,然后介紹ADI公司支持SPI的模擬開(kāi)關(guān)與多路轉(zhuǎn)換器,以及它們?nèi)绾螏椭鷾p少系...

關(guān)鍵字: gpio spi 串行外設(shè)接口

本文內(nèi)容是基于Android4.0源碼分析得到。android HAL是什么?為什么有它?硬件抽象層是介于android內(nèi)核kernel和上層之間的抽象出來(lái)的一層結(jié)構(gòu)。他是對(duì)linux驅(qū)動(dòng)的一個(gè)封裝,

關(guān)鍵字: Android hal android4.0源碼

一、什么是GPIO? GPIO,英文全稱(chēng)為General-Purpose IO ports,也就是通用IO口。嵌入式系統(tǒng)中常常有數(shù)量眾多,但是結(jié)構(gòu)卻比較簡(jiǎn)單的外部設(shè)備/電路,對(duì)這些設(shè)備/電路有的需要C

關(guān)鍵字: gpio 通用io口

//**********************************************************************//************************************...

關(guān)鍵字: gpio STM32

GPIO(General Purpose I/O Ports)意思為通用輸入/輸出端口,通俗地說(shuō),就是一些引腳,可以通過(guò)它們輸出高低電平或者通過(guò)它們讀入引腳的狀態(tài)-是高電平或是低電平。 S3C2410共有117個(gè)I...

關(guān)鍵字: ARM gpio 硬件介紹

Ⅰ、寫(xiě)在前面完事開(kāi)頭難,只要肯努力;師傅領(lǐng)進(jìn)門(mén),修行看個(gè)人;當(dāng)你看到本文,說(shuō)明你是幸運(yùn)的,作者接下來(lái)推出的一系列STM8S教程,將助你踏入STM8S的世界。本文是STM8S教程的開(kāi)始,寫(xiě)給剛?cè)腴T(mén)STM8S的朋友。學(xué)習(xí)本文

關(guān)鍵字: gpio stm8s 基礎(chǔ)知識(shí)

以下是驅(qū)動(dòng)的源碼。#includelinux/config.h//配置頭文件#includelinux/kernel.h//用于調(diào)用kmalloc和kfree#includelinux/sched.h//調(diào)度,進(jìn)程睡眠,...

關(guān)鍵字: gpio mini2440 驅(qū)動(dòng)led

一、API說(shuō)明HAL庫(kù)一共包含如下6個(gè)IO操作函數(shù):1、讀取某個(gè)引腳的電平狀態(tài):HAL_GPIO_ReadPin()2、寫(xiě)入某個(gè)引腳的電平狀態(tài):HAL_GPIO_WritePin()3、翻轉(zhuǎn)某個(gè)引腳的電平狀態(tài):HAL_G...

關(guān)鍵字: gpio LED STM32

GPIO作為常用個(gè)開(kāi)關(guān)量控制信號(hào),廣泛應(yīng)用于工業(yè)領(lǐng)域的數(shù)據(jù)采集和驅(qū)動(dòng)控制。當(dāng)GPIO配置為DI和DO時(shí),干節(jié)點(diǎn)與濕節(jié)點(diǎn)設(shè)計(jì)規(guī)范是否一致呢?GPIO配置為DI采集時(shí),隔離方案是選擇

關(guān)鍵字: gpio 電源技術(shù)解析
關(guān)閉