cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

Anonymous
Not applicable

Hi I'm trying to send a float number  I'm working with the Cypress BLE CY8C4248LQI-BL583, now im sending all the data in uint8_array but i have an array with length 90 so this decrease a lot the transfer speed, now I want to send all the data in float numbers but I don't know which function I need to use and how, because right now I'm using this one

   

  dataHandle.attrHandle = attrHandle;
  dataHandle.value.val = data;
  dataHandle.value.len = len;

   

  CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);

   

 

   

Thanks a lot for your help!!

   

 

   

Alejandro Villa

0 Likes
1 Solution
Anonymous
Not applicable

Hi,

   

The CyBle_GattsWriteAttributeValue can accept only arrays of uint8 type. A float value may be represented in 4 bytes and the Float value may be sent as an uint8 array with 4 elements.

   

For example:

   

float n;

   

uint8 temp[4];

   

temp[0] = n & 0xFF:

   

temp[1] = (n>>8)>> 0xFF;

   

temp[2] = (n>>16)>> 0xFF;

   

temp[3] = (n>>34)>> 0xFF;

   

dataHandle.attrHandle = attrHandle;
  dataHandle.value.val = temp;
  dataHandle.value.len = 4;

   

  CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);

   

Regards,

   

- Madhu Sudhan

View solution in original post

0 Likes
5 Replies
Anonymous
Not applicable

Hi,

   

The CyBle_GattsWriteAttributeValue can accept only arrays of uint8 type. A float value may be represented in 4 bytes and the Float value may be sent as an uint8 array with 4 elements.

   

For example:

   

float n;

   

uint8 temp[4];

   

temp[0] = n & 0xFF:

   

temp[1] = (n>>8)>> 0xFF;

   

temp[2] = (n>>16)>> 0xFF;

   

temp[3] = (n>>34)>> 0xFF;

   

dataHandle.attrHandle = attrHandle;
  dataHandle.value.val = temp;
  dataHandle.value.len = 4;

   

  CyBle_GattsWriteAttributeValue(&imuHandle,FALSE,&cyBle_connHandle,CYBLE_GATT_DB_PEER_INITIATED);

   

Regards,

   

- Madhu Sudhan

View solution in original post

0 Likes
Bob_Marlowe
Expert II

Good morning, Madhu 😉

   

Can you edit your post and replace the " >>0xFF" with " & 0xFF"

   

The ">> 34" is a  ">> 24"

   

 

   

Bob

Anonymous
Not applicable

Thanks a lot Madhu and Bob,

   

So there are not a function to send float, I need to separate my float numbers to send it through the BLE, so I don't understand why in the settings of the BLE it let me change the Type of the field that I want to send, because I always need to change the type into an array.

   

I have another question, if I want to send more than 3 fields in each characteristics how do I send that, like the picture.

   

 

   

Thanks again for your help 

   

 

   

   

Alejandro Villa

   

 

   

0 Likes
RoBe_1502026
Contributor

The code above doesn't work. give an invalid operand to binary expressions (float and int) for the & 

   

and the same error but (float to float ) with the >>

   

How do i resolve this. I really want to send floats via BLE.

   

Thanks,

   

Rob Berry

0 Likes
Anonymous
Not applicable

Hallo,

   

I had the same issues and solved the problem with using an "union":

   

union {

   

float flData;

   

uint8 charData[4];

   

 } data;

   

 

   

Now you can send the data as an uint8 array: "(uint8 *)&data.charData"

   

 

   

Regards,

   

Dominik Führer

0 Likes