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: Simple_Central Write request and Read response

Part Number: CC2640R2F

Hi,

I am able to write 1 byte request and 1 byte response successfully, But i want to send 20 byte request to Peripheral device and i want to receive 20 byte response from the Peripheral device.

Can anyone suggest me the procedure for this operation.

Thanks & regards

~Sretha reddy

  • How did you implement the 1 byte request and 1 byte response?

    You should be able to achieve it by expanding the characteristic to a 20 bytes array.
  • Thank you Christin for your reply,

    Actually i modified the 16 bit UUID with 128 bit UUID both in Central and peripheral examples.

    By using this definition  #define DEFAULT_DEV_DISC_BY_SVC_UUID          TRUE , i am able to discover the device, is it means that i am able to detect 128 bit UUID with no error?

    But  i am not able to perform read and write operation.

    case GATT_RW:
    Display_print0(dispHandle, 14, 0, "Entered read and write function");
    if (charHdl != 0 &&
    procedureInProgress == FALSE)
    {
    Display_print0(dispHandle, 15, 0, "Entered write function");
    uint8_t status;
    // Do a read or write as long as no other read or write is in progress
    if (doWrite)
    {
    // Do a write
    attWriteReq_t req;

    req.pValue = GATT_bm_alloc(connHandle, ATT_WRITE_REQ, 1, NULL);
    if ( req.pValue != NULL )
    {
    req.handle = charHdl;
    req.len = 1;
    req.pValue[0] = charVal;
    req.sig = 0;
    req.cmd = 0;

    status = GATT_WriteCharValue(connHandle, &req, selfEntity);
    if ( status != SUCCESS )
    {
    GATT_bm_free((gattMsg_t *)&req, ATT_WRITE_REQ);
    }
    }
    else
    {
    status = bleMemAllocError;
    }
    }
    else
    {
    Display_print0(dispHandle, 16, 0, "Entered read function");
    // Do a read
    attReadReq_t req;

    req.handle = charHdl;
    status = GATT_ReadCharValue(connHandle, &req, selfEntity);
    }

    if (status == SUCCESS)
    {
    procedureInProgress = TRUE;
    doWrite = !doWrite;
    }
    }
    Display_print0(dispHandle, 17, 0, "Exiting read and write function");
    break;

    This is my read and write function, and i am receiving only Read error 1 and write error 1, i am not understanding where is the problem.

    with 16 bit UUID everything is working perfectly.

    Please help me to solve this issue

    Thanks & regards

    ~Sretha Reddy

  • I understood that the below functions are not getting executed:

    static void SimpleBLECentral_processGATTDiscEvent(gattMsgEvent_t *pMsg)
    {
    if (discState == BLE_DISC_STATE_MTU)
    {
    // MTU size response received, discover simple service
    if (pMsg->method == ATT_EXCHANGE_MTU_RSP)
    {
    uint8 uuid[UUID_SIZE] = { TI_UUID(SIMPLEPROFILE_CHAR1_UUID) };

    // Just in case we're using the default MTU size (23 octets)
    Display_print1(dispHandle, 4, 0, "MTU Size: %d", ATT_MTU_SIZE);

    discState = BLE_DISC_STATE_SVC;

    // Discovery simple service
    VOID GATT_DiscPrimaryServiceByUUID(connHandle, uuid, ATT_UUID_SIZE,
    selfEntity);
    }
    }
    else if (discState == BLE_DISC_STATE_SVC)
    {
    // Service found, store handles
    if (pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP &&
    pMsg->msg.findByTypeValueRsp.numInfo > 0)
    {
    svcStartHdl = ATT_ATTR_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
    svcEndHdl = ATT_GRP_END_HANDLE(pMsg->msg.findByTypeValueRsp.pHandlesInfo, 0);
    }

    // If procedure complete
    if (((pMsg->method == ATT_FIND_BY_TYPE_VALUE_RSP) &&
    (pMsg->hdr.status == bleProcedureComplete)) ||
    (pMsg->method == ATT_ERROR_RSP))
    {
    if (svcStartHdl != 0)
    {
    Display_print0(dispHandle, 11, 0, "entered svchdl fun");
    attReadByTypeReq_t req;

    // Discover characteristic
    discState = BLE_DISC_STATE_CHAR;

    req.startHandle = svcStartHdl;
    req.endHandle = svcEndHdl;
    req.type.len = ATT_UUID_SIZE;
    uint8 uuid[UUID_SIZE] = { TI_UUID(SIMPLEPROFILE_CHAR1_UUID) };
    VOID osal_memcpy( req.type.uuid, uuid, UUID_SIZE );

    VOID GATT_ReadUsingCharUUID(connHandle, &req, selfEntity);
    }
    }
    }
    else if (discState == BLE_DISC_STATE_CHAR)
    {
    Display_print0(dispHandle, 12, 0, "entered disc state char function");
    // Characteristic found, store handle
    if ((pMsg->method == ATT_READ_BY_TYPE_RSP) &&
    (pMsg->msg.readByTypeRsp.numPairs > 0))
    {
    charHdl = BUILD_UINT16(pMsg->msg.readByTypeRsp.pDataList[0],
    pMsg->msg.readByTypeRsp.pDataList[1]);

    Display_print0(dispHandle, 2, 0, "Simple Svc Found");
    procedureInProgress = FALSE;
    }

    discState = BLE_DISC_STATE_IDLE;
    }
    }

    /*********************************************************************
    * @fn SimpleBLECentral_findSvcUuid
    *
    * @brief Find a given UUID in an advertiser's service UUID list.
    *
    * @return TRUE if service UUID found
    */
    static bool SimpleBLECentral_findSvcUuid(uint16_t uuid, uint8_t *pData,
    uint8_t dataLen)
    {
    uint8_t adLen;
    uint8_t adType;
    uint8_t *pEnd;

    pEnd = pData + dataLen - 1;

    // While end of data not reached
    while (pData < pEnd)
    {
    // Get length of next AD item
    adLen = *pData++;
    if (adLen > 0)
    {
    adType = *pData;

    // If AD type is for 16-bit service UUID
    if ((adType == GAP_ADTYPE_128BIT_MORE) ||
    (adType == GAP_ADTYPE_128BIT_COMPLETE))
    {
    pData++;
    adLen--;

    // For each UUID in list
    while (adLen >= 2 && pData < pEnd)
    {
    // Check for match
    if ((pData[0] == LO_UINT16(uuid)) && (pData[1] == HI_UINT16(uuid)))
    {
    // Match found
    return TRUE;
    }

    // Go to next
    pData += 2;
    adLen -= 2;
    }

    // Handle possible erroneous extra byte in UUID list
    if (adLen == 1)
    {
    pData++;
    }
    }
    else
    {
    // Go to next item
    pData += adLen;
    }
    }
    }

    // Match not found
    return FALSE;
    }

    Is there anything i need to change in these functions?

  • Please use the insert code function to past code. It's a bit difficult to read the code in text format.

    Did you change the UUID? If not, what's the need on using 128bit UUID?

    Can you post the code modification you made for UUID?
  • Closing the thread due to inactivity.