cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

KaSc_297456
New Contributor

 Hi 

   

I'm trying to get a analog signal converted in a single ended ADC, and then i want to transmit the converted value over the BLE. For this i trying to create a custom profile. How do i transmit my converted value? 

   

Thanks in advance. 

0 Likes
Reply
1 Solution
HeLi_263931
Honored Contributor II

Just a short intro (assuming you know how to read the ADC data and get it into a variable):

   
        
  • BLE doesn't do 'data transfer' in the sense of a data stream (like in a serial port)
  •     
  • BLE uses the notion of 'Attributes'
  •     
  • the side that provides the attribute data is the 'GATT server', the reading side is the 'GATT client'
  •     
  • attribute data is either transferred when the GATT client wants to read it, or via a notification
  •     
  • so when you have defined your custom service, your client just needs to set the attribute value, and fire the notification when they are enabled
  •     
  • don't forget to handle the notification settings that might come in from the GATT client
  •    

View solution in original post

0 Likes
Reply
16 Replies
Anonymous
Not applicable

 Can you give this post a look? It is related to something similar.

   

 

   

http://www.cypress.com/?app=forum&id=5283&rID=107084

0 Likes
Reply
Anonymous
Not applicable

Hi,

   

Can you please update the link? 

   

Thanks 

0 Likes
Reply
KaSc_297456
New Contributor

Not exactly: 

   

My code in main.c is: 

   

#include <project.h>

   

int main()

   

{

   

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

   

    ADC_Start();

   

    ADC_StartConvert();

   

    int EMGval = 0; 

   

 

   

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

   

    for(;;)

   

    {

   

        EMGval = ADC_GetResult16(0); 

   

       //Transmit EMGval with BLE 

   

    }

   

}

   

 

   

Could i use CyBle_GattcReadCharacteristicValue() here? And if, which parameters should this be given? 

0 Likes
Reply
HeLi_263931
Honored Contributor II

Just a short intro (assuming you know how to read the ADC data and get it into a variable):

   
        
  • BLE doesn't do 'data transfer' in the sense of a data stream (like in a serial port)
  •     
  • BLE uses the notion of 'Attributes'
  •     
  • the side that provides the attribute data is the 'GATT server', the reading side is the 'GATT client'
  •     
  • attribute data is either transferred when the GATT client wants to read it, or via a notification
  •     
  • so when you have defined your custom service, your client just needs to set the attribute value, and fire the notification when they are enabled
  •     
  • don't forget to handle the notification settings that might come in from the GATT client
  •    

View solution in original post

0 Likes
Reply
HeLi_263931
Honored Contributor II

Take this example project as a starting point: http://www.cypress.com/?rID=107617&cache=0 . Instead of the proximity data you need to send your ADC value.

Anonymous
Not applicable

can you update link to this project?

0 Likes
Reply
KaSc_297456
New Contributor

 Thanks you very much! 

0 Likes
Reply
Anonymous
Not applicable

Project provided by hli is the best way to start.

   

Just make following changes in the project:
1) Open BLE Component configuration by double clicking on it-> Profiles tab -> CapSense Proximity (characteristic) -> Change the type to sint16 (2 bytes) (marked red in attached image).

   

2) In BLEApplication.c file -> SendDataOverCapSenseNotification(), make the following change to notificationHandle.value.len

   

notificationHandle.value.len = 2;

   

 

   

3) Change the definition of the function SendDataOverCapSenseNotification(uint8) to SendDataOverCapSenseNotification(int16). This way, you can pass your 2 bytes of ADC data to it.

   

 

   

4) Redefine the function HandleCapSenseProximity()in main.c to obtain your ADC data and pass to the SendDataOverCapSenseNotification() function.

   

 

   

I would also advise you to change the value of UUID of the service and characteristic in BLE component to a different value (marked in purple in attached image). This way, the CySmart App will not recognize it as CapSense proximity.

   

 

   

-Rohit

0 Likes
Reply
KaSc_297456
New Contributor

 I tried to make the changes on the project that you recommended. But is still have some issues. 

   

I have change the settings in the CapSense Characteristics, and I modified the functions as followed: 

   

void HandleCapSenseProximity(void) {

   

int16 EMGval;

   

        EMGval = ADC_GetResult16(0);

   

SendDataOverCapSenseNotification(EMGval);    

   

}

   

 

   

and 

   

void SendDataOverCapSenseNotification(int16 EMGval)

   

{

   

CYBLE_GATTS_HANDLE_VALUE_NTF_T notificationHandle; 

   

if(busyStatus == CYBLE_STACK_STATE_FREE)

   

{

   

notificationHandle.attrHandle = CYBLE_CAPSENSE_CAPSENSE_PROXIMITY_CHAR_HANDLE;

   

notificationHandle.value.val = &EMGval;

   

notificationHandle.value.len = 2;

   

 

   

CyBle_GattsNotification(connectionHandle,&notificationHandle);

   

}

   

}

   

 

   

I've also given the characteristics and services a unique UUID 

   

 

   

But the value i get is just constant 14337, and the actual value I'm sending is a DC that can vari from 0 to 5 volt. 

0 Likes
Reply
JoMe_264151
Expert II

You did not wati for a conversion cycle ready before reading channel 0.

   

I cannot se whether you issued a ADC_StartConvert().

   

The BLE is sent to sleep, did you care for that sending the ADC to sleep, and wakeup or did you remove the

   

#define ENABLE_LOW_POWER_MODE in BLEApplications.h

   

 

   

Bob

0 Likes
Reply
KaSc_297456
New Contributor

Thanks. I though when called ADC_StartConvert() it was constantly converty until i called a method to stop it. 

   

But i works now! 

   

Thanks alot!

0 Likes
Reply
HeLi_263931
Honored Contributor II

The ADC can actually do that, when you configure it that way (just look at the configuration dialog). But even then you should for the finished conversion to be sure you get a valid result.

0 Likes
Reply
Anonymous
Not applicable

 Hello,

   

I don't know if it's a correct place to post my issue! But I'm doing similar thing..

   

 

   

I have modified the CapSense Proximity Project to send data stream. I have succeeded but I have some questions.

   

 

   
/*This is only a example, for the future in this part I going to use the ADC to take data of analog sensor and put data in the DataSend vector*/ 
   
void HandleCapSenseProximity(void)
   
{
   
    uint8 DataSend[MAX_INDEX];  //Data stream to send
   
    uint8 index;
   
    static uint16 cont = 0;
   
   /*Increment data*/
   
    for(index=0;index < MAX_INDEX; index++) 
   
    {
   
        DataSend[index] = 0x00+cont; 
   
        cont++;
   
    }
   
SendDataOverCapSenseNotification(DataSend); 
   
}
   
 
   
/*-------------------------------------------------------------------------------------------------------------------------------------------*/
   
void SendDataOverCapSenseNotification(uint8 DataSend[])
{
/* 'notificationHandle' is handle to store notification data parameters */
CYBLE_GATTS_HANDLE_VALUE_NTF_T notificationHandle; 
/* If stack is not busy, then send the notification */
if(busyStatus == CYBLE_STACK_STATE_FREE)
{
/* Update Notification handle with proximity data*/
notificationHandle.attrHandle = CYBLE_CAPSENSE_CAPSENSE_PROXIMITY_CHAR_HANDLE; notificationHandle.value.val = DataSend;
notificationHandle.value.len = NOTIFICATION_DATA_LEN; //max size of vector:15
/* Report data to BLE component for sending data by notifications*/
CyBle_GattsNotification(connectionHandle,&notificationHandle);
}
}
    

 

   

I'm using the CySmart1.0 tools to the Client. When I enable to receive notification, I receive some times 2 or 3 data stream in the same time.

   

 

   

[11:29:36:746] : 'Characteristic Value Notification' event received

   

[11:29:36:746] : Attribute Handle: 0x000E

   

[11:29:36:746] : Value: [0D:0E:0F:10:11:12:13:14:15:16:17:18:19:1A:1B]

   

[11:29:36:746] : 'Characteristic Value Notification' event received

   

[11:29:36:746] : Attribute Handle: 0x000E

   

[11:29:36:746] : Value: [1C:1D:1E:1F:20:21:22:23:24:25:26:27:28:29:2A]

   

[11:29:36:761] : 'Characteristic Value Notification' event received

   

[11:29:36:761] : Attribute Handle: 0x000E

   

[11:29:36:761] : Value: [2B:2C:2D:2E:2F:30:31:32:33:34:35:36:37:38:39]

   

 

   

Does this function control the data sent? CyBle_GattsNotification(connectionHandle,&notificationHandle); 

   

 How can I control to send only a one stream data for each interval connection?

0 Likes
Reply
HeLi_263931
Honored Contributor II

There is no "data stream" in BLE. It uses the notion of attributes (that form in the end kind of a tree). Typically the other end of the connection (the GATT client) queries the values of the attributes its interested in. A notification changes this into a push whenever the attribute value changes. But its only the current value thats pushed.

   

What might happen in your case: the payload length is limited, so maybe the notification is split into multiple packages.

0 Likes
Reply
Anonymous
Not applicable

I am trying to take code from the CapSense project and bring it into an existing project of mine. There's one symbol that I cannot find in the original project: CYBLE_CAPSENSE_CAPSENSE_PROXIMITY_CHAR_HANDLE

   

Is this the UUID of the characteristic that's defined in Creator for the BLE component?

0 Likes
Reply
Anonymous
Not applicable

I did eventually figure this out. It turns out that characteristics have both a UUID and a handle, and they are different. (It took me a while to realize what was meant by "handle".)  The only way I could figure out what the handle was for my custom characteristic was connect to the PSoC and use CySmart to read the BLE signal, and it showed what the handle value is. There's probably a better way, but I couldn't find it.

0 Likes
Reply