Page 1 of 1

How to cast an integer/float into a string?

Posted: Thu Oct 10, 2013 1:17 pm
by Noname
Hello

Everyting is in the title :D.

I have some values from I2C sensors I want to display on a character display (uGFX). That's why I need to convert the int/floar values into strings.

Thanks

Re: How to cast an integer/float into a string?

Posted: Thu Oct 10, 2013 3:58 pm
by Giovanni
Hi,

Using sprintf() for example, it is no different from a normal C application. You may also use chprintf() but you need to create a stream writer to a string buffer.

Giovanni

Re: How to cast an integer/float into a string?

Posted: Thu Oct 10, 2013 5:07 pm
by Noname
Hello

Yes that is what I have tried before but the compiler doesn't seem to like the sprintf function :D.
I don't know why.

Linking build/ch.elf
c:/chibistudio/tools/gnu tools arm embedded/4.7 2013q2/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libc.a(lib_a-sbrkr.o): In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0xc): undefined reference to `_sbrk'
collect2.exe: error: ld returned 1 exit status

Re: How to cast an integer/float into a string?

Posted: Thu Oct 10, 2013 5:48 pm
by Giovanni
Hi,

This is because you must provide a _sbrk() implementation to the compiler. The compiler does not provide syscalls for a bare machine. the documentation is here: https://sourceware.org/newlib/libc.html#Syscalls

It is not complex, there is also an implementation under ./os/various/syscall.c but it was done for the YAGARTO compiler and must be adapted.

Giovanni

Re: How to cast an integer/float into a string?

Posted: Sun Oct 13, 2013 4:18 pm
by russian
Noname wrote:Everyting is in the title :D.Thanks


Giovanni is a kind man.

Using the word "cast" in this context tells me that you really need to figure out a bit of the fundamentals - like a couple of fundamental differences between primitive types and human-readable strings...