This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Libuarte send and receive String

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!



  • 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.
    Is there any callback check which I can add in this function to wait until sending data?

    Thanks

    bool send_command(char cmd[],int size_cmd)
    {
    
        ret_code_t err_code;
        printf("Sending : ");
        printf(cmd);
        printf("\n");
    
        memset(command, 0, sizeof(command));
        
        for (int i=0;i<size_cmd;i++)
        {
          command[i]=cmd[i];   
        }
    
        err_code = nrf_libuarte_async_tx(&libuarte, command,sizeof(command) );
        APP_ERROR_CHECK(err_code);
        while(err_code==NRF_ERROR_BUSY); // Is this correct??
    
    }
    


        send_command("Muqarrab",sizeof("Muqarrab"));
        nrf_delay_ms(1000);
        send_command("Rahman",sizeof("Rahman"));
    

  • Looking at: https://sites.google.com/site/vmacgpsgsm/understanding-at-commands

    I can find that "Responses start and end with <CR><LF>."

    So I assume you could check if you receive <CR><LF>? 

    CR= carriage return
    LF= line feed

    See ascii table for hex values: https://www.asciitable.com/ 

  • I have read this post.


    I also don'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?


            case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
    
                ret = nrf_libuarte_async_tx(p_libuarte,p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                if (ret == NRF_ERROR_BUSY)
                {
                    buffer_t buf = {
                        .p_data = p_evt->data.rxtx.p_data,
                        .length = p_evt->data.rxtx.length,
                    };
    
                    ret = nrf_queue_push(&m_buf_queue, &buf);
                    APP_ERROR_CHECK(ret);
                }
                else
                {
                    APP_ERROR_CHECK(ret);
                }
                //while(ret==NRF_ERROR_BUSY)
                //{           
                //printf("Data : %s\n",p_evt->data.rxtx.p_data);
                //}
    
                printf("Data1 : %s\n",p_evt->data.rxtx.p_data);
    
                if(p_evt->data.rxtx.p_data==0x0D  || p_evt->data.rxtx.p_data=='\r')
                  printf("Completed\n");
    
                bsp_board_led_invert(1);
                m_loopback_phase = true;
                printf("Rx Called\n");
                break;
            case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
                if (m_loopback_phase)
                {
                    nrf_libuarte_async_rx_free(p_libuarte, p_evt->data.rxtx.p_data, p_evt->data.rxtx.length);
                    if (!nrf_queue_is_empty(&m_buf_queue))
                    {
                        buffer_t buf;
                        ret = nrf_queue_pop(&m_buf_queue, &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("Tx Called\n");
                break;
    

Related