Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
40
7 . 4 . 4
B l u e t o o t h F u n c t i o n s
Callback functions for specific Bluetooth BR/EDR events, connection up, connection down, and received data are
registered during the SPP library initialization inside the
application_init()
function (see
). The
wiced_bt_spp_reg_t
structure with appropriate callbacks and
wiced_bt_spp_startup()
are shown in
Code 29.
spp.c
: Structure with Details of Callbacks Needed for SPP Application and Function to Initialize SPP Library
wiced_bt_spp_reg_t
spp_reg =
{
SPP_RFCOMM_SCN,
/* RFCOMM service channel number for SPP connection */
MAX_TX_BUFFER,
/* RFCOMM MTU for SPP connection */
spp_connection_up_callback,
/* SPP connection established */
NULL,
/* SPP connection establishment failed, not used because this app
never initiates connection */
NULL,
/* SPP service not found, not used because this app never initiates
connection */
spp_connection_down_callback,
/* SPP connection disconnected */
spp_rx_data_callback,
/* Data packet received */
};
// Initialize SPP library
wiced_bt_spp_startup(&spp_reg);
The Inquiry response data for Bluetooth BR/EDR can be set in the
app_write_eir function
. In this example, the
device name and UUID of the SPP service are published as part of the inquiry response.
Code 30.
App_write_eir
: Inquiry Response Data
void
app_write_eir
(
void
)
{
uint8_t
*pBuf;
uint8_t
*p;
uint8_t
length;
uint16_t
eir_length;
pBuf = (
uint8_t
*)wiced_bt_get_buffer(WICED_EIR_BUF_MAX_SIZE);
WICED_BT_TRACE(
"hci_control_write_eir %x\n"
, pBuf);
if
(!pBuf)
{
WICED_BT_TRACE(
"app_write_eir %x\n"
, pBuf);
return
;
}
p = pBuf;
length = strlen((
char
*)wiced_bt_cfg_settings.
device_name
);
*p++ = 1;
*p++ = BT_EIR_COMPLETE_LOCAL_NAME_TYPE;
// EIR type full name
memcpy(p, wiced_bt_cfg_settings.
device_name
, length);
p += length;
*p++ = 2 + 1;
// Length of 16 bit services
*p++ = BT_EIR_COMPLETE_16BITS_UUID_TYPE;
// 0x03 EIR type full list of 16 bit service UUIDs
*p++ = UUID_SERVCLASS_SERIAL_PORT & 0xff;
*p++ = (UUID_SERVCLASS_SERIAL_PORT >> 8) & 0xff;
*p++ = 0;
// end of EIR Data is 0
eir_length = (
uint16_t
) (p - pBuf);
// print EIR data
wiced_bt_trace_array(
"EIR :"
, pBuf, MIN(p-pBuf, 100));
wiced_bt_dev_write_eir(pBuf, eir_length);
return
;
}
The next function to look for are connection up and connection down callback functions triggered by the Bluetooth stack
on successful connection or disconnection from the remote Bluetooth BR/EDR master. The Bluetooth connection
handle is saved by the connection up callback;
it is reset to ‘0’ by the connection down callback as shown in