integer to ascii (itoa) usage or equivalent

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
TeMa_1467596
Level 5
Level 5
5 sign-ins 5 likes given First like received

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.

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you #include <stdlib.h>

   

 

   

Bob

View solution in original post

0 Likes
7 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did you #include <stdlib.h>

   

 

   

Bob

0 Likes
TeMa_1467596
Level 5
Level 5
5 sign-ins 5 likes given First like received

Thanks Bob, now I have #include <stdlib.h> and the itoa() function is recognized 😄

   

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

0 Likes
TeMa_1467596
Level 5
Level 5
5 sign-ins 5 likes given First like received

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?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

TeMa_1467596
Level 5
Level 5
5 sign-ins 5 likes given First like received

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

 

   

Bob

0 Likes