cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

srme_3928751
New Contributor

Hi,

   I am working on CY8CKIT-142 and I created one custom profile BLE application with reference to CAPSENSE_RGB_LED_SENSOR application.Now my queries are

1.How to  receive the string sent from BLE Android Application to PSOC BLE.

2.In the same way how to send the string from PSOC to Android App.

3.While sending and receiving the data the data should be of length 20????

    As the test application was not ready I didn't test the below code which I wrote,so please can anyone suggest whether I am following correct way of coding:

  For the first query the code as follows which I was trying:

         uint8 *Transfer_Data;

         case CYBLE_EVT_GATTS_WRITE_REQ:

            /* This event is received when Central device sends a Write command on an Attribute */

            wrReqParam = (CYBLE_GATTS_WRITE_REQ_PARAM_T *) event Param

               Receive_Data = &wrReqParam->handleValPair.value.val[0];   //Will this assaignment will work for receiving string.

                 uart_write(Receive_Data,len);  //Fuction created to write to UART

For the Second query the code as follows which I was trying:

           case CYBLE_EVT_GATTS_WRITE_REQ:

              for(;i>0;i--)

               {

                /* Save character received by UARTx device into the receive buffer */ 

                 while(!(*(uint8_t*)Transfer_Data = (unsigned char)UART_1_UartGetChar())); 

                /* Stop reading if CR (Ox0D) character is received */ 

                 if (*(uint8_t*)Transfer_Data == '\0') {     /* New line character (CR) received ? */ 

                  *(uint8_t*)Transfer_Data = '\n';           /* Yes, convert LF to '\n' char. */ 

                 break;                           /* Stop loop and return received char(s) */ 

                 } 

                Transfer_Data++;                   /* Increase buffer pointer */ 

               }

                 BLENotificationCCCDhandle.attrHandle = CYBLE_TRANSFER_DATA_CONTROL_CLIENT_CHARACTERISTIC_CONFIGURATION_DESC_HANDLE;

                 BLENotificationCCCDhandle.value.val  = Transfer_Data;

                 BLENotificationCCCDhandle.value.len  = 20;

                 CyBle_GattsWriteAttributeValue(&BLENotificationCCCDhandle,FALSE, &connectionHandle, CYBLE_GATT_DB_PEER_INITIATED);

For the Third query does below code is enough:    

                BLENotificationCCCDhandle.value.len  = 20;

0 Likes
1 Solution
GyanC_36
Employee

Find attached project. I used a different device, select the correct device before programming.

-Gyan

View solution in original post

0 Likes
16 Replies
GyanC_36
Employee

Hi Srikanth,

        Please refer the code example from below link along with the document explaining the procedure for testing this project.

    PSoC-4-BLE/100_Projects_in_100_Days/Day020_BLE_UART at master · cypresssemiconductorco/PSoC-4-BLE · ...

Note: There are two PSoC Creator project 1) BLE Central 2) BLE Peripheral. You can use Mobile as a BLE Central device instead of this PSoC Creator Project (BLE Central).

Please go through the documentation for more details.

-Gyan

0 Likes
srme_3928751
New Contributor

Hi Gyan,

   Thanks for your reply and I have gone through the example but it was not the query which I was expecting.

=>My questions is how to receive a string from mobile and how to send a string to mobile from BLE.

=>How to check the data length while receiving and sending from BLE.

        Please check the code in my main question and tell whether I am following correct procedure to receive and send string from BLE.

Regards

srikanth.

0 Likes
GyanC_36
Employee

Srikanth,

   Did you went through the document and tested the Peripheral project ?

First we need to know what all are the methods for transfer data over BLE. Please refer below application note for details.

http://www.cypress.com/file/141171/download

For your queries ---

1.How to  receive the string sent from BLE Android Application to PSOC BLE.

Ans: Conceptually you are doing right but to receive the complete string ( You can write ASCII data from the Mobile App ( CySmart)) ,you can do something like below.

UART_SpiUartPutArray(uartRxDataWrReq->handleValPair.value.val, \

                                    (uint32) uartRxDataWrReq->handleValPair.value.len);

2.In the same way how to send the string from PSOC to Android App.

Ans: There are several methods to send the data from PSoC to Mobile such as  Notification, Indication, Read from Central. The example project implements Notification Method. It takes the ASCII data over UART and send it to Central device over Notification. Central device CySmart Mobile App can receive the data as ASCII characters.

3.While sending and receiving the data the data should be of length 20????

Ans: Not necessary. 20 bytes are the maximum length a BLE 4.1 compliant device can send in a single packet.

Please refer the Application Note and test the project. Your all questions will resolve hopefully.

PS:

BLENotificationCCCDhandle.value.val  = Transfer_Data;

                // BLENotificationCCCDhandle.value.len  = 20;

   BLENotificationCCCDhandle.value.len  = sizeof(Transfer_Data); //GYAN

-Gyan

0 Likes
srme_3928751
New Contributor

Hi Gyan,

    Actually I m not able to run the application which you have suggested as BLE component is v3.54. I tried to upgrade the component but it was not updating to 4.2.

   As you told to use below API to print in UART. I will try it and let you know if any issues in receiving data.

UART_SpiUartPutArray(uartRxDataWrReq->handleValPair.value.val, \

                                    (uint32) uartRxDataWrReq->handleValPair.value.len);

One more query

   In the BLE configuration for Custom Characteristic do I need to include two field  components like

      Receive_Data  uint8 array 20

      Transfer_Data uint8 array 20

Regards

srikanth

0 Likes
GyanC_36
Employee

The BLE Component latest version is 3.54 only. 4.2 is PSoC Creator IDE Version.  Select the correct device you have and program. ( Right Click on Project name -> Device Selector )

0 Likes
srme_3928751
New Contributor

error.png

Attached is the error I am getting

0 Likes
GyanC_36
Employee

Right Click on the Project name -> Update Components.

0 Likes
srme_3928751
New Contributor

Hi Gyan,

   I tried to update components but of no use.

One more update I have tested my application I am able to receive the string from cypress app to BLE and I am able to see the string in teraterm.

  But what is happening is for the first time I am able to receive the string but if I want to send another string it was not able to send.If I want to send means I have to disconnect and reconnect to device again and send the string.I am not able to understand what was the problem.And I sure that BLE was not disconnected from mobile.

Regards

srikanth.

0 Likes
GyanC_36
Employee

"I tried to update components but of no use." -> What is the problem you are facing in running this project ? This project is exactly what you want to do. Well you can copy paste c files in your project or atleast can see the implementation in project C files.

The firmware you are writing is not handling the things correctly or you are not following the correct sequence of events.

You can share your workspace so that I can write the necessary codes and provide modify project.

-Gyan

0 Likes
srme_3928751
New Contributor

Hi Gyan,

Please find the attached project.

Regards

srikanth.

0 Likes
GyanC_36
Employee

Find attached project. I used a different device, select the correct device before programming.

-Gyan

View solution in original post

0 Likes
GyanC_36
Employee

You can use either of below for sending the data over UART.

1)     Receive_Data=&wrReqParam->handleValPair.value.val[0];

         uart_write(Receive_Data,wrReqParam->handleValPair.value.len);

OR

2)    UART_1_SpiUartPutArray(wrReqParam->handleValPair.value.val,  (uint32) wrReqParam->handleValPair.value.len);

-Gyan

0 Likes
srme_3928751
New Contributor

Hi Gyan,

  Thanks for the modified code now I am able to write continuously.

I have a doubt like I am writing a string to ble after that if I am doing a function call and returning from that function call also.After that I am not getting write event generated again.

Please find the attached file and look for the function call uart_read();

    Is it the correct way to call a function over there or we have to some another flags??

Regards

srikanth.

0 Likes
srme_3928751
New Contributor

Hi GYAN,

   

  When I am trying to send data from BLE to mobile I am using below API

CyBle_GattsWriteAttributeValue(&BLENotificationCCCDhandle,FALSE, &connectionHandle, CYBLE_GATT_DB_PEER_INITIATED);

     Where I am filling the BLENotificationCCCDhandle structure with data and length and in the mobile side I am hitting the notify button but I am not receiving the data there.Do I need to do any other than this?

Regards

srikanth.

0 Likes
GyanC_36
Employee

For sending data from peripheral side to Mobile client as a Notification, you have to use CyBle_GattsNotification() API.

I have attached here a peripheral project which receives data from Mobile as Write request and sends data to Mobile as Notification.

Please refer this project.

-Gyan

0 Likes
srme_3928751
New Contributor

Hi Gyan,

  Thanks for your reply.I have taken reference of your UART example and modified a little bit as follows

In the attached file in line no:18 I kept a check to see if enter was pressed over UART so that to break of the loop and send the string over BLE to mobile.The code is as follows:

if(uartTxData[index] == '\n'){

        uartTxData[index] = '\n';

        uartTxDataLength =0;

        break;

       }

But it was not happening like that it was waiting for 20 bytes to be entered and then sending the data over BLE to mobile.

Regards

srikanth.

0 Likes