nrf51822/nrf52832开发过程中一些常用的API函数

来源:互联网 发布:商城系统数据库设计 编辑:程序博客网 时间:2024/05/24 05:14

作者:李大闯    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);}






原创粉丝点击