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.

CC2640R2F: Error while perform write using multirole as master on cc2640r2f

Part Number: CC2640R2F


Hello,

I am using multi_role on cc2640r2f. Currently I am testing its behavior as central.

It scans for the peripheral and performs connection with peripheral. After the service and characteristic discovery is done. I tried to perform a write to slave characteristic as following:

bool mr_doGattWrite(uint8_t index)
{
  bStatus_t status = FAILURE;
  uint8_t charVal2 = 0x88;
  // If characteristic has been discovered
  if (discInfo[index].charHdl != 0)
  {
    // Do a read / write as long as no other read or write is in progress
    if (!doWrite)
    {
      // Do a write
      attWriteReq_t req;
      // Allocate GATT write request
      req.pValue = GATT_bm_alloc(connHandleMap[index].connHandle, ATT_WRITE_REQ, 1, NULL);
      // If successfully allocated
      if (req.pValue != NULL)
      {
        // Fill up request
        req.handle = discInfo[index].charHdl;
        req.len = 1;
        req.pValue[0] = charVal2;
        req.sig = 0;
        req.cmd = 0;

        // Send GATT write to controller
        status = GATT_WriteNoRsp (connHandleMap[index].connHandle, &req); // gives an error INVALIDPARAMETER
//      status = GATT_WriteCharValue(connHandleMap[index].connHandle, &req, selfEntity); // gives an error blePending


        // If not sucessfully sent
        if ( status != SUCCESS )
        {
          // Free write request as the controller will not
          GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
        }
      }
    }
}
    

When i tried with
 GATT_WriteNoRsp returns 0x02 (INVALIDPARAMETER)
and while using 

GATT_WriteCharValue  returns 0x16 (blePending)

I checked the discInfo[index].charHdl they are correct. I am generating a event once the characteristic discovery is done and in that event i am calling :

bool mr_doGattWrite(uint8_t index)

Following is the code where i start clock:

static void multi_role_processGATTDiscEvent(gattMsgEvent_t *pMsg)
{

       //first performed service discovery

// If we're discovering characteristics
else if (discInfo[connIndex].discState == BLE_DISC_STATE_CHAR)
{
// Characteristic found
if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&
(pMsg->msg.readByTypeRsp.numPairs > 0))
{
// Store handle
discInfo[connIndex].charHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
pMsg->msg.readByTypeRsp.pDataList[1]);

// "Simple Svc Found"
}
Util_startClock(&periodicWriteClock);
}

}



Why the write is not getting successful ?

Waiting for your kind reply.

  • Hello,

    GATT_WriteNoRsp requires that req.sig = FALSE and req.cmd = TRUE. This is why you are receiving invalid parameter.

    blePending means that the stack is unable to accept this command at this time (generally because there is no buffer available or another sync procedure is in progress). When blePending is received, it is recommended to wait a few connection events and try again until SUCCESS is received.
  • Hi sean,

    Thanks for your suggestion. It works now :)

  • Thanks for following up, glad it is working!
  • Hi Sean, May be it is of topic question but can you tell me how I can discover other characteristics after discovering the first characteristic. The slave has a service and it contains 3 characteristics. I am able to get only one characteristic with multirole.
  • hello,

    it appears you have created another thread about this here:
    e2e.ti.com/.../2375022

    I will support this over there. In general, service discovery is very purpose driven. The reason why multi_role only discovers on char is because it is only asking the stack to find one char. see the code snippet below:

    discInfo[connIndex].discState = BLE_DISC_STATE_CHAR;
    req.startHandle = discInfo[connIndex].svcStartHdl;
    req.endHandle = discInfo[connIndex].svcEndHdl;
    req.type.len = ATT_BT_UUID_SIZE;
    req.type.uuid[0] = LO_UINT16(SIMPLEPROFILE_CHAR1_UUID);
    req.type.uuid[1] = HI_UINT16(SIMPLEPROFILE_CHAR1_UUID);
    
    // Send characteristic discovery request
    VOID GATT_DiscCharsByUUID(pMsg->connHandle, &req, selfEntity);



    If you wanted to discover all chars you would have to modify the code to call GATT_DiscAllChars() and then modify the handler function and the state machine to process each char that comes in from the GATT_DiscAllCharsI() and store their handles. Later when you want to write to them, you'll need to use these handles.