cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4

Anonymous
Not applicable

Hi experts,

   

 

   

I been trying to send  ADC data  from GATT server to Gatt client using custom service.   I  have written the following  BLE stack halnder function.  Could you check  why this is not working? I am using cy smart for PC and PROC BLE dongle  as GATT client. 

   

#include <project.h>

   

 

   

int16 ADC_data;

   

int16 ADC_data_mV;

   

#define channel_0  0

   

#define LED_On 0x01u 

   

uint16 ADC_volt_convert(void);

   

 

   

void Stack_Handler(uint32 eventCode, void *eventParam)

   

{

   

    

   

    CYBLE_CONN_HANDLE_T connHandle;

   

    CYBLE_GATTC_READ_REQ_T readReqParam;

   

    

   

switch(eventCode)

   

 

   

{

   

case CYBLE_EVT_STACK_ON:

   

case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:

   

 

   

        CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);

   

break;

   

 

   

        case  CYBLE_EVT_GATTC_READ_RSP  :

   

 

   

          readReqParam= ADC_volt_convert();

   

CyBle_GattcReadCharacteristicValue(connHandle, readReqParam );

   

break;

   

 

   

 

   

}

   

}

   

 

   

 

   

uint16 ADC_volt_convert()

   

{

   

ADC_SAR_Seq_1_StartConvert();

   

   while(ADC_SAR_Seq_1_IsEndConversion( ADC_SAR_Seq_1_RETURN_STATUS)==0)

   

       {

   

            }   

   

 

   

     ADC_data=  ADC_SAR_Seq_1_GetResult16(channel_0);

   

//ADC_data_mV=  ADC_SAR_Seq_1_CountsTo_mVolts(channel_0, ADC_data);

   

return(ADC_data);

   

}

   

 

   

 

   

 

   

int main()

   

{

   

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

   

 

   

   CyGlobalIntEnable;  /* Uncomment this line to enable global interrupts. */

   

CyBle_Start(Stack_Handler);

   

 

   

ADC_SAR_Seq_1_Start();

   

 

   

 

   

 

   

 

   

    for(;;)

   

    {

   

 

   

 

   

      CyBle_ProcessEvents();/* Place your application code here. */

   

    }

   

}

   

 

   

/* [] END OF FILE */

   
        
0 Likes
1 Solution
Anonymous
Not applicable

1) In your project, you will not get CYBLE_EVT_GATTC_WRITE_RSP as it is generated on the Client side. You are Server.

   

2) I did not understand this question. Does it mean that you want a way to send the latest data when you receive the Read request from connected GATT Client?

   

If yes, then note that unlike Write request from GATT Client, you do not get an event in Stack Handler when Client sends a read request. When a Read request comes, the stack automatically takes care of sending the correct data back. The only thing you need to do is to update the Database with the new value whenever you have. You updating the Database and Stack sending the data as part of read request are asynchronous.

   

Use the API CyBle_GattsWriteAttributeValue() to update your GATT database with new ADC data whenever it is available. The stack will take care of sending this data to Client when read request arrives.

   

Please check out the application note AN91162 at http://www.cypress.com/?rID=109900 regarding how to handle Custom GATT database on the server side.

   

3) Correct, the GATTS (GATT ending with S) are Server related API/macros and to be used in that role. GATTC (GATT with C) are Client based APIs which you don;t need in your project.

View solution in original post

0 Likes
7 Replies
ETRO_SSN583
Esteemed Contributor

Several projects over here  using ADC (first link) -

   

 

   

    

   

          

   

http://www.cypress.com/?id=5509 100 Projects in 100 Days with Bluetooth

   

http://www.cypress.com/?rID=102512     AN91445 - Antenna Design Guide

   

http://www.cypress.com/?rID=102505     AN94020 - Getting Started with PRoC™ BLE

   

http://www.cypress.com/?rID=110007     AN92584 - Designing for Low Power and Estimating Battery Life for BLE Applications

   

http://www.cypress.com/?rID=109900     AN91162 - Creating a BLE Custom Profile

   

http://www.cypress.com/?rID=110107     AN91184 - PSoC 4 BLE - Designing BLE Applications

   

http://www.cypress.com/?rID=102504     AN91267 - Getting Started with PSoC® 4 BLE

   

http://www.cypress.com/?rID=107332     AN95089 - PSoC® 4/PRoC™ BLE Crystal Oscillator Selection and Tuning Techniques

   

 

   

Also PSOC Creator start page, "Find Example projects" link.

   

 

   

Regards, Dana.

0 Likes
Bob_Marlowe
Expert II

Since my crystal-ball is in repair I am not able to check your program . I cannot see where ADC_volt_convert() is called and what you do with the result. Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.



Bob
 

0 Likes
ETRO_SSN583
Esteemed Contributor

You mean this in his code -

   

 

   

uint16 ADC_volt_convert()

   

{

   

ADC_SAR_Seq_1_StartConvert();

   

......

   

 

   

Dana.

0 Likes
rola_264706
Honored Contributor II

Try out this example should work for you it reads a signal an transmits it back to your Cysmart app. Also this gitthub locations has 49 good examples for using PSOC BLE.

   

 

   

https://github.com/cypresssemiconductorco/PSoC-4-BLE/tree/master/100_Projects_in_100_Days/Day045_Opt...

   

Bobgoar

0 Likes
Anonymous
Not applicable

 

   


   

Hi all,

   


   


   

I  have been able to solve the ADC  read problem. Still I have some doubt regarding the CyBle API.

   


   

1. CYBLE_EVT_GATTS_WRITE_REQ   event is generated whenever there is a write request from GATT client  Please correct if I am wrong.  Similary when would the  CYBLE_EVT_GATTC_WRITE_RSP  event would be generated.  I guess  CYBLE_EVT_GATTC_WRITE_RSP   is generated at the client side??  

   


   


   

2. If I want to send a read request seperatly from client instead of response to write request  which API should I use.

   


   

3. Another thing  I am confused with is    If I am configuring the GATT server I should use only  GATT server API function, not the GATTC client  API  fucntions ??  

0 Likes
Anonymous
Not applicable

1) In your project, you will not get CYBLE_EVT_GATTC_WRITE_RSP as it is generated on the Client side. You are Server.

   

2) I did not understand this question. Does it mean that you want a way to send the latest data when you receive the Read request from connected GATT Client?

   

If yes, then note that unlike Write request from GATT Client, you do not get an event in Stack Handler when Client sends a read request. When a Read request comes, the stack automatically takes care of sending the correct data back. The only thing you need to do is to update the Database with the new value whenever you have. You updating the Database and Stack sending the data as part of read request are asynchronous.

   

Use the API CyBle_GattsWriteAttributeValue() to update your GATT database with new ADC data whenever it is available. The stack will take care of sending this data to Client when read request arrives.

   

Please check out the application note AN91162 at http://www.cypress.com/?rID=109900 regarding how to handle Custom GATT database on the server side.

   

3) Correct, the GATTS (GATT ending with S) are Server related API/macros and to be used in that role. GATTC (GATT with C) are Client based APIs which you don;t need in your project.

View solution in original post

0 Likes
osguc_1563151
New Contributor

Following this conversation:

   

Imagine that the client wants to READ a timestamp. There is no sense that the server (proc 4 ble) must change the BLE database every second. I can see that the "CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ" event is generated when the client try to read. The problem is that the previous value is sent even if I modify the database with the CyBle_GattsWriteAttributeValue() function. Is there a way to synchronize the READ action with a new data to send?

0 Likes