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.

"how to add a service" example for BLE keyfob

Other Parts Discussed in Thread: CC2540

Hello!

Im working on small little hardware project based on the CC2540 and I'm starting off with the Keyfob demo app and slowly modify it for my hardware and application. 

I was wondering if someone could post a brief step-by-step guide on how to add a service to provide additional data from my hardware. there are a lot of files in the PROFILES directory and I'm not exactly sure where to add what.

specifically i want to add a service which provides a signed 16bit int (s16) value.

i was thinking of reusing one of the acceleration values (x for example) but that seems to be 8 bit only but i need 16 bit.

thanks in advance,

-r 

  • I could try to do that but I'm not at work right now.

    Why don't you try to do a "ctrl+shift+F" on IAR and search the word "service"? If I do not remember wrong, it was quite easy to identify several info that could be interesting for you this way :)

  • Hi Rene,

    I'm gonna try to make this easy for you.

    I suggest that you take a look at the simpleGATTprofile (found at C:\Texas Instruments\BLE-CC2540-1.1a\Projects\ble\Profiles\SimpleProfile). You can copy, rename, modify and add to your keyfob project (Right-click on "PROFILES" in IAR and "Add files..."). After that you would have to add the new service by calling SimpleProfile_AddService( GATT_ALL_SERVICES ); (Or whatever you renamed the profile to) from the KeyFobApp_Init function.

    When it comes to modifying the profile, please have a look at the simpleBLEperipheral project to make sure that you understand. If you want to add peripheral hardware functionality just have a look at the accelerometer.c in the keyfob project.

    I hope I haven't confused you :) Go ahead and try, I'll be around if you get stuck.

    Br

  • Thanks so much, will try these suggestions. 

    One follow up. Are GATT attributes always 8 bit or can they be 13 or even 32 bit? the code i looked at so far seems to only use 8bit gatt attribute values. i have some data that is 16 and other that is 32 bit so I'm wondering how i add an attribute to a service that has that many bits.

    thanks,

    -r

  • Interesting question, since the processor is a 8051 type, I guess 8 bit is the way to go here. If you want to store a 16 bit value in an attribute you could separate it, like this;

    static uint8 characteristicValue[2] = { 0, 0};

    characteristicValue[ 0 ] = HI_UINT16( your16BitData);

    characteristicValue[ 1 ] = LO_UINT16( your16BitData);

    I'm not into bits and bytes so maybe my suggestions is not the most optimized one, but it works.

    Br

  • Hi Rene and TI team, 

    Did you were able to solve the issue of greater size values. I am adding a gyroscope to the system that has 16 bits and I am facing some problems...

    Please, let me know if I am right in this. 

    From the structure of attAttribute_t if I want to store a value of 16 bits I will need to store it divided in 8 bit pieces? 

    /* GATT Attribute format.
    */
    typedef struct attAttribute_t
    {
    gattAttrType_t type; //!< Attribute type (2 or 16 octet UUIDs)
    uint8 permissions; //!< Attribute permissions
    uint16 handle; //!< Attribute handle - assigned internally by attribute server
    uint8* const pValue; //!< Attribute value - encoding of the octet array is defined in
    //!< the applicable profile. The maximum length of an attribute
    //!< value shall be 512 octets.
    } gattAttribute_t;
    
    
    thanks in advance
  • pixbroker,

    Data transfer over BLE link occurs in single Bytes anyway, so Joakim's suggestion to break it down into two-8-Bit Bytes would be your best bet.

    You can string them together again at the other end using;
    uint16 your16BitData = BUILD_UINT16( characteristicValue[ 0 ], characteristicValue[ 1 ]);
    which is the reverse of the suggested method to break it down.

    JB