<?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 send and receive String</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/78937/libuarte-send-and-receive-string</link><description>Hi, I am trying to send and receive strings using examples\peripheral\libuarte. I am trying to send a string like this but not receiving it on another board. Also how can I check coming data? Means how can I perform some action based on coming data? Thanks</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 26 Aug 2021 12:06:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/78937/libuarte-send-and-receive-string" /><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326772?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 12:06:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f381e5c0-b85f-4284-9f0f-b28867287196</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;I have read&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/68986/recieving-data-with-libuarte"&gt;this post&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;I also don&amp;#39;t want to save the data in the queue and resend on tx. I want to send AT commands and want to check the response immediately. I am not getting how to do this. Can you please help?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:

            ret = nrf_libuarte_async_tx(p_libuarte,p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
            if (ret == NRF_ERROR_BUSY)
            {
                buffer_t buf = {
                    .p_data = p_evt-&amp;gt;data.rxtx.p_data,
                    .length = p_evt-&amp;gt;data.rxtx.length,
                };

                ret = nrf_queue_push(&amp;amp;m_buf_queue, &amp;amp;buf);
                APP_ERROR_CHECK(ret);
            }
            else
            {
                APP_ERROR_CHECK(ret);
            }
            //while(ret==NRF_ERROR_BUSY)
            //{           
            //printf(&amp;quot;Data : %s\n&amp;quot;,p_evt-&amp;gt;data.rxtx.p_data);
            //}

            printf(&amp;quot;Data1 : %s\n&amp;quot;,p_evt-&amp;gt;data.rxtx.p_data);

            if(p_evt-&amp;gt;data.rxtx.p_data==0x0D  || p_evt-&amp;gt;data.rxtx.p_data==&amp;#39;\r&amp;#39;)
              printf(&amp;quot;Completed\n&amp;quot;);

            bsp_board_led_invert(1);
            m_loopback_phase = true;
            printf(&amp;quot;Rx Called\n&amp;quot;);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_loopback_phase)
            {
                nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
                if (!nrf_queue_is_empty(&amp;amp;m_buf_queue))
                {
                    buffer_t buf;
                    ret = nrf_queue_pop(&amp;amp;m_buf_queue, &amp;amp;buf);
                    APP_ERROR_CHECK(ret);
                    UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                }
            }
            bsp_board_led_invert(2);
            printf(&amp;quot;Tx Called\n&amp;quot;);
            break;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326740?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 11:11:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:be92f99a-4613-45af-b466-7227adc51206</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Looking at:&amp;nbsp;&lt;a href="https://sites.google.com/site/vmacgpsgsm/understanding-at-commands"&gt;https://sites.google.com/site/vmacgpsgsm/understanding-at-commands&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I can find that &amp;quot;&lt;span&gt;Responses start and end with &amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;.&lt;/span&gt;&amp;quot;&lt;/p&gt;
&lt;p&gt;So I assume you could check if you receive &amp;lt;CR&amp;gt;&amp;lt;LF&amp;gt;?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;CR= carriage return&lt;br /&gt;LF= line feed&lt;/p&gt;
&lt;p&gt;See ascii table for hex values:&amp;nbsp;&lt;a href="https://www.asciitable.com/"&gt;https://www.asciitable.com/&lt;/a&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326738?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 11:09:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c060b21f-7065-46fb-9e71-b8e9c77e49a5</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;I have made this function to send string(successfully received on another controller) but I have to put a 1-sec delay after one command.&lt;br /&gt;Is there any callback check which I can add in this function to wait until sending data?&lt;/p&gt;
&lt;p&gt;Thanks&lt;br /&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;bool send_command(char cmd[],int size_cmd)
{

    ret_code_t err_code;
    printf(&amp;quot;Sending : &amp;quot;);
    printf(cmd);
    printf(&amp;quot;\n&amp;quot;);

    memset(command, 0, sizeof(command));
    
    for (int i=0;i&amp;lt;size_cmd;i++)
    {
      command[i]=cmd[i];   
    }

    err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, command,sizeof(command) );
    APP_ERROR_CHECK(err_code);
    while(err_code==NRF_ERROR_BUSY); // Is this correct??

}
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;    send_command(&amp;quot;Muqarrab&amp;quot;,sizeof(&amp;quot;Muqarrab&amp;quot;));
    nrf_delay_ms(1000);
    send_command(&amp;quot;Rahman&amp;quot;,sizeof(&amp;quot;Rahman&amp;quot;));
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326699?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 09:56:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:29b99da7-2052-48a1-b1b9-d6faa2c9e5bf</guid><dc:creator>Muqarrab</dc:creator><description>[quote userid="2111" url="~/f/nordic-q-a/78937/libuarte-send-and-receive-string/326698#326698"]You might need to assemble the received data, so if you receive 1byte, you may need to copy it to a variable until the entire string is received.[/quote]
&lt;p&gt;How can I check that complete data is received?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326698?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 09:55:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed278d26-1f8e-4dbd-93a6-17fedb856e32</guid><dc:creator>Kenneth</dc:creator><description>[quote user="muqarrab_rahman"]Is there any other way as I have to send many AT commands?[/quote]
&lt;p&gt;You don&amp;#39;t need many variables, instead&amp;nbsp;update the&amp;nbsp;command data once a transfer is finished.&lt;/p&gt;
[quote user="muqarrab_rahman"]I am trying to get complete data but receive like one byte. How can receive complete string?[/quote]
&lt;p&gt;You might need to assemble the received data, so if you receive 1byte, you may need to copy it to a variable until the entire string is received.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Kenneth&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326694?ContentTypeID=1</link><pubDate>Thu, 26 Aug 2021 09:47:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07ac879f-a851-4a24-b12e-b376f8a99577</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/kenneth"&gt;Kenneth&lt;/a&gt;&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/78937/libuarte-send-and-receive-string/326536#326536"]Make sure that the string you want to send is defined as a variable, e.g. static uint8_t command[][/quote]
&lt;p&gt;Is there any other way as I have to send many AT commands?&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
[quote userid="2111" url="~/f/nordic-q-a/78937/libuarte-send-and-receive-string/326536#326536"]Also, I suggest that you check the return code from&amp;nbsp;&lt;span&gt;nrf_libuarte_async_tx(), if it&amp;#39;s NRF_ERROR_BUSY you should retry until NRF_SUCCESS.&lt;/span&gt;[/quote]
&lt;p&gt;I am trying to get complete data but receive like one byte. How can receive complete string?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            ret = nrf_libuarte_async_tx(p_libuarte,p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
            //if (ret == NRF_ERROR_BUSY)
            //{
            //    buffer_t buf = {
            //        .p_data = p_evt-&amp;gt;data.rxtx.p_data,
            //        .length = p_evt-&amp;gt;data.rxtx.length,
            //    };

            //    ret = nrf_queue_push(&amp;amp;m_buf_queue, &amp;amp;buf);
            //    APP_ERROR_CHECK(ret);
            //}
            //else
            //{
            //    APP_ERROR_CHECK(ret);
            //}
            while(ret==NRF_ERROR_BUSY)
            {           
            printf(&amp;quot;Data : %s\n&amp;quot;,p_evt-&amp;gt;data.rxtx.p_data);
            }
            ;

            printf(&amp;quot;Data1 : %s\n&amp;quot;,p_evt-&amp;gt;data.rxtx.p_data);

            if(p_evt-&amp;gt;data.rxtx.p_data==&amp;quot;Hello&amp;quot;)
              printf(&amp;quot;Data Matched&amp;quot;);

            bsp_board_led_invert(1);
            m_loopback_phase = true;
            printf(&amp;quot;Rx Called\n&amp;quot;);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_loopback_phase)
            {
                nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
                if (!nrf_queue_is_empty(&amp;amp;m_buf_queue))
                {
                    buffer_t buf;
                    ret = nrf_queue_pop(&amp;amp;m_buf_queue, &amp;amp;buf);
                    APP_ERROR_CHECK(ret);
                    UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                }
            }
            bsp_board_led_invert(2);
            printf(&amp;quot;Tx Called\n&amp;quot;);
            break;
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326536?ContentTypeID=1</link><pubDate>Wed, 25 Aug 2021 12:02:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fab296d5-817b-41b6-b885-cfe3d067bc4b</guid><dc:creator>Kenneth</dc:creator><description>&lt;p&gt;Make sure that the string you want to send is defined as a variable, e.g. static uint8_t command[] should work,&amp;nbsp;since this will cause the string to exist in RAM. You should not point to a string that is placed in FLASH, which is the case in the picture in your original case desription.&lt;/p&gt;
&lt;p&gt;Also, I suggest that you check the return code from&amp;nbsp;&lt;span&gt;nrf_libuarte_async_tx(), if it&amp;#39;s NRF_ERROR_BUSY you should retry until NRF_SUCCESS.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I do believe the&amp;nbsp;\nRF5_SDK_17.0.2_d674dde\examples\peripheral\libuarte example show both TX and RX. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If it still fails you need to connect a logic analyzer to measure the RX and TX pins to see what is received and sent during an transaction.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kenneth&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Libuarte send and receive String</title><link>https://devzone.nordicsemi.com/thread/326496?ContentTypeID=1</link><pubDate>Wed, 25 Aug 2021 09:58:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cec0fc18-557e-4ec1-be37-a2ed9dc22e37</guid><dc:creator>Muqarrab</dc:creator><description>&lt;p&gt;Also, I have sent one command and getting data in a loop like this.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
 * @defgroup libuarte_example_main main.c
 * @{
 * @ingroup libuarte_example
 * @brief Libuarte Example Application main file.
 *
 * This file contains the source code for a sample application using libuarte.
 *
 */

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;nrf_libuarte_async.h&amp;quot;
#include &amp;quot;nrf_drv_clock.h&amp;quot;
#include &amp;lt;bsp.h&amp;gt;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;
#include &amp;quot;nrf_queue.h&amp;quot;

NRF_LIBUARTE_ASYNC_DEFINE(libuarte, 0, 0, 0, NRF_LIBUARTE_PERIPHERAL_NOT_USED, 255, 3);

static uint8_t text[] = &amp;quot;UART example started5.\r\nLoopback:\r\n&amp;quot;;
static uint8_t text_size = sizeof(text);
static volatile bool m_loopback_phase;

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);

void uart_event_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    ret_code_t ret;

    switch (p_evt-&amp;gt;type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            bsp_board_led_invert(0);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            ret = nrf_libuarte_async_tx(p_libuarte,p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
            if (ret == NRF_ERROR_BUSY)
            {
                buffer_t buf = {
                    .p_data = p_evt-&amp;gt;data.rxtx.p_data,
                    .length = p_evt-&amp;gt;data.rxtx.length,
                };

                ret = nrf_queue_push(&amp;amp;m_buf_queue, &amp;amp;buf);
                APP_ERROR_CHECK(ret);
            }
            else
            {
                APP_ERROR_CHECK(ret);
            }
            bsp_board_led_invert(1);
            m_loopback_phase = true;
            printf(&amp;quot;Rx Done&amp;quot;);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_loopback_phase)
            {
                nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
                if (!nrf_queue_is_empty(&amp;amp;m_buf_queue))
                {
                    buffer_t buf;
                    ret = nrf_queue_pop(&amp;amp;m_buf_queue, &amp;amp;buf);
                    APP_ERROR_CHECK(ret);
                    UNUSED_RETURN_VALUE(nrf_libuarte_async_tx(p_libuarte, buf.p_data, buf.length));
                }
            }
            bsp_board_led_invert(2);
            printf(&amp;quot;Tx Done&amp;quot;);
            break;
        default:
            break;
    }
}

/**
 * @brief Function for main application entry.
 */




int main(void)
{
    bsp_board_init(BSP_INIT_LEDS);
    
    ret_code_t ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
  
    nrf_drv_clock_lfclk_request(NULL);

    ret_code_t err_code = NRF_LOG_INIT(app_timer_cnt_get);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = TX_PIN_NUMBER,
            .rx_pin     = RX_PIN_NUMBER,
            .baudrate   = NRF_UARTE_BAUDRATE_9600,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 100,
            .int_prio   = APP_IRQ_PRIORITY_LOW
    };

    err_code = nrf_libuarte_async_init(&amp;amp;libuarte, &amp;amp;nrf_libuarte_async_config, uart_event_handler, (void *)&amp;amp;libuarte);

    APP_ERROR_CHECK(err_code);

    nrf_libuarte_async_enable(&amp;amp;libuarte);

    //err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, text, sizeof(text));
    static uint8_t command[]=&amp;quot;AT+GSN\r\n&amp;quot;;
    err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, command,sizeof(command) );
    APP_ERROR_CHECK(err_code);


    while (true)
    {
        NRF_LOG_FLUSH();
    }
}


/** @} */
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1629885500568v1.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>