<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/54413/sprintf-needs-to-be-reset-every-128-characters</link><description>After having a problems with a function using vsnprintf, I finally boiled it down to sprintf. Every 128 characters that has been run through sprintf, it truncates the output. 
 
 Steps I used to reproduce it: 
 * I took the simplest example I could find</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 18 Nov 2019 14:31:38 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/54413/sprintf-needs-to-be-reset-every-128-characters" /><item><title>RE: sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/thread/220624?ContentTypeID=1</link><pubDate>Mon, 18 Nov 2019 14:31:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34324102-d60b-41d9-bd6d-2670f9f669ea</guid><dc:creator>humming</dc:creator><description>&lt;p&gt;Yeah, did some more testing today and the problem is with the logging module, as previously suggested.&lt;/p&gt;
&lt;p&gt;The problem seems to be with nrf_log_push, the following test does not print everything:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;for(...) {
   NRF_LOG_INFO(&amp;quot;%s&amp;quot;, nrf_log_push(&amp;quot;abcdefhijk&amp;quot;));
}
   &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Every 128 characters or so, the output is dropped...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/thread/220359?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2019 15:03:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8738db55-29fb-4aa0-87df-ccc507af0909</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;What does your &amp;quot;buf&amp;quot; variable look like? I would need to know more about how you call this code. Maybe this buffer is full? But then I don&amp;#39;t understand why it will print it later. But I still think you should remove the nrf_delay_ms(500).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/thread/220346?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2019 14:39:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:03f210f3-c156-4dea-8e01-ab5e1bc7c840</guid><dc:creator>humming</dc:creator><description>&lt;p&gt;Thanks for your answers. The reason I don&amp;#39;t think this is related to the logging is&lt;/p&gt;
&lt;p&gt;a) It still prints the &amp;#39;(20)&amp;#39; text, even though the actual string is chopped off. This could be an artifact of nrf_log_push, so it&amp;#39;s not conclusive only a sprintf problem&lt;/p&gt;
&lt;p&gt;b) In my real code, I sprint (actually vsnprintf) some text, send that text over a serial line, and sometimes that text shows up slightly shorter than expected. This could be a problem with my code, so again, not conclusive.&lt;/p&gt;
&lt;p&gt;When I get back to my nRF toolchain, I will try your suggestions to see if it&amp;#39;s a problem with the logging module.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/thread/220336?ContentTypeID=1</link><pubDate>Fri, 15 Nov 2019 14:15:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a40af473-b273-4f86-ae84-169874a90440</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;This believe this actually a limitation in the logging module. However, I see that you try to print this quite &amp;quot;slow&amp;quot;, by delaying 500ms. The issue is that it looks like you base this delay on nrf_delay_ms(500), which will halt the processor for 500ms. This means that it doesn&amp;#39;t have time to process the logging module. Try to use the app_timer to trigger the NRF logs instead. You can look in the ble_app_hrs example how to use the app_timer.&lt;/p&gt;
&lt;p&gt;Hint: you need to use these functions: app_timer_init(), app_timer_create() and app_timer_start().&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: sprintf needs to be reset every 128 characters?</title><link>https://devzone.nordicsemi.com/thread/220171?ContentTypeID=1</link><pubDate>Thu, 14 Nov 2019 20:20:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6058788a-994e-4283-9bd5-924f0eeb5a36</guid><dc:creator>TylerD</dc:creator><description>&lt;p&gt;Sounds odd to me that the sprintf would be the problem&amp;nbsp;in this case. Your code is printing the same constant 20-byte string in each iteration. What if you modify it so that you call sprintf() only once, outside the main loop. This is to initialize the global buf array with the given data &amp;quot;123...&amp;quot;. Then&amp;nbsp;run the same test, i.e. calling NRF_LOG_INFO repeatedly (but not calling sprintf() for each iteration).&lt;/p&gt;
&lt;p&gt;If the test still behaves the same, then the problem must be in the NRF logging system and not in sprintf.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>