nrf51822/nrf52832开发过程中一些常用的API函数
2017-08-23 21:50
1311 查看
作者:李大闯 2017/8/23 21:51
配置引脚为输出
static __INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
配置引脚为输入(pull_config:配置上拉/下拉或不拉)
static __INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
引脚置位函数(拉高引脚)
static __INLINE void nrf_gpio_pin_set(uint32_t pin_number)
引脚清0函数(拉低引脚)
static __INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
引脚状态取反(引脚电平反转)
static __INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
nrf51822外部中断配置示例:
//按键中断初始化
void gpiote_init(void)
{
nrf_drv_gpiote_init();
nrf_drv_gpiote_in_config_t pin_config;
pin_config.hi_accuracy = true;
pin_config.is_watcher = false;//这里如果设置为true会影响功耗
pin_config.pull = NRF_GPIO_PIN_PULLUP;//按键配置成内部上拉
pin_config.sense = NRF_GPIOTE_POLARITY_HITOLO;//配置为下降沿触发
nrf_drv_gpiote_in_init (KEY_IN, &pin_config, key_event_handler);//设置中断回调函数
nrf_drv_gpiote_in_event_enable (KEY_IN, true);//使能按键中断
}
//中断处理函数
void key_event_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
/*开关机按键一下就启动按键扫描定时器*/
if(!system_status.chrg_en)//如果没有在充电状态下
{
key_press_flag = true;
key_timer_start();
}
}
nrf51822 app_timer使用示例:
APP_TIMER_DEF (flash_timer); //flash数据处理定时器
#define FLASH_STATUS_TIME_INTERVAL 30 //用于算法定时器操作时间间隔设置
//app_timer初始化
void timers_init (void)
{
uint32_t err_code;
// Create timers.
err_code = app_timer_create (&flash_timer, APP_TIMER_MODE_REPEATED, flash_processing_timeout_handler);//创建一个用于flash操作的定时器,设置为重复定时器,指定中断回调函数。
APP_ERROR_CHECK (err_code);
}
/*****************************************************************
*功 能:用于操作flash功能时间计时
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_processing_timeout_handler (void * p_context)
{
UNUSED_PARAMETER (p_context);
system_status.flash = true;//大多数情况下,只在定时器中断里面设置标志位,具体的操作在for(;;)循环中处理
}
/*****************************************************************
*功 能:使能flash操作定时器
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_timer_start (void)
{
uint32_t err_code;
err_code = app_timer_start (flash_timer, APP_TIMER_TICKS (FLASH_STATUS_TIME_INTERVAL, 0), NULL);
APP_ERROR_CHECK (err_code);
}
/*****************************************************************
*功 能:停止flash操作定时器
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_timer_stop (void)
{
uint32_t err_code;
err_code = app_timer_stop (flash_timer);
APP_ERROR_CHECK (err_code);
}
配置引脚为输出
static __INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
配置引脚为输入(pull_config:配置上拉/下拉或不拉)
static __INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
引脚置位函数(拉高引脚)
static __INLINE void nrf_gpio_pin_set(uint32_t pin_number)
引脚清0函数(拉低引脚)
static __INLINE void nrf_gpio_pin_clear(uint32_t pin_number)
引脚状态取反(引脚电平反转)
static __INLINE void nrf_gpio_pin_toggle(uint32_t pin_number)
nrf51822外部中断配置示例:
//按键中断初始化
void gpiote_init(void)
{
nrf_drv_gpiote_init();
nrf_drv_gpiote_in_config_t pin_config;
pin_config.hi_accuracy = true;
pin_config.is_watcher = false;//这里如果设置为true会影响功耗
pin_config.pull = NRF_GPIO_PIN_PULLUP;//按键配置成内部上拉
pin_config.sense = NRF_GPIOTE_POLARITY_HITOLO;//配置为下降沿触发
nrf_drv_gpiote_in_init (KEY_IN, &pin_config, key_event_handler);//设置中断回调函数
nrf_drv_gpiote_in_event_enable (KEY_IN, true);//使能按键中断
}
//中断处理函数
void key_event_handler (nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
/*开关机按键一下就启动按键扫描定时器*/
if(!system_status.chrg_en)//如果没有在充电状态下
{
key_press_flag = true;
key_timer_start();
}
}
nrf51822 app_timer使用示例:
APP_TIMER_DEF (flash_timer); //flash数据处理定时器
#define FLASH_STATUS_TIME_INTERVAL 30 //用于算法定时器操作时间间隔设置
//app_timer初始化
void timers_init (void)
{
uint32_t err_code;
// Create timers.
err_code = app_timer_create (&flash_timer, APP_TIMER_MODE_REPEATED, flash_processing_timeout_handler);//创建一个用于flash操作的定时器,设置为重复定时器,指定中断回调函数。
APP_ERROR_CHECK (err_code);
}
/*****************************************************************
*功 能:用于操作flash功能时间计时
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_processing_timeout_handler (void * p_context)
{
UNUSED_PARAMETER (p_context);
system_status.flash = true;//大多数情况下,只在定时器中断里面设置标志位,具体的操作在for(;;)循环中处理
}
/*****************************************************************
*功 能:使能flash操作定时器
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_timer_start (void)
{
uint32_t err_code;
err_code = app_timer_start (flash_timer, APP_TIMER_TICKS (FLASH_STATUS_TIME_INTERVAL, 0), NULL);
APP_ERROR_CHECK (err_code);
}
/*****************************************************************
*功 能:停止flash操作定时器
*参 数: 无
*返回值: 无
*****************************************************************/
void flash_timer_stop (void)
{
uint32_t err_code;
err_code = app_timer_stop (flash_timer);
APP_ERROR_CHECK (err_code);
}
相关文章推荐
- Android开发过程中常用一些框架
- iOS开发过程中使用一些常用的宏
- 项目开发过程中一些常用的工具[持续更新中]
- 软件开发过程中常用到的一些工具
- 开发过程中的一些常用技巧
- ios开发过程中一些常用地址收集整理
- Android学习笔记3-开发过程中一些常用操作
- Swift开发过程中常用到的一些使用技巧和注意的地方
- Mac OS X & Linux下搭建Nrf51822开发环境与编译过程
- 开发YXPack32.dll过程中的一些经验
- 分享一些前端开发中最常用的JS代码片段
- FaceYe.com开发过程中的一些感受
- iPhone 开发过程中的一些小技术的…
- android data service开发过程常用的抓取log的命令
- 一些web开发中常用的、做成cs文件的js代码
- 开发过程遇到的一些问题(一)
- 网站开发过程中常用参考手册下载地址
- 讲解WordPress开发中一些常用的debug技巧
- Linux程序开发、编译过程相关的一些指令
- Android 开发过程中总计的一些经验教训