<?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>NRF51 - Hardware UART - hints needed</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/22054/nrf51---hardware-uart---hints-needed</link><description>Hi 
 I&amp;#39;m using the NRF51422 with hardware UART.
Brief outline of the configuration:
115200 Baud, 8-N-1, no HW flowcontrol
SoftDevice S130 V2.0.1
lib: app uart fifo 
 The main problem seems to be the SoC trying to send over UART while BLE timeslot</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 18 May 2017 12:57:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/22054/nrf51---hardware-uart---hints-needed" /><item><title>RE: NRF51 - Hardware UART - hints needed</title><link>https://devzone.nordicsemi.com/thread/86569?ContentTypeID=1</link><pubDate>Thu, 18 May 2017 12:57:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:20717635-3728-4dad-9fd0-c8f9fcd18997</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Martin&lt;/p&gt;
&lt;p&gt;The problem with the attached code is that you will essentially lock up the system when the UART is full, since you keep trying to add more data to the UART driver.&lt;/p&gt;
&lt;p&gt;I would suggest a more asynchronous approach where you push data to the UART in a non blocking manner.&lt;/p&gt;
&lt;p&gt;For instance, you could do something like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;static char buffer[1024];
static uint32_t buffer_pos = 0, buffer_length = 0;

static void uart_put_string(const char *str, ...)
{
    va_list args;
    va_start(args, str);
    vsprintf((char*)buffer, (char*)str, args);
    va_end(args);

    buffer_length = strlen(buffer);
    buffer_pos = 0;
}


// while loop in main()
while(1)
{
    ..
    
    while(buffer_length != 0 &amp;amp;&amp;amp; app_uart_put(buffer[buffer_pos++]) == NRF_SUCCESS)
    {
        if(buffer_pos &amp;gt;= buffer_length) 
        { 
            buffer_length = 0;
        }
    }
    
    power_down();

}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then you will be able to go to sleep or do other things when the UART is full, and as soon as bytes are cleared up from the UART the chip should be woken up from sleep and you can put more data in.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>