Sending 200 bytes, 20 bytes at a time in BLE ???

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I'm trying to send 200 bytes, by doing it 20 bytes at a time.  My questions is "How do I know it's OK to send the next 20 bytes?".

Here's what I'm doing.  Is this correct?

#define   ACCEL_DATA_SIZE      200

// Loaded with data in the Accelerometer interrupt

UINT8  accel_data[ACCEL_DATA_SIZE];

UINT8 i = 0;

while (i < ACCEL_DATA_SIZE) // Keep trying until all samples have been transmitted

{

      if (blecm_getAvailableTxBuffers() > 0) // Only send if TX buffers available

      {

           bleprofile_sendNotification(HDLC_LOOPD_SERVICE_ACCEL_DATA_VALUE, (accel_data + i), 20);

           i += 20;

     }

}

But for some reason, the device just drops the connection in the middle of the transmission.

Is using "blecm_getAvailableTxBuffers() " the right thing?  OR do I have to check or do something else?

Thanks!!

Gil

0 Likes
1 Solution
Anonymous
Not applicable

OK.  I've solved the problem.

Upon getting the data in an interrupt handler for a device we use (accelerometer), I was attempting to send the data via Bluetooth from within that same interrupt.  I assumed I would have time before the next interrupt happened, but that was not the case.

I changed the schem to just read the data from the FIFO in the accelerometer interrupt and put it in a buffer.  The actual sending via BLE is now being done in the fine timer handler, and that works.  I used part of the code from the "speed_test" example application.

View solution in original post

4 Replies
MichaelF_56
Moderator
Moderator
Moderator
250 sign-ins 25 comments on blog 10 comments on blog

Re: BCM20736S - change ATT_MTU

At the link above, there is long_characteristic sample application that has been modified to use characteristics of 208 bytes and and MTU size of 158 bytes.

Anonymous
Not applicable

Thank you. I will try to create one for 200 bytes.

But I should be able to send 20 bytes 10 times like I coded, right?  Is there any limits? What am I doing wrong?

Thanks,

Gil

0 Likes
Anonymous
Not applicable

OK.  I've solved the problem.

Upon getting the data in an interrupt handler for a device we use (accelerometer), I was attempting to send the data via Bluetooth from within that same interrupt.  I assumed I would have time before the next interrupt happened, but that was not the case.

I changed the schem to just read the data from the FIFO in the accelerometer interrupt and put it in a buffer.  The actual sending via BLE is now being done in the fine timer handler, and that works.  I used part of the code from the "speed_test" example application.

Excellent news.  Thanks for updating the thread with the solution as I imagine this will help others as well.