- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been through the knowledgebase and applied suggestions
Project -> Build Options -> linker -> Command Line -> -u_printf_float
Then tried Linker -> General -> Use newlib nano ... False
Finally tried, asm (".global _scanf_float");
None of these seemed to help. I can sprintf decimal values and strings ok but not floating point.
I am using Psoc Creator 3.2 SP1, ARM GCC 4.8.4 compiler, debug build
Here is my code (initially I was trying to print a float var but set an exlicit value to test)
#include "stdlib.h"
char tbuf[50];
sprintf(tbuf,"%f",(float) 1.35);
When I run this my buffer has values like
0x00, 0x2E, 0x80, 0x00, 0x20, 0x11, 0x00 ...
instead of 0x31, 0x2E, 0x33, 0x35
Any help much appreciated
Regards
David
- Labels:
-
PSoC 5LP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Switch on in project build options linker the Use newlib-nano and the use newlib-nano float formatting options.
Happy coding
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bob,
Both were set to true by default. I then tried both set to false but no difference,
Any other ideas I could try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By the way Bob,
Is there a simulator for PSCO creator? I am remoting into my work machine (which is very slow) to test this at the moment and would be great if I could test just the code on my machine here at home without the hardware.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Last question's answer first:
I have got a PSoC5 Development kit connected to a (fast) PC in my lab. Using TightVNC I am able to check a Project just during the ads-pause in TV from the laptop in my living-room. Quite nice, give it a thought. May be a bit more complicated when not on the same net or via the internet.
When you provide me with a workspace bundle I do not have to type a project myself and I am able to check all your settings.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://airsupplylab.com/index.php/learn/14-psoc5/9-psoc-floating-point-problem-in-psoc-creator-3 nano library enable
http://www.cypress.com/?id=4&rID=87354 nano library enable
I use Teamviewer to service remote machines, has been a very good ap, free
for non - commercial use.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Increasing the heap size in system tab of .cydwr-file to 0x0200 will help.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using these settings worked for me on a PSOC 4, I cannot find
my 5LP board -
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oh how nice it would be to be able to include a float value in a string, I would have throught it pretty stright forward but alas, all is not as it seems afterall.
Yesterday I was working with a new smart display module, I spent most of the day trying to send a string to the display (again, not something I would have thought should have been too challenging in this space age world in which we live).
However, after several HOURS!! and several posts to the support forum, I receive an email advising me the display can fail to program properly if me code ise is 2047 + any multiple of 2048 Bytes. Well guess what, mine was. I changed the font size slightly (which changed the code size0 and now it works again).
I wonder if this time I need to wiggle my left foot, rub my head anti-clockwise and shout "beam me up Scotty" to get the float conversion happening?
For this particular application, the display wants the value sent as an integer that ia 10 x the value to be displayed to give 1 dp readout (ie, 123 = 12.3), could I multiple my float by 10, add 0.5 and convert to int and then use sprintf on my "safe" integer value? Woudl I simply cast the float and get the real part
sprintf(buf,"%l",(int)(myFloat*10+0.5));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You overlooked my last post with the heap size!
Set the heap size to 0x0200
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I set heap size to 0x200, no change.
Where is the documentation for printf showing all these settngs that require changing in order to print a float?
It doesn't seem obvious or logical to me. So far, we are setting the 2 nano settings to true, adding the custom parameter and changing the heap size. Maybe one day it may even be possible to have a button to enable sprintf Float and it makes adjustment to ALL of the parameters needed to implement it.
It appears a lot to do to get a standard C function running. Hopefully this ONLY applies to float? Or does it also apply to other formats in the string?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, it works now, I had to implement all the items at the same time to get it working: I must have had one of these not set when I changed the heap size earlier.
Where did you find info that states all you need to do to print a float is......
Use newlib-nano = true
Use nano-newlib Float Formatting = true
Add custom parameter to linker command line -u_printf_float
Change heap size to 0x200
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks for this. I ran into the same problem, and this solved it for me.
On PSoC Creator 4, the System settings are under the 'Design-wide Resources' and, as Bob Marlowe mentioned, setting the heap size to 0x0200 does the trick.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, nayan.
Fine that such an old thread could help you!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I just came across with the same problem and solved it increasing the heap size to 0x200. How or why is that the solution?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When I had that problem I started to debug my project and found out that a call from the newlib-nano library to malloc() returned a NULL pointer. This usually indicates an out-of-heap error. The caller took some fixup. So I increased the heap zize and was successful.
I have to admit that I am not quite content with the handling of the heap in Creator. I am used from other programming languages that all unused memory gets allocated to the heap. This ensures that without any modifications all memory could be used, even when the project changes.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Finally,
Thanks for taking the time to help me sort this out Bob, much appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You are using Creator 3.2 which is not yet released for full use (early access). The default settings will not allow for using sprintf() and there was a hint here in the forum to generally increase the heap.
The other change "use newlib-nano float formatting" (default: FALSE) does exactly what you had to do manually when setting a linker parameter. When you highlight that item the full description shows the command-line added term.
I admit that it can turn out to be rather difficult when searching for help to sort out the needed settings for the 3.1 and 3.2 versions which differ in some places.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The reason you had crap in buffer, aside from the heap and outher issues,
is when you declared it you did not initialize it to something like " " blanks.
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
(((FYI, fixed)))
Bob and others:
For me,
char msgtemp[512]; // Plenty long, local var of a function
sprintf(msgtemp,"test_pht: Results: T=%g degC, P=%g Pa, H=%g %%RH\r\n", dTemp, dPressure, dHumidity);
prints up to the "T=" then the reset of the line is absent, as of processing failed or inserted a null terminator for the %g. I tried %f and in fact the program hung rather than continuing. Buffer is long enough. Amount printed is only 21 chars anyway
Windows 10. PSoC Creator 3.3. ARM GCC 4.9-2015-q1-update.
I begin by trying "-u_printf_float -u_scanf_float", but then saw Bob's 26 May 2015 post, searched for, and found liner setting "Use newlib-nano Float Formatting", set it True and removed my manual switches. Yes, I see the "-u _printf_float" in the gray window, but not the "-u_scanf_float". Whatever. But the behavior doesn't improve.
Looking for where to set heap size, but can't find it. QUESTION ONE: Where is it? Found it via Bob's earlier post: "Increasing the heap size in system tab of .cydwr-file to 0x0200 will help."
QUESTION TWO: Do I have to do all the other items Orbitcoms suggested? WORKING NOW. I had to do two things, set "Use newlib-nano Float Formatting" to True and set heap sizes to 0x200
QUESTION THREE: Otherwise, just how do I make my sprintf work? Be less impatient.
Thanks,
Helmut
P.S. Strike through font displays in edit window but not in post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"QUESTION TWO: Do I have to do all the other items Orbitcoms suggested? WORKING NOW. I had to do two things, set "Use newlib-nano Float Formatting" to True and set heap sizes to 0x200"
Usually changing only the above two items will allow for printing floats. Other changes became obsolete with Creator 4.0
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok this is driving me crazy.
Using PSoC Creator 4 (4.0.0.432)
Set heap size to 0x200
enabled/True: Use newlib-nano Float Formatting
Using the following simple code:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
CyGlobalIntEnable;
char tbuf[33];
UART_Start();
UART_UartPutString("TEST BEGIN\r\n");
sprintf(tbuf, "%f", (float)18.32);
UART_UartPutString(tbuf);
for(;;) {
}
}
It appears to hang on the sprintf function. I've also tried using printf, it will print up until the float. Am I missing something?!
EDIT: Looks like it is working IF I increase the heap size to 0x400. (OUCH! starting to wonder if it's worth using UART output floating point)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Increasing heap size to 0x400 worked for me too. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I usually survive with following trick
sprintf(tbuf, "%d.%02d", (int)(f_value + 0.005), ((int)(f_value * 100.0 + 0.5))%100);
===========================
#include "project.h"
#include <stdio.h>
#include <stdlib.h>
int main(void) {
char tbuf[33];
float f_value = 18.32 ;
CyGlobalIntEnable;
UART_Start();
UART_UartPutString("TEST BEGIN\r\n");
// sprintf(tbuf, "%f", (float)18.32);
sprintf(tbuf, "%d.%02d", (int)(f_value + 0.005), ((int)(f_value * 100.0 + 0.5))%100);
UART_UartPutString(tbuf);
for(;;) {
}
}
===========================
moto