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.

CC2540 set variable using HCI commands

Other Parts Discussed in Thread: CC2540

Hello,

 

I have installed the KeyFobDemo and am using the JavaSimplePeripheral program to send HCI commands. I have been able to modify the JavaSimplePeripheral and the KeyFobDemo code to be able to turn on and off the accelerometer data. In keyfobdemo.c the ACCEL_READ_PERIOD is defined as 50 ms. I would like to modify the JavaSimplePeripheral program to be able to set this period remotely.

 

The way I currently understand the HCI commands is that essentially I am sending a write request which asks to write a value to a handle which is associated to a specific UUID. This makes sense for enabling the accelerometer and enabling notifications since both have a UUID associated with them (0xFFA1 to enable and 0xFFA3 for x direction) and corresponding handles associated with enabling the accelerometers and notifications. I just can't figure out how to write a value using HCI commands which will get assigned to a variable which can be used elsewhere in the program. Any advice would be greatly appreciated.

 

Thank you,

Ryan

  • You will have to modify the firmware for that (keyfob firmware) - only from the java code you can't ...

    Adding a new variable with new UUID and switching that read period from constant to that variable would solve your problem - there are plenty of examples in the SDK for that - the accelenabler is one of them ... So install the IAR compiler and start coding :)

    regards,

    B.

  • Thanks for your quick reply! I have the IAR compiler (the trial version for now anyway) and have already modified the firmware somewhat. I changed the the accelRead function so that it will send the accelerometer data at every read period instead of only if the threshold has been satisfied. I have been slowing figuring it out but still not sure how everything works together with all of the different layers.(hal, gatt, gap, hci, and the operating system OSAL)

    So I can just define a new profile parameter and profile UUID in the accelerometer header file, then do a read request to get the handle of the attribute, then write the value I want to that handle and set it equal to my read period?

    I will try to find some more examples in the SDK. Thanks for your response :)

     

    Ryan

     

     

     

  • Yes, it's just a new variable - there are plenty of examples - you can also check the SimpleBLEPeripheral project which has r,w and r/w variables but have no callbacks if I remember well. Anywhere you see RegisterAppCBs function in the profile: that call registers some callbacks from main application for later callback (callback can be done on individual UUID change as well in the WriteAttrCB functions).

    What I would do is:

    - instead of #define timer I would use a timer variable initialized to 50msec (1 or 2 byte value)

    - add a new UUID and vairable to the accelerometer profile (accelerometer.h)

    - add a new callback to this struct in the accelerometer.h

    typedef struct

    {

      accelEnabler_t        pfnAccelEnabler;  // Called when Enabler attribute changes

    } accelCBs_t;

    - add that callback into keyfobdemo.c like the enabler is but maybe with one parameter (the time period)

    static void accelEnablerChangeCB( void )

    - call my new callback from accel_WriteAttrCB whenever my UUID is changed by somebody

    - change the timer variable from this callback with some error checks 

    The AccelEnabler shows kinda clearly those steps.

     

    I know for the first the connections between the gatt/att/gap/hal/osal is not easy to understand but working a few weeks with it will clear things up - worth looking the documentation from the SDK since has a clear drawing about all those layers - check out the TI_BLE_Software_Developer's_Guide.pdf and the rest of it :)

    B.

  • Hi, 

    i am newer to CC2540 mini developement kit..i have tried keyfob example. it is working fine.

    i don't know how to use timer using to set led blinking in CC2540..i have tried with Keyfob example but it is not working.

    can u tell me how to use timer in CC2540..?..

     

    thanks ..

     

  • To use set an OSAL event based on a timer, you can use osal_start_timerEx. The SimpleBLEPeripheral application has an example of this for the periodic event.

    If you want to use the hardware timers, check out sections 9 and 10 of the CC2540 User Guide (http://www.ti.com/litv/pdf/swru191b) for more information on HW Timers 1, 3, and 4. Note that Timer 2 cannot be used by the application, as the link layer of the BLE stack uses this.