RX63T and s(n)printf with float or double
RX63T and s(n)printf with float or double
Hi,
Hi Everybody,
since a few days I´m trying to get a LCD running on my RX63T. Works fine for any type of variable but not for “float” or “double”. In this case the controller runs to nowhere.
Piece of my code:
extern int8_t Buffer[];
extern uint32_t value; // = 0xABCDEF
extern double pi; // = 3.141592
lcd_ddram_addr(FIRST_LINE,POS_0);
lcd_putc(‘0’);
lcd_putc(‘x’);
snprintf(Buffer,sizeof(Buffer),”%X”,value);
write_lcd(lcd_data, Buffer);
lcd_ddram_addr(SECOND_LINE,POS_0);
snprintf(Buffer,sizeof(Buffer),”%i”,value);
write_lcd(lcd_data, Buffer);
/*
lcd_ddram_addr(THIRD_LINE,POS_0);
snprintf(Buffer,sizeof(Buffer),”%0.6f”,pi);
write_lcd(lcd_data, Buffer);
*/
I´m working with e2 studio (Version: 5.1.0.022) and GNURX v16.01(ELF), so I hope that anybody can explain to me what I´m doign wrong.
Thank you in advance
Alex
Hello Alex,
Thank you for reaching GNU Support Team. We have tried to snprintf some values based on your code and succeeded.
First of all, we would like you to explain a little bit what does “runs to nowhere” mean.
Then we would like to comment the code excerpt you have sent.
1. sizeof(Buffer); //will result in error, as sizeof is compile-time evaluated, and Buffer being defined in another module(extern), there is no way to know the size of an incomplete type; you can explicitly define it as “extern int8_t Buffer[32];” instead
2. Please note, you can avoid consecutive calls of the same function (e.g. “lcd_putc(‘0’); lcd_putc(‘x’);”) by
a) allocating sufficient space in the Buffer variable and
b) printing the proper contents in the same Buffer variable, e.g. snprintf(Buffer, sizeof(Buffer), “0x%X”, value)
So, in order for a prompt and to the point answer, we would like to ask you to send your project to us for analysis.
—
Thank you,
Grigore Dobra,
The GNU Tools Team