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.

  • Please tell me where in segger I can check the output of the command

  • Here is my 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 "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    #define ENABLE_SWO
    
    //#define DTM_RX_PIN NRF_GPIO_PIN_MAP(0, 11) // p0.11
    //#define DTM_TX_PIN NRF_GPIO_PIN_MAP(1, 8) // p1.08
    
    
    #define UART_TX_BUFF_SIZE 256
    #define UART_RX_BUFF_SIZE 256
    
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    
    
    void uart_err_handle(app_uart_evt_type_t * p)
    {
      
    
    }
    
    
    ///**@brief Function for UART initialization.
    // */
    //static void uart_init(void)
    //{   
    //    uint32_t err_code;
    //    const app_uart_comm_params_t comm_params =
    //      {
    //          DTM_RX_PIN,
    //          DTM_TX_PIN,
    //          RTS_PIN_NUMBER,
    //          CTS_PIN_NUMBER,
    //          APP_UART_FLOW_CONTROL_DISABLED,
    //          false,
    //          NRF_UART_BAUDRATE_115200
    //          //DTM_BITRATE
    //      };
    
    int main(void)
    {
    
      APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
      NRF_LOG_DEFAULT_BACKENDS_INIT();
      
      NRF_LOG_INFO("AT/n");
      uint32_t err_code;
    
      bsp_board_init(BSP_INIT_LEDS);
      
      const app_uart_comm_params_t com_params = 
       {
        RX_PIN_NUMBER, 
        TX_PIN_NUMBER, 
        RTS_PIN_NUMBER,
        CTS_PIN_NUMBER,
        UART_HWFC,     //APP_UART_FLOW_CONTROL_DISABLED
        false,
        NRF_UART_BAUDRATE_115200
        };
    
    
      APP_UART_FIFO_INIT(&com_params, 
                          UART_RX_BUFF_SIZE, 
                          UART_TX_BUFF_SIZE, 
                          uart_err_handle, 
                          APP_IRQ_PRIORITY_LOWEST, 
                          err_code);
    
      APP_ERROR_CHECK(err_code);
      NRF_LOG_INFO("AT/n");
      nrf_delay_ms(1000);
      //printf("Hello PC from Nordic");
      
      while(true)
      {
        uint8_t cr;
        NRF_LOG_INFO("AT/n");
        printf("\r\nAT\r\n");
        nrf_delay_ms(2000);
        while(app_uart_get(&cr) != NRF_SUCCESS);//wait here for the character from pc
        if(cr == 'OK')
        {
          bsp_board_leds_on();
          NRF_LOG_INFO("OK");
          
        }
        if(cr == 'ERROR')
        {
          bsp_board_leds_off();
          NRF_LOG_INFO("ERROR");
        }
      }
    }
    
    
    
    

    Please correct me where i am wrong?

Related