Support us and view this ad

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

免费文章

Introduction: The Challenge of Voice Data Over BLE in a Custom Mouse The nRF5340, with its dual-core Arm Cortex-M33 architecture and dedicated Bluetooth Low Energy (BLE) radio, is a powerful platform for custom wireless peripherals. However, transmitting voice data—a continuous, isochronous stream of high-fidelity audio—over a protocol designed primarily for low-power, intermittent control packets presents a unique engineering challenge. In a custom wireless mouse, the user expects both low-latency cursor movement and real-time voice capture (e.g., for voice commands or dictation). The inherent trade-offs between throughput, latency, and power consumption become critical. This article provides a technical deep-dive into optimizing BLE throughput for voice data on the nRF5340, focusing on packet engineering, connection parameter tuning, and leveraging the Bluetooth 5.2 LE Isochronous Channels (LE Audio) where applicable, while maintaining the responsiveness of a standard HID mouse. Core Technical Principle: Packetization and Connection Interval Engineering The fundamental bottleneck in BLE voice transmission is the limited payload per connection event and the fixed connection interval. A standard BLE connection event can carry a maximum of 251 bytes of application data (using the Data Length Extension, DLE) in a single packet. For voice, we typically use 16-bit linear PCM at 16 kHz, which yields a raw data rate of 256 kbps. Without optimization, this would require approximately 128 connection events per second with a 251-byte payload, which is feasible but consumes excessive power and channel time. The optimization strategy involves three key elements: (1) minimizing overhead through efficient packet framing, (2) using a custom L2CAP CoC (Connection-oriented Channel) for reliable, sequenced data, and (3) leveraging the nRF5340’s dedicated PPI (Programmable Peripheral Interconnect) and EasyDMA to reduce CPU intervention. The packet format we designed is a compact, two-layer structure. The outer layer is a standard BLE L2CAP frame with a 4-byte header (Length + CID). The inner layer is our custom voice payload header: // Voice Packet Format (L2CAP Payload) // Byte 0: Sequence Number (0-255) – for loss detection // Byte 1: Flags (bit0: voice active, bit1: last packet of frame) // Bytes 2-3: Timestamp (16-bit, 1ms resolution) // Bytes 4-251: Audio Data (248 bytes of 16-bit PCM samples, 124 samples) This packet carries 124 samples (2.48 ms of audio at 16 kHz) per connection event. With a connection interval of 7.5 ms (the minimum allowed for central roles in BLE 5.2), we can transmit one packet per event, achieving a theoretical throughput of 248 bytes / 0.0075 s = 33.1 kB/s, which is close to the required 32 kB/s for 16-bit/16kHz mono audio. The key is to align the audio sampling clock with the BLE connection event timer to avoid buffer underruns or overruns. Timing diagram description: The nRF5340’s 32 kHz RTC (Real-Time Counter) drives a timer that triggers an EasyDMA transfer from the I2S interface (connected to a digital microphone) to a double-buffer in RAM. The audio ISR (Interrupt Service Routine) fills a 248-byte segment. Simultaneously, the BLE stack’s connection event callback (on the application core) checks for a full buffer and schedules a write to the L2CAP CoC channel. The connection event start is synchronized to the RTC tick, ensuring that the audio buffer is always ready exactly at the event start, minimizing latency jitter. Implementation Walkthrough: Code and State Machine for Isochronous Voice The nRF5340’s dual-core architecture allows us to isolate the voice processing to the network core (core 0) and the HID mouse logic to the application core (core 1). The voice path uses a custom state machine with three states: IDLE, STREAMING, and RECOVERY. The transition to STREAMING occurs when the user presses a dedicated voice button. The network core then configures the I2S, starts the audio timer, and establishes an L2CAP CoC with the host (dongle). The following code snippet demonstrates the critical function that prepares and queues a voice packet for the BLE stack, using the nRF5 SDK’s SoftDevice API (for BLE 5....

继续阅读完整内容

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

正在加载广告...