nrf51822 app timer简单使用

只关心应用,不关系内部实现机制:



是时候秀一波操作了:

随便找一个sdk里面的ble例子,我使用的是sdk9里的ble_app_uart_s110_pca10028例程,工程路径为:XX\nRF51_SDK_9.0.0_2e23562\examples\ble_peripheral\ble_app_uart\pca10028\s110\arm4

代码很简单,只是用app timer来翻转一个led灯,我的板子是18脚连着一个led灯。

app_timer_id_t my_timer;
static void my_timer_handler(void * p_context)
{
    nrf_gpio_pin_toggle(18);
}

/**@brief Application main function.
 */
int main(void)
{
    uint32_t err_code;
    bool erase_bonds;
    uint8_t  start_string[] = START_STRING;
    
    // Initialize.
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    uart_init();
    buttons_leds_init(&erase_bonds);
    ble_stack_init();

    nrf_gpio_pin_dir_set(18, NRF_GPIO_PIN_DIR_OUTPUT);
    app_timer_create(&my_timer, APP_TIMER_MODE_REPEATED, my_timer_handler);
    app_timer_start(my_timer, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL);
    while(1);

    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    printf("%s",start_string);

    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    
    // Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
编译完下载进去就可以看到led闪烁了



  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
nrf51822中文参考手册,nRF51822 是一款集成nRF51x系列无线收发器的超低功耗的片上系统 (Soc) , 包含一个32位ARM Cortex-M0 CPU , flash 存储器和模拟、数字外设。NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Liability disclaimer Nordic Semiconductor ASa reserves the right to make changes without further notice to the product to improve reliability, function or design. Nordic Semiconductor asa does not assume any liability arising out of the application or use of any product or circuits described herein ife support applications Nordic Semiconductor's products are not designed for use in life support appliances, devices, or systems where malfunction of these products can reasonably be expected to result in personal injury. Nordic Semiconductor ASa customers using or selling these products for use in such applications do so at their own risk and agree to fully indemnify Nordic Semiconductor ASA for any damages resulting from such improper use or sale Contact details Foryournearestdistributorpleasevisitwww.nordicsemi.com Information regarding product updates, downloads, and technical support can be accessed through your My Page account on our home page Main office: Otto Nielsens veg 12 Mailing address: Nordic Semiconductor 7052 Trondheim P.O. Box 2336 Norway 7004 Trondhe Phone:+4772898900 Norway 4772898989 画N远 NS-EN ISO 9001 CERTIFICATEDFIRM RoHS and reach statement Nordic semiconductor's products meet the requirements of Directive 2002/95/EC of the European Parliament and of the Council on the restriction of Hazardous Substances(roHS)and the requirements of the reach regulation(EC 1907/2006)on Registration, Evaluation, Authorization and Restriction of Chemicals. The SvHC(Substances of Very High Concern) candidate list is continually being updated Complete hazardous substance reports material composition reports and latest version of nordics reach statementcanbefoundonourwebsitewww.nordicsemicom Page 2 of 67 NORDIC SEMICONDUCTOR nRF51822 Product Specification v1.3 Datasheet status Status Description Objective Pro
以下是nRF52832芯片使用FTMS协议的一个简单示例,供您参考: ```c #include <stdbool.h> #include <stdint.h> #include "nrf.h" #include "nordic_common.h" #include "boards.h" #include "app_error.h" #include "bsp.h" #include "nrf_delay.h" #include "ble.h" #include "ble_hci.h" #include "ble_advdata.h" #include "ble_advertising.h" #include "ble_conn_params.h" #include "ble_nus.h" #include "ble_ftms.h" #include "peer_manager.h" #include "peer_manager_handler.h" #include "fds.h" #include "fstorage.h" // 定义FTMS服务UUID #define BLE_UUID_FTMS_SERVICE 0x180D // 定义FTMS特性UUID #define BLE_UUID_FTMS_FEATURE 0x2ACC // 定义FTMS数据UUID #define BLE_UUID_FTMS_DATA 0x2ABD // 定义设备名称 #define DEVICE_NAME "MyFTMS" // 定义连接参数 #define MIN_CONN_INTERVAL MSEC_TO_UNITS(100, UNIT_1_25_MS) #define MAX_CONN_INTERVAL MSEC_TO_UNITS(200, UNIT_1_25_MS) #define SLAVE_LATENCY 0 #define CONN_SUP_TIMEOUT MSEC_TO_UNITS(4000, UNIT_10_MS) // 定义广播参数 #define APP_ADV_INTERVAL 64 #define APP_ADV_TIMEOUT 18000 // 定义NUS服务句柄 BLE_NUS_DEF(m_nus); // 定义FTMS服务句柄 BLE_FTMS_DEF(m_ftms); // 定义广播参数和连接参数 static ble_gap_adv_params_t m_adv_params; static ble_gap_conn_params_t m_conn_params = { .min_conn_interval = MIN_CONN_INTERVAL, .max_conn_interval = MAX_CONN_INTERVAL, .slave_latency = SLAVE_LATENCY, .conn_sup_timeout = CONN_SUP_TIMEOUT }; // 定义广播数据 static ble_advdata_t m_advdata = { .flags = BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED, .name_type = BLE_ADVDATA_FULL_NAME, .include_appearance = false, .manufacturer_specific_data.p_data = NULL, .manufacturer_specific_data.size = 0 }; // 定义广播名称 static ble_advdata_manuf_data_t m_adv_manuf_data = { .company_identifier = 0x0059, // Nordic Semiconductor .data.p_data = (uint8_t*) DEVICE_NAME, .data.size = sizeof(DEVICE_NAME) }; // 定义广播数据结构 static ble_advdata_manuf_data_t m_adv_data[] = { &m_adv_manuf_data }; // 广播事件处理函数 static void on_adv_evt(ble_adv_evt_t ble_adv_evt) { switch (ble_adv_evt) { case BLE_ADV_EVT_FAST: case BLE_ADV_EVT_IDLE: break; default: break; } } // 初始化广播参数 static void adv_params_init(void) { memset(&m_adv_params, 0, sizeof(m_adv_params)); m_adv_params.type = BLE_GAP_ADV_TYPE_ADV_IND; m_adv_params.p_peer_addr = NULL; m_adv_params.interval = APP_ADV_INTERVAL; m_adv_params.timeout = APP_ADV_TIMEOUT; } // 初始化连接参数 static void conn_params_init(void) { ret_code_t err_code; ble_conn_params_init_t cp_init; memset(&cp_init, 0, sizeof(cp_init)); cp_init.p_conn_params = &m_conn_params; cp_init.first_conn_params_update_delay = APP_TIMER_TICKS(5000); cp_init.next_conn_params_update_delay = APP_TIMER_TICKS(30000); cp_init.max_conn_params_update_count = 3; cp_init.start_on_notify_cccd_handle = BLE_GATT_HANDLE_INVALID; cp_init.disconnect_on_fail = true; cp_init.evt_handler = NULL; err_code = ble_conn_params_init(&cp_init); APP_ERROR_CHECK(err_code); } // 广播初始化 static void advertising_init(void) { ret_code_t err_code; ble_advdata_t advdata; ble_adv_modes_config_t options; memset(&options, 0, sizeof(options)); memset(&advdata, 0, sizeof(advdata)); advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.include_appearance = false; advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE; options.ble_adv_fast_enabled = BLE_ADV_FAST_ENABLED; options.ble_adv_fast_interval = APP_ADV_INTERVAL; options.ble_adv_fast_timeout = APP_ADV_TIMEOUT; options.ble_adv_slow_enabled = BLE_ADV_SLOW_ENABLED; options.ble_adv_slow_interval = APP_ADV_INTERVAL; options.ble_adv_slow_timeout = APP_ADV_TIMEOUT; err_code = ble_advertising_init(&advdata, NULL, &options, on_adv_evt, NULL); APP_ERROR_CHECK(err_code); ble_advertising_conn_cfg_tag_set(0); } // FTMS服务初始化 static void ftms_init(void) { ret_code_t err_code; ble_ftms_init_t ftms_init; memset(&ftms_init, 0, sizeof(ftms_init)); ftms_init.evt_handler = NULL; ftms_init.feature = BLE_FTMS_FEATURE_TREADMILL; err_code = ble_ftms_init(&m_ftms, &ftms_init); APP_ERROR_CHECK(err_code); } // 应用程序初始化 void init(void) { ret_code_t err_code; err_code = nrf_sdh_enable_request(); APP_ERROR_CHECK(err_code); err_code = app_timer_init(); APP_ERROR_CHECK(err_code); err_code = ble_stack_init(); APP_ERROR_CHECK(err_code); err_code = gap_params_init(); APP_ERROR_CHECK(err_code); conn_params_init(); adv_params_init(); advertising_init(); ftms_init(); } // 应用程序主函数 void main(void) { init(); advertising_start(); while (true) { power_manage(); } } ``` 这个示例程序实现了一个基本的FTMS服务,包括广播、连接、服务初始化和数据传输等功能。需要注意的是,这个示例程序仅供参考,实际使用时需要根据具体的应用场景进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值