Hello all,
The problem resurfaced after little more code is added to my program. Optimisation is set to s. Sprintf behaves funny with %f. I am giving below sample code and the output
unsigned char buffer[100];
sprintf (buffer,"Hello %f hello\n\r", 34.56);
send_2_serial (buffer);
the output for the first two times is correct
Hello 34.56 hello
Before every output some other reasonably large calculations are carried
Hello 34.56 hello
Hello hello
The float converted string is missing.
Could anybody throw some light on why this is happening? Thanks in advance.
Regards
Nayani P
On 1/18/06, Parthasaradhi Nayani wrote:
> Hello all,
> In one of my projects (ATMega128 based) I am using floating point
numbers
> and sprintf to write a formatted record to a buffer. Tthe buffer contents is
> then sent to a mini printer. The first two records print properly and
> thereafter I am getting garbage from sprintf!! The optimisation was set to
> 0. When I change the optimisation to s, then correct data is being printed!!
> Moreover there is a difference in the way _delay_loop_2 and _delay_loop_1
> delays are generated with different optimisations. I would like to know the
> reason why this is happening (specially with sprintf) to avoid any pitfalls
> in my coding. Thanks in advance.