3 Replies Latest reply on Dec 12, 2017 6:28 AM by user_503006941

    CyBle_GattcReadCharacteristicValue(cyBle_connHandle, readReqParam) not working


      I have two CyBle modules in the project. One is the client (master) and the other server (peripheral). Upon power up, the peripheral updates all of the custom characteristics with specific values. I can connect to the peripheral with CySmart app and read/write to each characteristic so that side of things works great.


      On the central side, once it is connected to the other CyBle module, when I press a button on the central device, it sends a value to the peripheral and then the peripheral performs a function. I have a need to read a couple of the characteristics from the peripheral to be used in the client to alter the type of message being sent. I know the handle of the characteristic I want to read from so I try to use the function as follows


      readReqParam = 0x0010;

      bleApiResult = CyBle_GattcReadCharacteristicValue(cyBle_connHandle, readReqParam);


      When I call this function in my main program, I get the invalid operation error code and the system locks up every time.


      I have no problem writing from client to server but reading from server to client is not working at all. Not sure what is wrong or why. I added the event handling


                   readResponse = (CYBLE_GATTC_READ_BY_TYPE_RSP_PARAM_T *) eventparam;


      but that is never reached.


      I dont believe anything needs to be done on the peripheral (server side) since I can read any characteristic from the app. Since I am able to write to the server using a known handle, I dont think there is anything wrong because that works ok.


      This is extremely frustrating why a simple read is not working, help is greatly appreciated.





        • 1. Re: CyBle_GattcReadCharacteristicValue(cyBle_connHandle, readReqParam) not working

          I believe you need to have the characteristic handle "readReqParam" cast as the CYBLE_GATT_DB_ATTR_HANDLE_T type for the function to be okay with it. Although, since it resolves to a uint16, it might be something else...

          • 2. Re: CyBle_GattcReadCharacteristicValue(cyBle_connHandle, readReqParam) not working

            Is there a particular sequence of events after which this issue happens?

            Have you tried reading the characteristic value at a different instant?


            Could you post your project or at least your source files.


            • 3. Re: CyBle_GattcReadCharacteristicValue(cyBle_connHandle, readReqParam) not working



              It appears the problem is the heap size. When the command was invoked to read the characteristic, the event handler is supposed to respond once a result is ready. Whil ein debug, I found the event handler wasnt being called and instead it was going to the deafult IRQ nadler and then stuck in a while loop. Upon hours of searching, a recommendation to increase heap size should resolve this issue. The default heap size is 0x80. I tired setting to 0x200 and still didnt work. I set it to 0x800 and then the BLE event handler started working.


              I also have found that reading characteristics is very sensitive to timing. If you want to read more than one characteristic it is best to use the read multi characteristic API instead of single reads. If you try to send any read api before the previous one completes, then system crashes. In my application, I only need to read the server once on power up to get the servers initial data so now I use the read multiple characteristic api for a block of handles that I already know what those handles are.


              I find the Cypress API information very poor in both their implementation explanation but also general information that could impact proper operation such as heap size. I spent a day on this which should have taken 5 minutes with better information available.


              Thanks for your reply, hope what I found is helpful to you in the future.