<?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>Libuarte and GPS</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/76159/libuarte-and-gps</link><description>Hello everyone, I ran into an issue where I just can&amp;#39;t get my head around. I followed the Libuarte example, and I thought I modified it &amp;quot;correctly&amp;quot; to fit my application where I am connected to a GPS device emitting a number of messages every second.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 22 Jul 2021 13:08:13 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/76159/libuarte-and-gps" /><item><title>RE: Libuarte and GPS</title><link>https://devzone.nordicsemi.com/thread/321365?ContentTypeID=1</link><pubDate>Thu, 22 Jul 2021 13:08:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a4ef67d-2c8f-4766-a260-5905dc9068fc</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;The only thing I can think of is to use &lt;a href="https://www.cplusplus.com/reference/cstring/strchr/"&gt;strchr()&lt;/a&gt;&amp;nbsp;to look for the first instance of &amp;#39;\n&amp;#39; character, and copy the string from start og buffer until the pointer where the &amp;#39;\n&amp;#39; character was found using memcpy().&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte and GPS</title><link>https://devzone.nordicsemi.com/thread/314505?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 13:38:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed675546-2d11-444b-8976-61c9d83fe85d</guid><dc:creator>dariusBotha</dc:creator><description>&lt;p&gt;Thank you, Jorgen, that worked:)&lt;br /&gt;&lt;br /&gt;Is there a way to handle the data up to the &amp;quot;\n&amp;quot; character? so that it keeps filling the uart0_array[] with the data from the GPS until the &amp;quot;/n&amp;quot; character is reached and then break or copy the whole string to another buffer so I can process it?&lt;br /&gt;&lt;br /&gt;Because I tried the following (sprintf() and memcpy()) and get the string up to &amp;quot;/n&amp;quot; but after3-4 seconds I get a HardFault_Handler: error.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 5);


typedef struct {
    uint8_t * p_data;
    uint32_t length;
} buffer_t;
//NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);
NRF_QUEUE_DEF(buffer_t, m_buf_queue, 10, NRF_QUEUE_MODE_NO_OVERFLOW);


uint8_t uart0_array[500]; //buffer to copy uart data to


void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    
    static uint8_t data_array[100];
    static uint16_t index = 0;
    
    switch(p_evt-&amp;gt;type)
    { 
      case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
      {
        strcat(data_array,p_evt-&amp;gt;data.rxtx.p_data);
        index++;

      if ((data_array[index] == &amp;#39;\n&amp;#39;) ||
          (data_array[index - 1] == &amp;#39;\r&amp;#39;))
      {

          //memcpy(uart0_array,data_array,sizeof(data_array));
          sprintf(uart0_array, &amp;quot;%s&amp;quot;, data_array);
          nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
            


          index = 0;
      }


          //sprintf(byte,&amp;quot;%s&amp;quot;,p_evt-&amp;gt;data.rxtx.p_data);
          //strcat(uart0_array,p_evt-&amp;gt;data.rxtx.p_data);
          
          //nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
      }break;
      case NRF_LIBUARTE_ASYNC_EVT_ERROR:
      {
          //printf(&amp;quot;\nUART ERROR: %d&amp;quot;, p_evt-&amp;gt;data.errorsrc);
      }break;
      case NRF_LIBUARTE_ASYNC_EVT_OVERRUN_ERROR:
      {
          //printf(&amp;quot;\nUART OVERRUN ERROR&amp;quot;);
      }break;
      
    }
}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Thanks for your help so far.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte and GPS</title><link>https://devzone.nordicsemi.com/thread/314498?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 13:28:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c892edd4-33a0-4419-bc5e-a4d421537044</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Why do you send the data one and one byte at a time?&lt;/p&gt;
&lt;p&gt;You should be able to write the full TX buffer like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//Function to send via UART
void send_UART(char *sdata, int len)
{
    ret_code_t ret;
    ret = nrf_libuarte_async_tx(&amp;amp;libuarte, sdata, len);
    
    APP_ERROR_CHECK(ret);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Note that you can only start a single transfer at a time, if there is already an ongoing transfer, you will get the&amp;nbsp;&lt;span&gt;NRF_ERROR_BUSY return code.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can use a do-while to do a blocking wait for the previous transfer to finish:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//Function to send via UART
void send_UART(char *sdata, int len)
{
    ret_code_t ret;
    do {
        ret = nrf_libuarte_async_tx(&amp;amp;libuarte, sdata, len);
    while (ret == NRF_ERROR_BUSY);
    
    APP_ERROR_CHECK(ret);
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Not sure where you get the NRF_ERROR_NO_MEM return code from, this does not seem to be a valid return code from the&amp;nbsp;nrf_libuarte_drv_tx() function.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To look for a substring in a string, you can use &lt;a href="https://www.tutorialspoint.com/c_standard_library/c_function_strstr.htm"&gt;strstr() function&lt;/a&gt;. Note that the string function may take long time to process, you should consider doing this outside of the interrupt/event handler, to allow other interrupts to be handled while processing strings.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>