<?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>NRF_LOG_INFO issues when formatting strings</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/37414/nrf_log_info-issues-when-formatting-strings</link><description>Hi, I&amp;#39;m using nRF52840PDK and SDK 14.2.0. I started from the SAADC example and tried to use NRF_LOG_INFO to print some strings through the UART. I have this: 
 
 
 
 
 And the output in the UART is: 
 
 The first 3 values are ok because the first character</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 13 Aug 2018 11:43:05 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/37414/nrf_log_info-issues-when-formatting-strings" /><item><title>RE: NRF_LOG_INFO issues when formatting strings</title><link>https://devzone.nordicsemi.com/thread/143925?ContentTypeID=1</link><pubDate>Mon, 13 Aug 2018 11:43:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:701e3801-b8b2-451a-8a09-f4424bb71748</guid><dc:creator>Gustavo Velasco-Hern&amp;#225;ndez</dc:creator><description>&lt;p&gt;I found a solution. The problem is present when char arrays are declared within the function, this is what I had when post the question (file nRF5_SDK_14.2.0/examples/peripheral/saadc/main.c):&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{

char test[5] = &amp;quot;test&amp;quot;;
char data[8] = &amp;quot;data&amp;quot;;

...

NRF_LOG_INFO(&amp;quot;%c*%X*%X*%s*%s&amp;quot;, test[0], test[0], test, test, data);

...

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But it was solved declaring the buffers outside the function, it is, at file level:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;char test[5] = &amp;quot;test&amp;quot;;
char data[8] = &amp;quot;data&amp;quot;;

void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
...

NRF_LOG_INFO(&amp;quot;%c*%X*%X*%s*%s&amp;quot;, test[0], test[0], test, test, data);
...

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In this case, the output of the UART is:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: t*74*20000054*test*data&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The difference I see is that the memory location for the variables is in another range (previous: 0x2003FF14, now: 0x20000054).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_LOG_INFO issues when formatting strings</title><link>https://devzone.nordicsemi.com/thread/143913?ContentTypeID=1</link><pubDate>Mon, 13 Aug 2018 11:22:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4825925-201b-4066-b255-d0be703f4208</guid><dc:creator>Gustavo Velasco-Hern&amp;#225;ndez</dc:creator><description>&lt;p&gt;Thanks Erik for your response. Actually when you declare &amp;quot;test&amp;quot; it includes the null terminator &amp;#39;\0&amp;#39;. For this reason the array should be initiated for 5 elements. Also, sprintf includes the null terminator when storing a formatted string in an array. You must be sure that the array is long enough to store the formatted output. I learnt that the hard way: A critical bug found in production.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF_LOG_INFO issues when formatting strings</title><link>https://devzone.nordicsemi.com/thread/143895?ContentTypeID=1</link><pubDate>Mon, 13 Aug 2018 09:45:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4afdd7a-5266-42fa-a0b5-ddcedb7e120e</guid><dc:creator>eriknorth</dc:creator><description>&lt;p&gt;Hi Gustavo,&lt;br /&gt;&lt;br /&gt;Not sure if this will fix it but in general when using %s, strings (char arrays) should be null terminated with &amp;quot;\0&amp;quot;.&lt;/p&gt;
&lt;p&gt;/Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>