Support us and view this ad

可选:点击以支持我们的网站

免费文章

1. Introduction: Beyond Basic Beacons – The Need for Extended and Periodic Advertising Traditional BLE advertisement beacons, such as iBeacon or Eddystone, broadcast a fixed 31-byte payload in a single advertisement event. This suffices for simple presence detection but falls short for high-throughput data dissemination, sensor telemetry, or encrypted payloads. The Bluetooth 5.0 specification introduced two key enhancements: Extended Advertising (LE 1M, 2M, or Coded PHY) and Periodic Advertising. Extended advertising allows payloads up to 255 bytes per advertisement event and supports multiple PHY modes for range or speed. Periodic advertising establishes a synchronized isochronous channel where the scanner can synchronize with the advertiser’s timing, enabling deterministic, low-latency data streams without constant re-scanning. The nRF52840 SoC from Nordic Semiconductor is a prime candidate for implementing such advanced beacon systems. It integrates a Bluetooth 5.2-compliant radio, a 64 MHz ARM Cortex-M4F, and 1 MB of Flash plus 256 kB of RAM. This article provides a technical deep-dive into constructing a high-performance BLE advertisement beacon that leverages both extended and periodic advertising, focusing on the nRF52840’s SoftDevice controller (S140 v7.x) and the nRF5 SDK. We will cover packet formatting, timing constraints, register-level configuration via the SoftDevice API, and a full implementation walkthrough with code snippets. Finally, we present real-world power and latency measurements. 2. Core Technical Principles: Packet Format, Timing, and Synchronization Extended Advertising Packet Format: Unlike legacy advertising, extended advertising uses a primary channel (37/38/39) PDU containing an Auxiliary Pointer. This pointer references a secondary channel (0-36) where the actual payload is transmitted. The primary PDU is a legacy-compatible PDU type (ADV_EXT_IND) that carries an AuxPtr field: Offset (10 bits, in 125 µs units relative to the primary event end), PHY (2 bits: 1M, 2M, Coded), and Channel Index (5 bits). The secondary PDU (AUX_ADV_IND) carries the full advertising data (up to 255 bytes) and can also include a SyncInfo field for periodic advertising. Periodic Advertising Timing: Periodic advertising uses a fixed interval Periodic_Advertising_Interval (range: 7.5 ms to 81.91875 s, in steps of 1.25 ms). The advertiser transmits an AUX_SYNC_IND PDU on a secondary channel. The scanner can synchronize by receiving a SyncInfo field from an extended advertisement. Once synchronized, the scanner wakes up at the exact interval without scanning all channels. The timing is governed by the formula: T_periodic = Periodic_Advertising_Interval × 1.25 ms Event_Count = (current_time - anchor_point) / T_periodic Next_event_time = anchor_point + (Event_Count + 1) × T_periodic The anchor point is the timestamp of the first AUX_SYNC_IND event. The scanner maintains a Sync_Offset to compensate for clock drift. State Machine: The advertiser transitions between idle, advertising, and periodic advertising states. The SoftDevice manages radio scheduling; the application only sets parameters via API calls. The key states are: Idle: No radio activity. Extended Advertising: Primary channel events (ADV_EXT_IND) plus scheduled secondary events (AUX_ADV_IND). Periodic Advertising: AUX_SYNC_IND events at fixed intervals. 3. Implementation Walkthrough: nRF52840 with SoftDevice S140 We use the nRF5 SDK v17.1.0 with SoftDevice S140 v7.2.0. The application configures the radio via the ble_gap.h API. Below is a step-by-step implementation. Step 1: Initialize SoftDevice and GAP #include "ble.h" #include "ble_gap.h" #include "nrf_sdh.h" #include "nrf_sdh_ble.h" #define APP_BLE_CONN_CFG_TAG 1 static void ble_stack_init(void) { ret_code_t err_code; err_code = nrf_sdh_enable_request(); APP_ERROR_CHECK(err_code); uint32_t ram_start = 0; err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start); APP_ERROR_CHECK(err_code); err_code = nrf_sdh_ble_enable(&ram_start); APP_ERROR_CHECK(err_code); } Step 2: Configure Extended Advertising Parameters Extended advertising requires the ble_gap_adv_params_t structure with .type = BLE_GAP_ADV_TYPE_EXTENDED. We set the primary PHY to 1M and secondary to 2M for higher throughput. static void advertising_init(void) { ret_code_t err_code; ble_gap_adv_params_t adv_params; memset(&adv_params, 0, sizeof(adv_params)); adv_params.properties.type = BLE_GAP_ADV_TYPE_EXTENDED; adv_params.properties.include_tx_power = true; adv_params.p_peer_addr = NULL; // Undirected adv_params.interval = 100; // 100 * 0.625 ms = 62.5 ms adv_params.duration = BLE_GAP_ADV_TIMEOUT_NO_TIMEOUT; adv_params.primary_phy = BLE_GAP_PHY_1MBPS; adv_params....

继续阅读完整内容

支持我们的网站,请点击查看下方广告

正在加载广告...

Login