- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The following works as expected:
iBufUsed += sprintf(tx_buff + iBufUsed, "%u,ACK,", *(volatile uint8 *) &iMyUnitID);
iBufUsed += sprintf(tx_buff + iBufUsed, "%s,", sSequenceID);
But this is broken:
iBufUsed += sprintf(tx_buff + iBufUsed, "%u,ACK,%s,", *(volatile uint8 *) &iMyUnitID, sSequenceID);
In the broken example the final string has garbage where the string pointed to by sSequenceID should be. It's going to be hard to remember which things don't work as they should.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Is it possible to share more info in this forum. This can happen if the output string length of sprintf exceed the destination string length. Can you check this.
Thanks
JOBIN GT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Is it possible to share more info in this forum. This can happen if the output string length of sprintf exceed the destination string length. Can you check this.
Thanks
JOBIN GT
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We were about 20 characters into a 1024 byte buffer. Clearly the buffer is amply sized because doing it in two function calls works.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
More or less a guess: Increase the heap size to 0x0200 bytes.
When nothing helps, consider to post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can tell you from personal experience heap size is the problem. Increase as needed until sprintf behaves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Other than that bundle appearing to contain all our IP and not just the project settings that sounds like a great idea.
I will attempt the heap size fix when I next touch this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is probably the case that heap size is the problem as others have said. You can increase this in the System tab of the cydwr window. Having said that, I'm not sure what you mean by the variable containing garbage. If you are printing the variables out in a terminal window, be sure your UART parameters agree with your term parameters. Also be sure your code starts the UART and its interrupt: UART_1_Start(); and isr_1_Start(); for example. I once forgot to put in these lines and I got garbage on the screen.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
By garbage I mean something other than the contents of my string. if myUID is 8 and sSequence is "ABCD" the first block will give a string of:
"8,ACK,ABCD"
But the second block will give:
"8,ACK,<a few unprintable characters, variable each time it's run>"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Assuming you are using UART and a terminal program to read the output, be sure to connect P0[1] to TX, both by physical wire on the development board (assuming you are using one) and in your cydwr.
If you were using the GNU compiler I would say to check build settings and go to Linker > General and make newlib-nano and newlib-nano Float Format both True. From your other posts, I think you might be using the Keil compiler. I'm not sure what the equivalent settings there are.