硬件——nrf51822第三篇,按键控制小灯

 

 

现象是按键按下,小灯亮,按键抬起,小灯灭。

从这一节我们细致剖析gpio口的设置:

nrf51822片上一共有32个数字引脚,分为4个port,如下:

port 0    pin 0-7

port 1    pin 8-15

port 2    pin 16-23

port 3    pin 24-31

每个gpio都有8个寄存器对其参数进行配置,这些寄存器均为32位,每个位对应每个gpio。

三个设置引脚输入输出寄存器:DIR   DIRSET    DIRCLR

三个设置引脚高低电平寄存器:OUT   OUTSET   OUTCLR 

一个读引脚电平寄存器:IN

一个引脚配置寄存器:PIN_CNF[n]

接下来重点介绍PIN_CNF[n],在gpio的配置中,用的比较多,该寄存器有32个,分别对应32个gpio。

第0位:设置gpio接口方向

第1位:设置input buffer 是否启用 ,作用为再输入禁用时可以节省电流降低功耗,这对于某些对功耗要求较高的场合尤为试用。

            当有输入时或者读取gpio电平时都要使能input buffer,输出时为了节省电流也要关闭该模块。

第2-3位:设置上、下拉电阻的使能

第8-10位:设置gpio的驱动能力

第16-17位:设置监测电平的极性  对外部电平的检测(sense功能),通俗来说可以理解为外部中断,其原理为gpio检测到高,低电平时会产生PORT event,

                                                     进而唤醒CPU或者响应相应的中断机制。

 

这里应该插入一张图片:

 

 

下面我们重新来看nrf_gpio.h文件下的函数:

nrf_gpio_range_cfg_output(uint32_t pin_range_start, uint32_t pin_range_end)  可以设置好几个引脚

:没有电平检测;驱动能力是最低等级;没有上下拉;没有启动input buffer;输出;

 nrf_gpio_range_cfg_input(uint32_t pin_range_start, uint32_t pin_range_end, nrf_gpio_pin_pull_t pull_config)  可以设置好几个引脚

:没有电平检测;驱动能力是最低等级;上下拉是根据传入的参数设定的;启动input buffer;输入;

nrf_gpio_cfg_output(uint32_t pin_number)  设置一个引脚

:没有电平检测;驱动能力是最低等级;没有上下拉;没有启动input buffer;输出;

nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)  设置一个引脚

:没有电平检测;驱动能力是最低等级;上下拉根据传入参数而定;启动input buffer;输入;

nrf_gpio_cfg_sense_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config, nrf_gpio_pin_sense_t sense_config)

:电平检测高或低由传入参数而定;驱动能力是最低等级;上下拉根据传入参数而定;启动input buffer;输入;

nrf_gpio_pin_dir_set(uint32_t pin_number, nrf_gpio_pin_dir_t direction)

:没有电平检测;驱动能力是最低等级;没有上下拉;启动input buffer;输入输出由传入参数决定;

nrf_gpio_pin_set(uint32_t pin_number)  //设置某个引脚为高电平

nrf_gpio_pin_clear(uint32_t pin_number)//设置某个引脚为低电平

nrf_gpio_pin_toggle(uint32_t pin_number)//翻转某个引脚的电平

nrf_gpio_pin_write(uint32_t pin_number, uint32_t value) //写某个引脚的电平,可以写高,也可以写低

nrf_gpio_pin_read(uint32_t pin_number) //读取某个引脚的电平

nrf_gpio_word_byte_write(volatile uint32_t * word_address, uint8_t byte_no, uint8_t value) //写多个port的值

nrf_gpio_word_byte_read(const volatile uint32_t* word_address, uint8_t byte_no) //读多个port的值

nrf_gpio_port_dir_set(nrf_gpio_port_select_t port, nrf_gpio_port_dir_t dir) //Function for setting the direction of a port.

nrf_gpio_port_read(nrf_gpio_port_select_t port) //Function for reading a GPIO port.

nrf_gpio_port_write(nrf_gpio_port_select_t port, uint8_t value) //Function for writing to a GPIO port.

nrf_gpio_port_set(nrf_gpio_port_select_t port, uint8_t set_mask) //Function for setting individual pins on GPIO port.

nrf_gpio_port_clear(nrf_gpio_port_select_t port, uint8_t clr_mask) //Function for clearing individual pins on GPIO port.

 

转载于:https://www.cnblogs.com/chulin/p/7118468.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
nrf51822中文参考手册,nRF51822 是一款集成nRF51x系列无线收发器的超低功耗的片上系统 (Soc) , 包含一个32位ARM Cortex-M0 CPU , flash 存储器和模拟、数字外设。NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Liability disclaimer Nordic Semiconductor ASa reserves the right to make changes without further notice to the product to improve reliability, function or design. Nordic Semiconductor asa does not assume any liability arising out of the application or use of any product or circuits described herein ife support applications Nordic Semiconductor's products are not designed for use in life support appliances, devices, or systems where malfunction of these products can reasonably be expected to result in personal injury. Nordic Semiconductor ASa customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Nordic Semiconductor ASA for any damages resulting from such improper use or sale Contact details Foryournearestdistributorpleasevisitwww.nordicsemi.com Information regarding product updates, downloads, and technical support can be accessed through your My Page account on our home page Main office: Otto Nielsens veg 12 Mailing address: Nordic Semiconductor 7052 Trondheim P.O. Box 2336 Norway 7004 Trondhe Phone:+4772898900 Norway 4772898989 画N远 NS-EN ISO 9001 CERTIFICATEDFIRM RoHS and reach statement Nordic semiconductor's products meet the requirements of Directive 2002/95/EC of the European Parliament and of the Council on the restriction of Hazardous Substances(roHS)and the requirements of the reach regulation(EC 1907/2006)on Registration, Evaluation, Authorization and Restriction of Chemicals. The SvHC(Substances of Very High Concern) candidate list is continually being updated Complete hazardous substance reports material composition reports and latest version of nordics reach statementcanbefoundonourwebsitewww.nordicsemicom Page 2 of 67 NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Datasheet status Status Description Objective Pro

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值