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到车载设备, 到耳机.游戏手柄.音响.电视, 再到手环.电子秤.智能医疗器械(血糖仪.数字血压计.血气计.数字脉搏/心率监视器.数字体 ...
随机推荐
- exec命令
exec 命令实例 find . -name "*.cc" -exec grep -P -n -H --color=auto "[^\w]main[^\w]" ...
- LCIS HDOJ 4512 吉哥系列故事——完美队形I
题目传送门 题意:中文题面 分析:LCIS应用:设置b[]为a[]的反转,然后LCIS,若相等的是自己本身,则+1, 否则+2 代码: #include <cstdio> #include ...
- win 7 普通家庭版 装IIS
每当一个程序员入职的时候,几乎都会干一件事情,就是重装操作系统,这是一场不易之战: 1)耗时太长: 2)容易遇到怪异的系统行为. 1.win7为毛装不上VS2012 先装一个win7 x64 旗舰版, ...
- windows 8 系统部署IIS并发布网站
企业用户可以在已经部署了windows 8 的电脑中通过部署IIS服务器来发布自己公司的企业内部网站实现对企业的网络办公的管理工作. 准备篇 IIS的添加和运行 一.IIS的添加 1.请进入“控制面板 ...
- BZOJ4310 : 跳蚤
首先求出后缀数组,得到本质不同的子串的个数. 然后二分答案,每次先通过后缀数组求出第$mid$小的子串,然后贪心进行检验. 检验的时候,从后往前贪心,每次加入一个后缀,如果不能加了,那就划为一段. 时 ...
- COJ559 回文
试题描述 给定字符串,求它的回文子序列个数.回文子序列反转字符顺序后仍然与原序列相同.例如字符串aba中,回文子序列为"a", "a", "aa&qu ...
- Flex httpservice返回值类型和处理 (转)
这两天在考虑flex与后端java服务交互的问题.在采用BlazeDS的Remote Object方式,还是传统的http service方式之间徘徊了一段时间 采用BlazeDS的Remote Ob ...
- jdk+myeclipse配置安装相关步骤
1.JDK的安装JDK 版本:7u25 安装路径:c:\java(注意:装不装公共jre都可,自己可以选择安装到哪里)环境变量配置:(1)JAVA_HOME:C:\Java(就是你安装jdk的目录 ...
- Html - 幽灵键盘
Css ;text-align:center} #shurufa_gongneng,#shurufa_num_123,#shurufa_num_456,#shurufa_num_789{} #shur ...
- PHP中有关Session的函数比较多,最常用到的也就这么几个函数
php中的cookie与session技术详解 一.cookie介绍 cookie常用于识别用户.cookie是服务器留在用户计算机中的小文件.每当相同的计算机通过浏览器请求页面时,它同时会发送coo ...