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 Read Accelerometer Values

I have been using BTool to turn on and off notifications for the accelerometer and I can see when it is adjusted. I began to use KeyFobDemo and HostTestApp and would like to make slight changes so that I no longer have to use BTool to change the values and instead would like to flash program the devices. My main goal is to track the values of the accelerometer.

I understand that I need to write a value of 0x01 to the proper handles and in order to turn on notifications:

static void accelEnable(void )
{
attWriteReq_t reqest;
request.len=2;
request.value[0] = ENABLED;
request.sig=0;
request.cmd=0;

request.handle = ENABLE_ACCEL_X;
GATT_WriteCharValue( CONNECTION_HANDLE, &request, simpleBLETaskId );

request.handle = ENABLE_ACCEL_Y;
GATT_WriteCharValue( CONNECTION_HANDLE, &request, simpleBLETaskId );

request.handle = ENABLE_ACCEL_Z;
GATT_WriteCharValue( CONNECTION_HANDLE, &request, simpleBLETaskId );

}

I believe the above function should do that. 

However, I'm not sure where to apply this function. I assume I should flash this to the central device (USB Dongle). If this is the case, how would I then get the notifications from the accelerometer? I can't use GATT_ReadCharValue.

Any help would be much appreciated

  • By the way, ENABLED, ENABLE_ACCEL_X (and y and z) and CONNECTION_HANDLE have all been typedef'd to the proper hex value
  • Sorry I don't fully understand what you're trying to do. Do you just want to modify your project so that the accelerometer is enabled by default? Are you using the sensor tag project?
  • Hi Tim,

    Sorry I wasn't clearer. Yeah, I've been flashing (and editing) the HostTestRelease to the USB dongle and KeyFobDemo to KeyFob. Ultimately, I'd like to flash program something so that the Dongle can read the accelerometer values.

    What I've been doing is using BTool to manually update specific handles. For example, writing a 0x01 to handle 0x0034 enables the accelerometer. However, I'm trying to figure out a way to flash program that in so that it works automatically.

    Also, I'm trying to append the accelerometer info at the end of the advertising packets. I can statically update the advertData array but when I try to dynamically update it using:

    ********************************************************
    //turn off advertising
    uint8 advertEnabled = FALSE;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advertEnabled );

    // Update the advertising data
    advertData[13] = 0xAA;

    bStatus_t stat;
    stat = GAP_UpdateAdvertisingData( 0, TRUE, sizeof( advertData ), advertData);

    //turn on advertising
    advertEnabled = TRUE;
    GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &advertEnabled );

    ********************************************************

    it no longer works. Any ideas?

    Thanks so much!
  • You can set the accelerometer profile's attribute values in the embedded project using Accel_SetParameter().

    The advertising thing you're mentioning is actually a bug in the 1.4.0 stack. Luckily, there is a new stack (1.4.1) being released. It should be available here by end-of-day tomorrow: www.ti.com/blestack
  • Hey Tim,

    Thanks for the response. I had tried the Accel_SetParameter() function but it appeared that the switch statement only had options to set the value of the x,y and z coordinates and not the toggle that creates notifications. Is that not the case?

    Thanks for the info about the dynamic advertising. Isn't it possible to add the battery level to the advertising? If so, why is it different for the accelerometer values?

    Thanks so much!
  • According to the BT spec, it is necessary for the connected device to enable notifications (over-the-air). You can't just do this on the embedded code.

    Have you been able to add the battery level dynamically? The bug prevents dynamic advertising modifications: you need to stop and then restart advertising to get around it. The new stack with the bug fix is now released: www.ti.com/blestack
  • Thanks so much!

    I actually hadn't been able to add the battery level dynamically but I had seen documentation about it so I figured it was possible. Thanks for your help!