- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 */
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.