NRF51822之GPIOTE介绍
- Note
- This library is obsolete and should not be used in new designs. Instead, you should use GPIOTE driver.
The general purpose Input/Output is organized in the nRF51 Series chips as one port with up to 32 I/Os (dependent on package) enabling access and control of up to 32 pins through one port. In most applications, the state of a GPIO or a change in state of a GPIO may trigger an application to take action or transition to another state.
The GPIO Tasks and Events (GPIOTE) provides functionality for accessing GPIO pins using tasks and events. The GPIO Task & Events (GPIOTE) library referred to as the the 'app_gpiote' in the SDK, facilitates application(s) to register for notification of change in state of one or more pins.
Since an application can consist of multiple independent modules, GPIOTE library allows several components to share the GPIOTE interrupt,each user defining a set of pins able to generate events to the user. When a GPIOTE interrupt occurs, the GPIOTE interrupt handler will identify pin transition(S) and notify each client registered for the transition.
- Note
- Components that register with the library are henceforth referred to as clients or users.
- This library uses GPIOTE driver, which must be enabled and properly configured in nrf_drv_config.h. You must specify GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS, which is the number of pins used for low power EVENTS_PORT including the pins used by this library.

The GPIOTE users are responsible for configuring all their corresponding pins, except the SENSE field, which should be initialized to GPIO_PIN_CNF_SENSE_Disabled.
The module specifies on which pins events should be generated if the pin(s) goes from low->high or high->low or both directions.
- Note
- Even if the application is using the Scheduler, the GPIOTE event handlers will be called directly from the GPIOTE interrupt handler.
- 尽管应用使用了Scheduler,但是GPTOTE的事件句柄还是直接来自GPTOTE中断句柄。
Initializing GPIOTE module
The initialization procedure must be performed before using any of the other APIs of the module. It is recommended to use initialization macro APP_GPIOTE_INIT instead of the routine app_gpiote_init as the former takes care of reserving needed memory for the each user requested in the MAX_USERS parameter of the macro. This parameter indicates how may users are going to be registering with the library.
// Macro to initialize GPIOTE module and reserving necessary memory for each of user. APP_GPIOTE_INIT(MAX_USERS);
- Note
- Module initialization should be performed only once. Specifically when using the macro to avoid reserving memory for each module several times.
Registering with GPIOTE
Each user must register itself with the module to be notified of change in state of GPIO. During registry, the user must provide callback handler to notify of a transition event and pin transitions its is interested in. 32-bit bitmask is used to represent 32 GPIO pins as shown in Figure 2 below. User can register for transition from high to low and/or low to high.

On successful registration, the user is assigned a user id and the user is expected to remember this identifier for all subsequent requests made to the module. This identifier is provided in the out parameter p_user_id. A sample registration is shown below.
// GPIOTE user identifier for the example module. static app_gpiote_user_id_t m_example_user_id; // GPIOTE event handler. static void example_gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low); . . . uint32_t low_to_high_bitmask = 0x0000000F; // Bitmask to be notified of transition from low to high for GPIO 0-3 uint32_t high_to_low_bitmask = 0x0000000E; // Bitmask to be notified of transition from high to low for GPIO 0-2 uint32_t retval; retval = app_gpiote_user_register(&m_example_user_id, low_to_high_bitmask, high_to_low_bitmask, example_gpiote_event_handler); if (retval != NRF_SUCCESS) { // Failed to register with user with GPIO module! }
Note
- It is possible for more than one user to register for same set/subset of GPIO pins; each of the concerned users will be notified of pin transition events.
By default, the GPIOTE is disabled on initialization. Therefore the GPIOTE has to be enabled by one of the users to start receiving GPIOTE state events. app_gpiote_user_enable is used to enable GPIOTE.
The following is a sample of registered user callback handling pin transition events.
// GPIOTE event handler. void example_gpiote_event_handler (uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low) { . . . if (event_pins_low_to_high & 0x00000001) { // GPIO pin 0 transitioned from low to high. // Take necessary action. } if (event_pins_high_to_low & 0x00000004) { // GPIO pin 2 transitioned from high to low. // Take necessary action. } . . . }
Enable/Disable GPIOTE
The GPIOTE module can be enabled or disabled by a registered user at any point of time. No state transition events are received when the GPIOTE is disabled. On initialization, by default, the GPIOTE is disabled.
The following code snippet disables and enables the GPIOTE.
uint32_t retval; // Enable notifications for example user module which is already registered. retval = app_gpiote_user_disable(m_example_user_id); if (retval != NRF_SUCCESS) { // Enabling notifications failed. Take corrective/needed action. . . } . . .
// Enable notifications for example user module which is already registered. retval = app_gpiote_user_enable(m_example_user_id); if (retval != NRF_SUCCESS) { // Enabling notifications failed. Take corrective/needed action. . . }
Reading GPIOTE State
A registered user can read the current state of GPIOs by reading the state information. The following code snippets demonstrates a module reading the state information.
uint32_t retval; uint32_t gpio_pin_state; retval = app_gpiote_pins_state_get(m_example_user_id,&gpio_pin_state); if (retval != NRF_SUCCESS) { // Failed to read state information. Take corrective action. } else { . . if (gpio_pins_state & 0x00000006) // Checks if pin one and two are set { // Take necessary action } . . }
NRF51822之GPIOTE介绍的更多相关文章
- NRF51822之GPIOTE使用
---恢复内容开始--- 在上篇介绍nrf51822的GPIOTE http://www.cnblogs.com/libra13179/p/5336580.html 我们现在开始下水游泳. /** @ ...
- nRF5芯片外设GPIO和GPIOTE介绍
nRF51/nRF52同时包含GPIO和GPIOTE两种外设,经常有人将两者搞混,今天我们就来介绍一下这2种外设有什么不同,及使用注意事项. GPIO和GPIOTE都属于芯片外设,但两者功能完全不一样 ...
- NRF51822之pstorage介绍
This information applies to the following SoftDevices: S110, S120, S130, S310 Introduction Persisten ...
- nRF51822外设应用[2]:GPIOTE的应用-按键检测
版权声明:本文为博主原创文章,转载请注明作者和出处. 作者:强光手电[艾克姆科技-无线事业部] 1. nRF51822寄存器类型 nRF51822的寄存器和一般的单片机有所差别,nRF51822 ...
- [nRF51822] 5、 霸屏了——详解nRF51 SDK中的GPIOTE(从GPIO电平变化到产生中断事件的流程详解)
:由于在大多数情况下GPIO的状态变化都会触发应用程序执行一些动作.为了方便nRF51官方把该流程封装成了GPIOTE,全称:The GPIO Tasks and Events (GPIOTE) . ...
- nrf51822裸机教程-GPIOTE
GPIO通常都会具有中断功能,上一讲的GPIO中并没有涉及到中断的相关寄存器. 51822将GPIO的中断相关做成了一个单独的模块GPIOTE,这个模块不仅提供了GPIO的中断功能,同时提供了 通过t ...
- nrf51822微信开发2:[转]airkiss/airsync介绍
"微信蓝牙"专题共分为8部分 1.airkiss/airsync介绍 2.eclipes的j2ee软件使用教程 3.微信公众号使用Dome(airkiss/airsync) 4.新 ...
- [编译] 4、在Linux下搭建nRF51822的开发烧写环境(makefile版)
星期日, 09. 九月 2018 07:51下午 - beautifulzzzz 1.安装步骤 1) 从GNU Arm Embedded Toolchain官网下载最新的gcc-arm工具链,写文章时 ...
- [nRF51822] 14、浅谈蓝牙低功耗(BLE)的几种常见的应用场景及架构(科普类干货)
蓝牙在短距离无线通信领域占据举足轻重的地位—— 从手机.平板.PC到车载设备, 到耳机.游戏手柄.音响.电视, 再到手环.电子秤.智能医疗器械(血糖仪.数字血压计.血气计.数字脉搏/心率监视器.数字体 ...
随机推荐
- eclipse下提交job时报错mapred.JobClient: No job jar file set. User classes may not be found.
错误信息: 11/10/14 13:52:07 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. A ...
- tcp的三次握手及四次挥手(连接与中断流程)
连接的三次握手: 1握.client向server发送连接请求,发送的报文是:syn=1,seq number=生成的随机数x . 这时client的状态是SYN_SEND 2握.server从sy ...
- Eclipse启动Tomcat时45秒超时的解决方法
Eclipse启动Tomcat时,默认配置的启动超时时长为45秒.假若项目需要加载的东西比较多,启动时间会比较久,如果启动超过45秒将会报错.有两种解决途径,方法只有一个,就是修改启动时间. 1. 修 ...
- IOS 获取最新设备型号方法
1.IOS 获取最新设备型号方法列表最新对照表:http://theiphonewiki.com/wiki/Models方法: #import "sys/utsname.h” struct ...
- Centos6.4 yum安装MariaDB5.5
vi /etc/yum.repos.d/MariaDB.repo 加入下面内容 [mariabd]name=MariaDBbaseurl=http://yum.mariadb.org/5.5.34/c ...
- 【BZOJ】2761: [JLOI2011]不重复数字(set+巨水题+超坑题)
http://www.lydsy.com/JudgeOnline/problem.php?id=2761 太水了,不说了. 但是这格式错误我已经没话说了....行末不能有空格 #include < ...
- ARC指南1 - strong和weak指针
一.简介 ARC是自iOS 5之后增加的新特性,完全消除了手动管理内存的烦琐,编译器会自动在适当的地方插入适当的retain.release.autorelease语句.你不再需要担心内存管理,因 ...
- NSString 处理技巧:分割字符串
摘要 string类型是objective-c中用的最多的类型之一,有时会出现字符串中有我们不想要的字符. 如 "hello world"中的空格,或是"hello/wo ...
- Solve error: 'class vtkImageActor' has no member named 'SetInput'
Replacement of SetInput() with SetInputData() and SetInputConnection() someFilter->SetInput(someR ...
- thinkphp 代码执行
相关漏洞:http://loudong.360.cn/vul/info/id/2919 ThinkPHP 开启lite模式后,会加载ThinkPHP/Extend/Mode/Lite/Dispache ...