- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to simply print out a uint64 to UART. Currently I'm trying this:
uint64 = 12345678;
char buff[10];
sprintf(buff, “%” PRIu64, param);
UART_UartPurtString(buff);
Which all I get out from that is "lu" in the UART window. I've tried other options I found on stack overflow but they all give the same output...Is there something I'm missing here?
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So this:
sprintf(buff, "%ld", YourInt64);
Is working fine in PSoC 4 although you do get a warning of:
"format specifies type 'long' but the argument has type 'uint64'(aka 'unsigned long long').
Then if you try to change to this:
sprintf(buff, "%lld", YourInt64);
All that prints out to UART is "ld"
. It seems to working fine w/ @bobs answer 🙂 Thank you so much!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try the "l" (small letter "L") specifier, so you get sprintf(buff, "%ld", YourInt64);
Have a look here for sprintf usage.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob,
your idea .....
Try the "l" (small letter "L") specifier, so you get sprintf(buff, "%ld", YourInt64);
is clear, but it does not work at least on PSoC Creator 3.3
Another modifier like "%llu" for uint64 does not work too.
Viktor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So this:
sprintf(buff, "%ld", YourInt64);
Is working fine in PSoC 4 although you do get a warning of:
"format specifies type 'long' but the argument has type 'uint64'(aka 'unsigned long long').
Then if you try to change to this:
sprintf(buff, "%lld", YourInt64);
All that prints out to UART is "ld"
. It seems to working fine w/ @bobs answer 🙂 Thank you so much!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ran,
on PSoC4 your code .... sprintf(buff, "%ld", YourInt64); ..... "works" only if the YourInt64 value is < than uint32
SPRINTF ERROR PERSISTS
Viktor
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah I see...that's really weird. Have you found a viable work around?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This works too
char *myUint64S(uint64 n) { // only one in a printf format string since local buffer
static char res[21];
int i = 21;
res[--i] = 0;
if(n == 0) res[--i] = '0';
else while(n) {
res[--i] = '0' + n%10;
n /= 10;
}
return res + i;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
user_459156114,
I 'had' the same issue as you today and just saw your post. Sorry I'm late.
Bob's answer is to convert to float. OK but is subject to rounding/truncating issues.
As I indicated, I had the same problem until I identified the reason that the proper 'C' syntax of "%lld" did not work the first time in sprintf().
Proper syntax:
sprintf(buff, "%lld", YourInt64);
However, you are probably using the default build settings of:
Use newlib-nano = True
Set it to False and "%lld" will work correctly with a UInt64.
"Engineering is an Art. The Art of Compromise."