You are here

integer to ascii (itoa) usage or equivalent | Cypress Semiconductor

integer to ascii (itoa) usage or equivalent

Summary: 7 Replies, Latest post by Bob Marlowe on 19 Jul 2017 07:53 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
Ted Mawson's picture
User
22 posts

I've searched and read other threads in this forum but I can't get this to be recognized. I want to take an ADC result and convert it to a string so I can send t out over UART.

itoa seems not to be recognized.

I'm in PSoC creator 4.1 and the compiler is GCC 4.1.0.2686

Thanks in advance.

user_1377889's picture
User
10705 posts

Did you #include <stdlib.h>

 

Bob

Ted Mawson's picture
User
22 posts

Thanks Bob, now I have #include[d] <stdlib.h> and the itoa() function is recognized :D

Where can I find the documentation of all the extra functions that are in stdlib.h?

user_1377889's picture
User
10705 posts

Best place will be GCC documentation. Additional libraries of interest is newlib-nano.

 

Bob

Ted Mawson's picture
User
22 posts

Thanks, one other question if I may... now I have the result coming from the ADC and I use itoa() to convert it, like this...

itoa(ADC_SAR_Seq_1_GetResult16(1),buffy, 10);

The char string built in buffy (an array of char) is clearly assuming that the integer input is signed so a 0xFFF result reads -2048, is there a simple way to cast this so that I don't have that issue?

user_1377889's picture
User
10705 posts

itoa() macro is a kind of simple. Did you ever consider using formatted IO with printf().

This will require some settings:

In Project -> Build Settings -> Linker set "Use Newlib nano" and "use newlib nano float formatting" (if you need that)

In System view set Heap Size to 0x0200

In your modules #include <stdio.h>

For formatted I/O see here. Best will be sprintf(Buffer,...) and UART_PutString(Buffer)

Do not forget to put a delimiter at end of your string. So the receiver will be able to detect and syncronize to the begin of a new sequence.

 

Bob

Ted Mawson's picture
User
22 posts

Bob, thanks for those suggestion which I'll investigate.  I read up on newlib-nano and it seems to be applying some neat algorithms to make sprintf() and printf() statements as small as possible in the compiled code.  Can you comment on that?  Thanks

user_1377889's picture
User
10705 posts

Yes, newlib nano has a very small footprint. Only exception to standard is that the scanf() functions are not contained.

 

Bob

Log in to post new comments.