This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2541: Add own function to examples from BLE stack (simple UART exchange)

Part Number: CC2541
Other Parts Discussed in Thread: CC2540

Hello,

I have couple modules with CC2541:

I have uploaded through debugger SimpleBLEPeripheral example from BLE stack (BLE-CC254x-1.4.2.2).

Now I'm able to see it via phone with android and in SmartRF Studio.

So, I suppose everything with settings/wiring is fine.

How can I add my own function to this project?

For example, sending some bytes throuhg UART.

I have connected USB-UART dongle  (  ) to P03 and P02 pins and want to see some packets throught terminal at first. 

(In further I would like also to see how to use I2C with this module, but let's postpone it for later)

As I understand (correct me please if I'm wrong) in SimpleBLEPeripheral_Main.c I have nothing to do, 

since function

 /* Start OSAL */
  osal_start_system();

calls 

osal_run_system();

in forever loop. And in this function only pocessing tasks and events. So, I need to work with simpleBLEPeripheral.c I suppose?

As I understand, I need to create my own task?

I checked another examples and figured out that I need to use 

osal_start_timerEx()

to set time with interrupt.

But how can I add my own function in all system?

I tried add this 

void custom_func_test()
{
  uint8 testbuf [5]={7,6,5,4,3};
  
  osal_start_timerEx( 1, 2, 100);
  SimpleBLEPeripheral_ProcessEvent(11, 1);
  HalUARTWrite(1, testbuf, 5);
}

but I have no clue from where I need to call it. (tried to put in MAIN function before OSALsystem run in simpleBLEperipheral_main.c , but debugger dint not even get there)

  • Hi AIU2017,

    Why not take a look at our example projects for guidance on this? (Or look at the step by step guides?)

    processors.wiki.ti.com/.../Category:BluetoothLE

    And look under CC254x Bluetooth low energy

    Regards,
    Rebel
  • Hi Rebel,

    Unfortunatelly, I have issue with SimpleBLEPeripheral_SerialInterface example (described in this topic https://e2e.ti.com/support/wireless_connectivity/bluetooth_low_energy/f/538/t/598254).

    I'm studying SWRU271 right now (CC2540 and CC2541 Bluetooth® low energy Software Developer’s Reference Guide) but this manual is pretty complex - still dont understand where I can insert my own functions and how can I insert it into forever loop from osal_run_system().

    I have checked OSAL_SimpleBLEPeripheral.csimpleBLEPeripheral.c files from SimpleBLEPeripheral_SerialInterface and from original SimpleBLEPeripheral, there is only few differences:

    simpleBLEPeripheral.c:

    #if defined (SERIAL_INTERFACE)
    #include "serialInterface.h"
    #endif
    
    //call in order to allow more CPU time for driver
    HCI_EXT_HaltDuringRfCmd(HCI_EXT_HALT_DURING_RF_DISABLE);

    (+ some TRUE to FALSE in advertisement settings)

    simpleBLEPeripheral.h:

    Only one string added

    uint8 Application_StartAdvertise(uint16 duration, uint16 interval);

    OSAL_SimpleBLEPeripheral.c:

     

    #if defined (SERIAL_INTERFACE)
    #include "serialInterface.h"
    #endif
    
    
      GATTServApp_ProcessEvent,                                         // task 10
    #if defined (SERIAL_INTERFACE)
      SerialInterface_ProcessEvent,
    #endif 
    
      GATTServApp_Init( taskID++ );
    #if defined (SERIAL_INTERFACE)
      SerialInterface_Init(taskID++ );
    #endif