一. 测试平台
参考文章:
https://devzone.nordicsemi.com/nordic/tutorials/b/software-development-kit/posts/radio-notification
本篇文章主要介绍如何在程序中加入radio notification功能。
整个测试平台如下:
环境:win10,64位,MDK集成开发环境.
SDK:nRF5_SDK_15.2
协议栈:s132_nrf52_6.1_softdevice.hex.
硬件平台:pca10040开发板.
二. 作用
- 准确知道蓝牙发送数据的时间;
- 解决资源使用的冲突,数据发送和ADC采样同时进行,导致ADC采样数据出错;
- 将蓝牙发送功能与其他功能彻底分割。
三.Application移植
在main.c中添加一下程序:
- 添加头文件引用
#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. */
};