Search code examples
bluetoothbluetooth-lowenergygatt

Struggling to dispatch GAP_INIT command correctly (HCI commands with payloads)


I have an ST Micro Bluetooth 4.1 Bluenrg chip communicating connected to an xmega256a3u via SPI. I can communicate with the chip and send simple commands (e.g. HCI_READ_LOCAL_VERSION_INFORMATION (0x1001)).

My problem comes when I try to send an ACI command with a payload (e.g. GAP_INIT (0xFC8A)).

MOSI 0x0A  0x00  0x00  0x00  0x00  0x01  0x8A  0xFC  0x01  0x01
MISO 0x02  0x7F  0x00  0x00  0x00  0xFF  0xFF  0xFF  0xFF  0xFF

Then read:

MOSI 0x0B  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00  0x00
MISO 0x02  0x7F  0x00  0x0C  0x00  0x04  0x0E  0x0A  0x01  0x8A  0xFC  0x12  0x00  0x00  0x00  0x00  0x00  0x00

The status response 0x12 (12th byte in MISO) tells me that I have something wrong with my payload length, payload structure, or command packet. Any insight?


Solution

  • The BlueNRG-MS and newer firmware for the Bluenrg change the GAP_INIT command from 1 byte to 3 bytes:

    Role (1 byte):
    0x01:Peripheral 0x02: Broadcaster 0x04: Central 0x08: Observer

    Privacy (1 byte):
    0x00: Privacy is disabled 0x01: Privacy is enabled

    Length of Device Name (1 byte):
    Length of the device name characteristic