Go Down

Topic: Curie TinyTile: Can't update BLE characteristics <25ms? (Read 286 times) previous topic - next topic

timontunes

Oct 27, 2018, 08:00 pm Last Edit: Oct 28, 2018, 09:09 am by timontunes Reason: updated cross links
Board Name: Intel Curie's Tiny Tile

Trying to update two characteristic every 10ms.

The nrf Connect app which is used to receive data gets hanged after few receiving few data packets.

I have also asked the question in GitHub. Here's the link,



Can anyone please find the mistake/bug in the below code :smiley-confuse:
Code: [Select]
#include <CurieBLE.h>
#include <CurieIMU.h>

#define MAX_IMU_RECORD 1

typedef struct {
    int index;
    unsigned int slot[3];
} imuFrameType;

// Buffer to hold IMU data
imuFrameType imuBuf[MAX_IMU_RECORD];
unsigned seqNum = 0;
BLEService bleImuService("A7580001-153E-D4F6-F26D-43D8D98EEB13"); // Tx IMU data Characteristic
BLECharacteristic bleImuChar("F7580003-153E-D4F6-F26D-43D8D98EEB13", // standard 128-bit characteristic UUID
                             BLERead | BLENotify, sizeof(imuBuf));   // remote clients will be able to
                                                                                          // get notifications if this characteristic changes                                                                
void setup()
{
      Serial.begin(9600);    // initialize serial communication
    bool txpower_set = BLE.setTxPower(4);
    BLE.begin();
    CurieIMU.begin();
    BLE.setLocalName("Imu");
    BLE.setAdvertisedServiceUuid(bleImuService.uuid());  // add the service UUID
    //Accelerometer sampling rate = 200Hz
    CurieIMU.setAccelerometerRate(200);
    //Minimum, Maximum connection interval 7.5ms- 10ms (0x06=7.5/1.25, 0x08= 10/1.25)
    //0x028=50/1.25
    BLE.setConnectionInterval(0x06,0x28);
    BLE.addService(bleImuService);   // Add the Imu service
    bleImuService.addCharacteristic(bleImuChar); // add the Imu characteristic
    bleImuService.addCharacteristic(bleImuChar1);
    bleImuService.addCharacteristic(bleImuChar2);
    bleImuService.addCharacteristic(bleImuChar3);
    BLE.advertise();
}

void loop()
{
    BLEDevice central = BLE.central();
    // if a central is connected to peripheral:
    if (central)
    {
        long currentMillis, sentTime;
        // Send IMU data as long as the central is still connected
        currentMillis = sentTime = millis();
        while (central.connected())
        {
          while(bleImuChar.canNotify())
          {
            // update IMU data every 10ms
            if ((millis() - sentTime) >= 10)
            {
                    for(int i=0; i<=1; i++)
                    {
                      //Reads acc data
                      recordImuData(i);
                      delay(10);
                    }
                    
                    bleImuChar.setValue((unsigned char *)&(imuBuf[0]), sizeof(imuBuf[0])); // Sets Tx buffer to
                                                                                                                                     //the read acc data
                                
                    sentTime = millis();  //note what time data was sent
                    for(int j=0;j<=1;j++)
                    {
                      for(int k=0; k<=2; k++)
                      {
                        Serial.println(imuBuf[j].slot[k]);
                        imuBuf[j].slot[k]=0;
                      }
                    }
                    
                 }
            }
        }
       } // end of while loop
 }


// This function records the IMU data that we send to the central
void recordImuData(int index)
{
    // Read IMU data.
    int ax, ay, az;
    imuBuf[index].index = seqNum++;
    CurieIMU.readAccelerometer(ax, ay, az);
        // the data into the buffer
    imuBuf[index].slot[0] = (unsigned int)(ax);
    imuBuf[index].slot[1] = (unsigned int)(ay);
    imuBuf[index].slot[2] = (unsigned int)(az);

}

pert

Also posted at:

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.

timontunes

Also posted at:

If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.
Sorry about that Pert, I didn't know.
I have updated now.
Will follow from now on.
Merci!
Tim

Go Up