查看: 1505|回复: 1

【Silicon Labs EFR32xG22 开发板】评测四:蓝牙SDK和应用

[复制链接]

该用户从未签到

发表于 2020-7-10 13:15:29 | 显示全部楼层 |阅读模式
分享到:
本帖最后由 北方. 于 2020-7-10 12:56 编辑

1、启动Simplicity并登录,账户是需要首先注册好的。使用Simplicity或者试用版的IAR都是可以的,安装的时候也有Keil支持。
整个开发过程是基于GECKO平台,包括完整的库和安装包。
蓝牙协议的主要参数是,
Bluetooth 5.2,最大8个连接,最大传输速率1300 kbps over 2M。
使用Gecko的最大优点之一是通过了蓝牙联盟认证,就是已经给SIG交了钱的,用这个模块生产产品可以比较容易通过认证,打上蓝牙的标识。否则,就是山寨,哪怕比蓝牙5.2还高级。

2、开发库可以使用CMSIS,或者SiliconLab的简化版emlib。Host是可以通过UART接口管理控制这个协议,
7.PNG
具体协议,
7.PNG

3、上电测试3.1 首先把选择开关拨在AEM的位置,这个是进行能量检测的位置
2096556510.jpg
3.2 可以根据需要更换SDK
7.PNG
更新firmware
7.PNG
3.3 选择demo就可以直接进入演示
7.PNG

4 项目开发流程
创建项目
7.PNG
创建成功
7.PNG
编译并下载,就实现了项目开发的全过程。
7.PNG
7.PNG
代码简析
程序核心是appMain(),
在这个程序中实现了初始化,以及基本的蓝牙广播,连接等功能。这个程序使用nativeGecko编写,逻辑清晰。通过在线手册,可以知道API和各个程序的功能,更方便开发和使用。

  1. void appMain(gecko_configuration_t *pconfig)
  2. {
  3. #if DISABLE_SLEEP > 0
  4.   pconfig->sleep.flags = 0;
  5. #endif

  6.   /* Initialize debug prints. Note: debug prints are off by default. See DEBUG_LEVEL in app.h */
  7.   initLog();

  8.   /* Initialize stack */
  9.   gecko_init(pconfig);

  10.   while (1) {
  11.     /* Event pointer for handling events */
  12.     struct gecko_cmd_packet* evt;

  13.     /* if there are no events pending then the next call to gecko_wait_event() may cause
  14.      * device go to deep sleep. Make sure that debug prints are flushed before going to sleep */
  15.     if (!gecko_event_pending()) {
  16.       flushLog();
  17.     }

  18.     /* Check for stack event. This is a blocking event listener. If you want non-blocking please see UG136. */
  19.     evt = gecko_wait_event();

  20.     /* Handle events */
  21.     switch (BGLIB_MSG_ID(evt->header)) {
  22.       /* This boot event is generated when the system boots up after reset.
  23.        * Do not call any stack commands before receiving the boot event.
  24.        * Here the system is set to start advertising immediately after boot procedure. */
  25.       case gecko_evt_system_boot_id:

  26.         bootMessage(&(evt->data.evt_system_boot));
  27.         printLog("boot event - starting advertising\r\n");

  28.         /* Set advertising parameters. 100ms advertisement interval.
  29.          * The first parameter is advertising set handle
  30.          * The next two parameters are minimum and maximum advertising interval, both in
  31.          * units of (milliseconds * 1.6).
  32.          * The last two parameters are duration and maxevents left as default. */
  33.         gecko_cmd_le_gap_set_advertise_timing(0, 160, 160, 0, 0);

  34.         /* Start general advertising and enable connections. */
  35.         gecko_cmd_le_gap_start_advertising(0, le_gap_general_discoverable, le_gap_connectable_scannable);
  36.         break;

  37.       case gecko_evt_le_connection_opened_id:

  38.         printLog("connection opened\r\n");

  39.         break;

  40.       case gecko_evt_le_connection_closed_id:

  41.         printLog("connection closed, reason: 0x%2.2x\r\n", evt->data.evt_le_connection_closed.reason);

  42.         /* Check if need to boot to OTA DFU mode */
  43.         if (boot_to_dfu) {
  44.           /* Enter to OTA DFU mode */
  45.           gecko_cmd_system_reset(2);
  46.         } else {
  47.           /* Restart advertising after client has disconnected */
  48.           gecko_cmd_le_gap_start_advertising(0, le_gap_general_discoverable, le_gap_connectable_scannable);
  49.         }
  50.         break;

  51.       /* Events related to OTA upgrading
  52.          ----------------------------------------------------------------------------- */

  53.       /* Check if the user-type OTA Control Characteristic was written.
  54.        * If ota_control was written, boot the device into Device Firmware Upgrade (DFU) mode. */
  55.       case gecko_evt_gatt_server_user_write_request_id:

  56.         if (evt->data.evt_gatt_server_user_write_request.characteristic == gattdb_ota_control) {
  57.           /* Set flag to enter to OTA mode */
  58.           boot_to_dfu = 1;
  59.           /* Send response to Write Request */
  60.           gecko_cmd_gatt_server_send_user_write_response(
  61.             evt->data.evt_gatt_server_user_write_request.connection,
  62.             gattdb_ota_control,
  63.             bg_err_success);

  64.           /* Close connection to enter to DFU OTA mode */
  65.           gecko_cmd_le_connection_close(evt->data.evt_gatt_server_user_write_request.connection);
  66.         }
  67.         break;

  68.       /* Add additional event handlers as your application requires */

  69.       default:
  70.         break;
  71.     }
  72.   }
  73. }
复制代码



7.PNG
回复

使用道具 举报

该用户从未签到

发表于 2020-7-16 08:57:34 | 显示全部楼层
这个功耗能做到多少
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /1 下一条

手机版|小黑屋|与非网

GMT+8, 2024-4-25 07:47 , Processed in 0.133866 second(s), 18 queries , MemCache On.

ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

苏公网安备 32059002001037号

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.