Nrf52832添加radio notification 功能

一. 测试平台

参考文章:

https://devzone.nordicsemi.com/nordic/tutorials/b/software-development-kit/posts/radio-notification

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__ble__radio__notification.html

本篇文章主要介绍如何在程序中加入radio notification功能。

整个测试平台如下:

环境:win10,64位,MDK集成开发环境.
SDK:nRF5_SDK_15.2
协议栈:s132_nrf52_6.1_softdevice.hex.
硬件平台:pca10040开发板.

二. 作用

  1. 准确知道蓝牙发送数据的时间;
  2. 解决资源使用的冲突,数据发送和ADC采样同时进行,导致ADC采样数据出错;
  3. 将蓝牙发送功能与其他功能彻底分割。

三.Application移植

在main.c中添加一下程序:

  1. 添加头文件引用
#include nrf_nvic.h

     2. 添加初始化函数

/**@brief Function for initializing Radio Notification Software Interrupts.*/
	uint32_t radio_notification_init(uint32_t irq_priority, uint8_t notification_type, uint8_t notification_distance)
	{
    		uint32_t err_code;
    		err_code = sd_nvic_ClearPendingIRQ(SWI1_IRQn);
    		if (err_code != NRF_SUCCESS)
    	{
        		return err_code;
    	}
    	err_code = sd_nvic_SetPriority(SWI1_IRQn, irq_priority);
    	if (err_code != NRF_SUCCESS)
    	{
        		return err_code;
    	}
    	err_code = sd_nvic_EnableIRQ(SWI1_IRQn);
    	if (err_code != NRF_SUCCESS)
    	{
        		return err_code;
    	}
    	// Configure the event
    	return sd_radio_notification_cfg_set(notification_type, notification_distance);
	}

     3.  添加中断函数

/**@brief Software interrupt 1 IRQ Handler, handles radio notification interrupts.
*/
void SWI1_IRQHandler(bool radio_evt)
{
    	if (radio_evt)
	{
	//add your function
        	nrf_gpio_pin_toggle(BSP_LED_2); //Toggle the status of the LED on each radio notification event
    	}
}

         4. 在main函数中添加初始化

                一般放在ble_stack_init();之后     


​err_code = radio_notification_init(3, NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE, 
			NRF_RADIO_NOTIFICATION_DISTANCE_800US);
	APP_ERROR_CHECK(err_code);

参数定义:

      ①中断优先级

      ②中断触发模式

/**@brief Radio notification types. */
enum NRF_RADIO_NOTIFICATION_TYPES
{
    NRF_RADIO_NOTIFICATION_TYPE_NONE = 0,        /**< The event does not have a radio         notification signal. */
    NRF_RADIO_NOTIFICATION_TYPE_INT_ON_ACTIVE,   /**开启radio时进入中断 */
    NRF_RADIO_NOTIFICATION_TYPE_INT_ON_INACTIVE, /**关闭radio时进入中断 */
    NRF_RADIO_NOTIFICATION_TYPE_INT_ON_BOTH,     /**开启和关闭radio都会进入中断 */
};

       ③中断与实际radio的间隔时间

/**@brief Radio notification distances. */
enum NRF_RADIO_NOTIFICATION_DISTANCES
{
  NRF_RADIO_NOTIFICATION_DISTANCE_NONE = 0, /**< The event does not have a notification. */
  NRF_RADIO_NOTIFICATION_DISTANCE_800US,    /**< The distance from the active notification to start of radio activity. */
  NRF_RADIO_NOTIFICATION_DISTANCE_1740US,   /**< The distance from the active notification to start of radio activity. */
  NRF_RADIO_NOTIFICATION_DISTANCE_2680US,   /**< The distance from the active notification to start of radio activity. */
  NRF_RADIO_NOTIFICATION_DISTANCE_3620US,   /**< The distance from the active notification to start of radio activity. */
  NRF_RADIO_NOTIFICATION_DISTANCE_4560US,   /**< The distance from the active notification to start of radio activity. */
  NRF_RADIO_NOTIFICATION_DISTANCE_5500US    /**< The distance from the active notification to start of radio activity. */
};

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值