Sie sind auf Seite 1von 4

MasterSlaveSwitch 1

MasterSlaveSwitch
Bluetooth Low Energy Wiki Main Page [1]

MASTER SLAVE SWITCH


This example demonstrates the ability of the CC254x with 1.4.1 stack to switch roles between master and slave. The
example is based off of the SimpleBlePeripheral project and adds in components from SimpleBleCentral. The roles
can be switched multiple times. Projects for both the CC2540 and CC2541 Keyfob are included.

Requirements
2 CC2540/1 KeyFob's
Texas Instruments Stack 1.4.1 (www.ti.com/blestack)
CC Debugger

Project Files
The patch is found here:
Apply this patch to the $INSTALL$ directory of the stack: C:\Texas Instruments\BLE-CC254x-1.4.1.43908 by
default. Select yes to replace all files.
The project will then be located at $INSTALL$\Projects\ble\SimpleBLESwitch

Operation
1. Flash each keyfob with the SimpleBLESwitch project.
2. Upon power on, the keyFobs will both be advertising. Press the left button on keyFob#1 to change its role to
master. This will also cause it to connect to keyfob#2
3. It is possible to connect to multiple peripherals. Since the user interface on the keyfob is limited, the addresses
which the central will attempt to connect to are hardcoded in the project in SimpleBLESwitch_Init() in
simpleBLESwitch.c:

// CENTRAL APP STARTUP


//devices the central will try and connect to
uint8 addr1[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0x02};
uint8 addr2[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0x03};
uint8 addr3[6] ={0xFF,0xFF,0xFF,0xFF,0xFF,0x04};

4. Press the left button to switch roles as desired.


Red Led blink indicates advertising mode
Green led indicates connected mode or scanning
Slave will blink once when connected
Master will blink 1 + number of connected devices (max 3)
MasterSlaveSwitch 2

File Modification
The only profile which requires modification is peripheral.c., to remove a check for gapRole_state in
GAPRole_StartDevice. This is included in the patch here.
In OSAL_SimpleBLESwitch.c the tasksArr must be update to include the central task
(GAPCentralRole_ProcessEvent)

const pTaskEventHandlerFn tasksArr[] =


{
LL_ProcessEvent, //
task 0
Hal_ProcessEvent, //
task 1
HCI_ProcessEvent, //
task 2
#if defined ( OSAL_CBTIMER_NUM_TASKS )
OSAL_CBTIMER_PROCESS_EVENT( osal_CbTimerProcessEvent ), //
task 3
#endif
L2CAP_ProcessEvent, //
task 4
GAP_ProcessEvent, //
task 5
SM_ProcessEvent, //
task 6
GATT_ProcessEvent, //
task 7
GAPRole_ProcessEvent, //
task 8
GAPCentralRole_ProcessEvent, //
task 9
GAPBondMgr_ProcessEvent, //
task 10
GATTServApp_ProcessEvent, //
task 11
SimpleBLESwitch_ProcessEvent // task
12
};

In OSAL_SimpleBLESwitch.c the central task is initialized/registered with OSAL

/* Profiles */
GAPRole_Init( taskID++ );
GAPCentralRole_Init( taskID++ ); //Add Central task here
GAPBondMgr_Init( taskID++ );

In simpleBLESwitch.c within the simpleBLESwitch_Handlekeys() function the following line is changed:

//cancel current link request


GAPCentralRole_TerminateLink( 0xFFFF );
MasterSlaveSwitch 3

In simpleBLESwitch.c in the simpleBLESwitch_Handlekeys() function the following call to the osal timer is
changed to use the proper taskID:

osal_start_timerEx( simpleBLESwitch_TaskID, SBP_START_DEVICE_EVT, 500


);

References
[1] http:/ / processors. wiki. ti. com/ index. php/ Category:BluetoothLE
Article Sources and Contributors 4

Article Sources and Contributors


MasterSlaveSwitch Source: http://processors.wiki.ti.com/index.php?oldid=204434 Contributors: DanRinkes, JLindh, Lhend, Slyons22, T Camise

Das könnte Ihnen auch gefallen