- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using PSoC Creator 4.2 for the PSoC 5. I am monitoring a thermoelectric cooler (TEC) controller that reports both positive and negative currents and voltages. As long as everything is positive I'm ok. I'm taking an ascii string representation of hex numbers and converting it to a long that is stored in a uint32. If I get a negative number and apply the following, I always get 0x7FFFFFFF.
h2 is a global uint32 (hex 2 byte)
h2 = strtol(cbuf, (char**)NULL, 16); // create the uint32 from the payload
I'm sure there is an easy way to do this without having to write a bunch of low level code to sort the sign bit, exponent and mantissa. Should I cast h2 as float and use atof to convert it? Somebody has surely done this.
Thank you,
Nick
Solved! Go to Solution.
- Labels:
-
PSoC Creator & Designer Software
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I would try...
#include "project.h"
#include "stdio.h"
...
int32_t h2 ; // btw int32_t or uint32_t are 4 bytes
sscanf(cbuf, "%x", &h2) ;
...
moto
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I would try...
#include "project.h"
#include "stdio.h"
...
int32_t h2 ; // btw int32_t or uint32_t are 4 bytes
sscanf(cbuf, "%x", &h2) ;
...
moto