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.

Unable to receive notifications at correct frequency

Other Parts Discussed in Thread: CC2540

I'm trying to get my CC2540 to send out notifications at 50Hz.

What I've done is to make the following changes in simpleBLEPeripheral.c

#define SBP_PERIODIC_EVT_PERIOD                                 20 
#define DEFAULT_ENABLE_UPDATE_REQUEST              TRUE
#define DEFAULT_DESIRED_MIN_CONN_INTERVAL       8
#define DEFAULT_DESIRED_MAX_CONN_INTERVAL      8
#define DEFAULT_DESIRED_CONN_TIMEOUT                  100

I'm looking at the time in btool and am only receiving notifications every 70-100ms.

First notification received at : 10:19:58.146
2nd notification received at:  10:19:58.232
3rd notification received at:   10:19:58.318

I've looked through about 500 packets, at different times of the day and most of the data appear to follow the same trend, so it can't be a random noise spike. Also, the CC2540 and the USB dongle are only about 5 cm apart.

As you can see, notifications are received at nowhere near the expected frequency of 50Hz (20ms period).

Would appreciate some help!

  • An update on the status.

    I've tried restoring everything to the default  simpleBLEPeripheral.c and only modified SBP_PERIODIC_EVT_PERIOD to 200, 500, 1000. Everything works as expected. What I mean is that I'm getting a notification every 200, 500 and 1000 ms respectively.

    So, I decided to try increasing the frequency. I've simply increased the frequency of the periodic event to 20Hz (by setting SBP_PERIODIC_EVT_PERIOD to 50).This means that 2 notifications will be sent in every connection interval, and this is fine.

    However, according to the timestamps in btool (and my own btool like java program), I'm only getting 13/14 notifications per second instead of the expected 20. Surely, I can't have exceeded the amount of CPU time? I mean, what is happening in the periodic event is simply read 1 byte from SIMPLEPROFILE_CHAR3 and then writing that same byte to SIMPLEPROFILE_CHAR4, causing a notification to be sent.

    I've disabled power savings, so I don't think this is a factor. Also, I've tried the same experiment with connection interval as 50 ms and am getting the same results.

    I would really appreciate some help on this!

  • Hi guys,

    I would really appreciate some help on this issue.

    Perhaps a simpler question would help.

    How do I change simpleBLEPeripheral such that SIMPLEPROFILE_CHAR4 is sending its notifications at 20 times per second? Currently it is only sending 10 notifications per second.

  • Try using the osal_start_reload_timer() API just once in the SBP_START_DEVICE_EVT and you don't need to touch it in the SBP_PERIODIC_EVT.

     

  • Sorry, but that didn't help. I am still only receiving 15 notifications per second instead of the expected 20.

    In fact, I've tried decreasing the timer interval to only 20ms (for a 50Hz rate) and am also getting 15 notifications per second.

    Is there something wrong with the BLE stack?

      
      
      

    These are the changes that I made to simple BLE to make use of the osal_start_reload_timer() API. Please advice if I am wrong.

    if ( events & SBP_START_DEVICE_EVT )
    {
    // Start the Device
    VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs );

    // Start Bond Manager

    VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs );

    // Set timer for first periodic event
    //osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    osal_start_reload_timer(simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, 50);

    return ( events ^ SBP_START_DEVICE_EVT );
    }

    if ( events & SBP_PERIODIC_EVT )
    {
    // Restart timer
    /*if ( SBP_PERIODIC_EVT_PERIOD )
    {
    osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD );
    }*/

    // Perform periodic application task
    performPeriodicTask();

    return (events ^ SBP_PERIODIC_EVT);
    }

  • If we break down your problem into its pieces, there are 3 potential places where things are going wrong:

    1. your periodic update task isn't running at the expected rate
    2. the BLE connection interval isn't what you expect
    3. the unsychronized interaction between the periodic task and the BLE connection interval is giving you trouble

    The first seems pretty straight forward, and unlikely to be the problem, but you can easily verify this by storing the number of times performPeriodicTask() is called and monitoring its value after 10 seconds or so. That would be quick and easy to do through the IAR debugger.

    The second is where I would look, especially because in your first post the notifications were 86 msec apart. This makes me think that your connection interval was actually 86 msec no matter what you specified in the configuration. Ideally I'd say use the packet sniffer to figure out what your actual connection interval is. If you can't do that then at least use GAPRole_GetParameter() to read GAPROLE_CONN_INTERVAL after connecting and see what the connection interval is set to.

    Finally, given an unfortunate combination of task period and connection interval, you could end up with fewer notifications than expected. This should only happen if your periodic task interval is about equal or longer than the connection interval. In this case you might get two connection attempts between periodic updates.

    At least in the typical case you aren't going to get any more than one notification on this characteristic per connection interval (I don't know the stack internals, so some very specific sequence of events might allow two to get out). This limits your max notification rate to 1/connection interval. This certainly would make me want to check the connection interval first.

  • Unfortunately, it is still not working. This is extremely frustrating because it is supposed to be very simple!

      

    1. Periodic update task isn't running at the expected rate

    I've checked this by incrementing a variable in the periodic event and checking the value after 30s. Bluetooth notifications are enabled after the first few seconds (need time to press the buttons on btool). I am getting the correct result for 10Hz, 20Hz and even 100Hz.

      

    2. BLE connection interval isn't what I expect

    I don't have an additional board right now to act as a packet sniffer (I can get it next week). So, I've used the GAPRole_GetParameter() to read GAPROLE_CONN_INTERVAL and the result is exactly what I had set it to be.

      

    3. Unsychronized interaction between the periodic task and the BLE connection interval

    I'm setting my connection interval to 6, which is the minimum. So, hopefully, this isn't an issue.

      

    4. Aren't going to get any more than one notification on this characteristic per connection interval

    Actually, I've asked in this thread and was told that 3 max-size notifications can be sent in each connection interval. 

      

    Just to recap, the current situation is as follows:

    I can only get around 15 notifications per second despite setting the periodic event to 20Hz or even 100Hz. Connection interval is set at 6, and I am using the simpleBLEPeripheral sample program that is given. 

  • Is your problem that you only see around 15 notifications per second reported by BTool, even though you think you are sending them faster? The problem may be that your situation is limited by the dongle and BTool itself. There is a virtual COM port link between the dongle and BTool, and you may just be seeing the effect of bandwidth limitation on this link, or the speed of BTool itself. I think this topic has come up before and I seem to remember this being a limiting factor.
  • Here is an update on the situation.

    I've updated everything to the 1.3 stack and am getting better results.

    I can achieve frequencies of 30 Hz reliably.

    40Hz is unreliable, it works for the first few seconds and then will start to have a lower and lower rate in which notifications are being received. If I power down the transmitting device, btool would continue to show many notifications. 

    I suppose Matthew Kendall is right and that this is a limit of the dongle. I am fairly certain that this is not a problem with btool because I have my own program to parse the received notifications and am getting similar results.

    Can I check whether the HostTestApp project that is given is actually the firmware that is loaded onto the usb dongle? I might take a look at it when I have time to see if there is anything that could be done to boost the notification rate.