|
本帖最后由 北方. 于 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接口管理控制这个协议,
具体协议,
3、上电测试3.1 首先把选择开关拨在AEM的位置,这个是进行能量检测的位置
3.2 可以根据需要更换SDK
更新firmware
3.3 选择demo就可以直接进入演示
4 项目开发流程
创建项目
创建成功
编译并下载,就实现了项目开发的全过程。
代码简析
程序核心是appMain(),
在这个程序中实现了初始化,以及基本的蓝牙广播,连接等功能。这个程序使用nativeGecko编写,逻辑清晰。通过在线手册,可以知道API和各个程序的功能,更方便开发和使用。
- void appMain(gecko_configuration_t *pconfig)
- {
- #if DISABLE_SLEEP > 0
- pconfig->sleep.flags = 0;
- #endif
- /* Initialize debug prints. Note: debug prints are off by default. See DEBUG_LEVEL in app.h */
- initLog();
- /* Initialize stack */
- gecko_init(pconfig);
- while (1) {
- /* Event pointer for handling events */
- struct gecko_cmd_packet* evt;
- /* if there are no events pending then the next call to gecko_wait_event() may cause
- * device go to deep sleep. Make sure that debug prints are flushed before going to sleep */
- if (!gecko_event_pending()) {
- flushLog();
- }
- /* Check for stack event. This is a blocking event listener. If you want non-blocking please see UG136. */
- evt = gecko_wait_event();
- /* Handle events */
- switch (BGLIB_MSG_ID(evt->header)) {
- /* This boot event is generated when the system boots up after reset.
- * Do not call any stack commands before receiving the boot event.
- * Here the system is set to start advertising immediately after boot procedure. */
- case gecko_evt_system_boot_id:
- bootMessage(&(evt->data.evt_system_boot));
- printLog("boot event - starting advertising\r\n");
- /* Set advertising parameters. 100ms advertisement interval.
- * The first parameter is advertising set handle
- * The next two parameters are minimum and maximum advertising interval, both in
- * units of (milliseconds * 1.6).
- * The last two parameters are duration and maxevents left as default. */
- gecko_cmd_le_gap_set_advertise_timing(0, 160, 160, 0, 0);
- /* Start general advertising and enable connections. */
- gecko_cmd_le_gap_start_advertising(0, le_gap_general_discoverable, le_gap_connectable_scannable);
- break;
- case gecko_evt_le_connection_opened_id:
- printLog("connection opened\r\n");
- break;
- case gecko_evt_le_connection_closed_id:
- printLog("connection closed, reason: 0x%2.2x\r\n", evt->data.evt_le_connection_closed.reason);
- /* Check if need to boot to OTA DFU mode */
- if (boot_to_dfu) {
- /* Enter to OTA DFU mode */
- gecko_cmd_system_reset(2);
- } else {
- /* Restart advertising after client has disconnected */
- gecko_cmd_le_gap_start_advertising(0, le_gap_general_discoverable, le_gap_connectable_scannable);
- }
- break;
- /* Events related to OTA upgrading
- ----------------------------------------------------------------------------- */
- /* Check if the user-type OTA Control Characteristic was written.
- * If ota_control was written, boot the device into Device Firmware Upgrade (DFU) mode. */
- case gecko_evt_gatt_server_user_write_request_id:
- if (evt->data.evt_gatt_server_user_write_request.characteristic == gattdb_ota_control) {
- /* Set flag to enter to OTA mode */
- boot_to_dfu = 1;
- /* Send response to Write Request */
- gecko_cmd_gatt_server_send_user_write_response(
- evt->data.evt_gatt_server_user_write_request.connection,
- gattdb_ota_control,
- bg_err_success);
- /* Close connection to enter to DFU OTA mode */
- gecko_cmd_le_connection_close(evt->data.evt_gatt_server_user_write_request.connection);
- }
- break;
- /* Add additional event handlers as your application requires */
- default:
- break;
- }
- }
- }
复制代码
|
-
|