how to send hex (uint 8) via uart

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
EyLa_1625036
Level 3
Level 3
10 likes given 10 sign-ins 25 replies posted

hello all ,

   

i have a temp sensor connected to a psoc 4 device ,

   

this sensor sends to the psoc data via i2c and i recive it as 2 bytes stored in an array EX:

   

uint8 rawTemperature[2];

   

rawTemperature[0]=0x68;

   

rawTemperature[1]=0xfc;

   

what i want to do is combine the two bytes , convert them  from hex to integer , and then pass the value to UART 

   

EX:

   

0x68fc ---> convert to int -->26876 -->convert from int to string --> "26876" --> send to uart via uart_1_UartPutString("temp is: 26876")

   

i am having problem implementing this casting , 

   

how can i do it ?

   

thanks lampel

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

char Buffer[20];

   

int16 IntTemp = (int16)rawTemperature[0] << 8 | rawTemperature[1];

   

sprintf(Buffer,""temp is: %d",IntTemp);

   

uart_1_UartPutString(Buffer);

   

Do not forget to allow float formatting in Project Settings and to increase heap size to 0x200

   

 

   

Bob

0 Likes
EyLa_1625036
Level 3
Level 3
10 likes given 10 sign-ins 25 replies posted

thank you so much bob , works great! 

   

your solution works without :

   

"Do not forget to allow float formatting in Project Settings and to increase heap size to 0x200"

   

what do you mean ?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

In case you will send float numbers via UART

   

Creator -> Project -> Build Settings -> Linker -> use newlib-nano float formatting

   

and

   

Creator -> .cydwr view -> System -> Heap size 0x200

   

 

   

Bob

0 Likes
EyLa_1625036
Level 3
Level 3
10 likes given 10 sign-ins 25 replies posted

thank you bob!

   

i learn so much from you.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You are always welcome!

   

 

   

Bob

0 Likes