You are here

Print out uint64 to UART | Cypress Semiconductor

Print out uint64 to UART

Summary: 8 Replies, Latest post by dvorakvik on 04 Oct 2016 09:03 PM PDT
Verified Answers: 1
Last post
Log in to post new comments.
user_459156114's picture
User
35 posts

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? 

user_1377889's picture
User
10439 posts

Try the "l" (small letter "L") specifier, so you get  sprintf(buff, "%ld", YourInt64);

Have a look here for sprintf usage.

 

Bob

dvorakvik's picture
User
110 posts

You may try my old example, now updated to the last PSoC Creator version

Viktor

dvorakvik's picture
User
110 posts

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

 

user_459156114's picture
User
35 posts

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!!

dvorakvik's picture
User
110 posts

Ran, 

on PSoC4 your code ....   sprintf(buff, "%ld", YourInt64); ..... "works" only if the YourInt64 value is < than uint32 

SPRINTF ERROR PERSISTS

Viktor 

user_459156114's picture
User
35 posts

Ah I see...that's really weird. Have you found a viable work around? 

user_1377889's picture
User
10439 posts

Oops, one of my posts disaipeared...  Or I forgot to send it  :-(

I saw a trick using float formatting. Remember to set the heap size to at least 0x200 and allow newlib nano float formatting.

 

See attached.

 

Bob

dvorakvik's picture
User
110 posts

The uint64 -> string tested solution is attached.

Viktor

Log in to post new comments.