- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you bob!
i learn so much from you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are always welcome!
Bob