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

How to send sensor data using AT commands to a device using Uart in segger embedded studio

Hi, I am new to NRF and segger embedded studio.

So I want to send temperature sensor data connected with nrf52840 DK to the Murata1_SC  device using UART.

The data will be sent using AT Commands.

So how to send AT Commands in Segger embedded studio.

Thank you for the help in advance.

  • i have made this code

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf.h"
    #include "bsp.h"
    #include "nrf_uart.h"
    #include <string.h>
    
    
    #define UART_TX_BUF_SIZE 256                         /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 256                         /**< UART RX buffer size. */
    
    /* When UART is used for communication with the host do not use flow control.*/
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    
    void uart_error_handle(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
        else if (p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    }
    
    void uart_putstring(const uint8_t *str) 
    {
           uint32_t err_code;
    
           while( str ) 
           {
                err_code = app_uart_put(( uint8_t*) str++ );
    
                APP_ERROR_CHECK(err_code);
           }
    }
     
    char* uart_getstring(char* rx_data) 
    {
           uint32_t err_code;
           err_code = app_uart_get(rx_data);
           return rx_data;
    }
    
    
    /**
     * @brief Function for main application entry.
     */
    int main(void)
    {
        uint32_t err_code;
    
        const app_uart_comm_params_t comm_params =
          {
              RX_PIN_NUMBER,
              TX_PIN_NUMBER,
              RTS_PIN_NUMBER,
              CTS_PIN_NUMBER,
              UART_HWFC,
              false,
    
              NRF_UART_BAUDRATE_115200
    
          };
    
        APP_UART_FIFO_INIT(&comm_params,
                             UART_RX_BUF_SIZE,
                             UART_TX_BUF_SIZE,
                             uart_error_handle,
                             APP_IRQ_PRIORITY_LOWEST,
                             err_code);
    
        APP_ERROR_CHECK(err_code);
    
     //Commands to send data to murata_1sc
    
    //    uart_putstring((const char*)"AT\r\n"); //variaible iterate - array iterate
      //   char* output;
        //output = uart_getstring(output);
         //printf("Hello PC from Nordic Device!!!\r\n");
    
    
     
     //array of commands declare
     char arrr[12][150]  = { " AT\r\n ",
                             " ",
                             " ",
                             " AT%CERTCMD=\"DIR\"%CERTCMD:murata_1sc_cert.pem,cert.pem,privatekey.pem,murata_private.key\r\n ",
                             " AT%CERTCFG=\"ADD\",1,,\"~\",\"murata_1sc_cert.pem\",\"murata_1sc_private.key\"\r\n ",
                             " AT%AWSIOTCFG=\"PROTOCOL\",1200,0\r\n ",
                             " AT%AWSIOTEV=\"ALL\",1\r\n ",
                             " AT%AWSIOTCMD=\"CONNECT\"\r\n ",
                             " AT%AWSIOTCMD=\"PUBLISH\",\"tracker/location\",\"{\"message\":\"Hello from Murata 1SC\"}\"\r\n ",
                             " AT%AWSIOTCMD=\"SUBSCRIBE\",\"tracker/location\"\r\n ",
                             " AT%AWSIOTCMD=\"SUBSCRIBE\",\"$aws/things/murata_1sc/shadow/update\"\r\n ",
                             " AT%AWSIOTCMD=\"PUBLISH\",\"$aws/things/murata_1sc/shadow/update\",\" { \"state\": {\"desired\": { \"color\": \"yellow\" } } }\"\r\n "
                           };
     //char outttt[12][100];    
     //loopstart
    
     int i = 0;
     for(i=0;i<13;i++)
     {
        uart_putstring((const char*)arrr[i]); //variaible iterate - array iterate
        char* output;
       
          while( !timeout && !reply_complete )
            {
              // wait for timeout or reply complete
              output = uart_getstring(output);
              if (output == "ERROR")
              {
               printf("ERROR");
              }
    }
    
    //print
    //loop end
    }
    }
    

    I am still confused about time out

  • What, exactly, is your confusion?

    Another on ignoring responses when sending commands - only this morning:

    www.avrfreaks.net/.../3144271

  • I have sent AT every commands to the module using TeraTerm software, so some commands took almost 3 to 4 seconds to respond. 

    So 4 seconds timout will be fine for this?

  • This should really be documented by the module manufacturer - you need to contact them for details.

    Remember that you have to consider worst case conditions.

    But if your application is OK to wait a whole 4s for a command which should complete "immediately" - then that's fine.

    It's your application - only you can answer that.

  • Yes, I am just testing the timeout with different commands.

    Could me please tell me, how can I make other pins as UART

    Because P0.05 to P0.08 are Hardware UART pins

      how can i make other GPIO pins work as UART like software serial in Arduino 

Related