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到车载设备, 到耳机.游戏手柄.音响.电视, 再到手环.电子秤.智能医疗器械(血糖仪.数字血压计.血气计.数字脉搏/心率监视器.数字体 ...
随机推荐
- char *c和char c[]区别
char *c和char c[]区别 问题引入:在实习过程中发现了一个以前一直默认的错误,同样char *c = "abc"和char c[]="abc",前者 ...
- loadrunner中创建唯一随机数
常用的时间唯一脚本: Action() { int id, scid; char *vuser_group,strid[5]; char proposalNo[1024]; int i; ...
- loadrunner个版本历程
1.工具介绍: LoadRunner是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找问题, LoadRunner能够对整个企业架构进行测试.通过 ...
- jmeter断言
响应断言:检查的内容,如果是变量,设置为变量 断言结果:断言的结果 断言持续时间:请求事件不能超过设置的断言持续时间 Size Assertion:断言字节大小
- xcode命令行编译时:codesign命令,抛出“User interaction is not allowed.”异常 的处理
之前正常运行的hudson iOS编译服务器slave节点,忽然出现编译失败.发现原因有2个: 第一个原因是编译机上用来签名的用户帐号过期,第二个原因是操作系统和xCode升级造成的. 对于第一个,重 ...
- 水题 ZOJ 3869 Ace of Aces
题目传送门 水题,找出出现次数最多的数字,若多个输出Nobody //#include <bits/stdc++.h> //using namespace std; #include &l ...
- 操作properties文件,注意抹掉最前面的"file:"
package com.xiewanzhi.property; import java.io.BufferedInputStream; import java.io.File; import java ...
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- Idea_Maven配置
操作方式:在install上右键——>Run***install 出现Run Configurations ——>右键——>Edit Run Configuration 1.Inst ...
- JAVA操作COOKIE
JAVA操作COOKIE 1.设置Cookie Cookie cookie = new Cookie("key", "value"); cookie.setMa ...