UART + RTT LOG Setup

Hello, 

I have my own custom board with nRF52832 and a NB-iot module SIM7080G that interfaces via UART. 

I can easily program the device through SWD using J-Link. I am even able to print things using RTT.

I have a button and made a simple program to print a thing once the button is pressed:

 

while (true)
    { 
        if(nrf_gpio_pin_read(button) == 1){
          NRF_LOG_INFO("Button pressed!\r\n");
          NRF_LOG_FLUSH();
          nrf_gpio_pin_clear(led1);
          nrf_delay_ms(1200);
        }else{
          nrf_gpio_pin_set(led1);
        }
    }

The thing is I want to communicate via UART (TX pin P0.04, RX pin P0.03) to the SIM7080G module at the same time I print things using RTT Log. This module is AT COMMAND so it would be really practical to write on the RTT in the computer and send this information to TX pin in the UART. After that, listen to the RX PIN (answer from the module) and print it again to the RTT Log so I can see it in the computer.

I tried setting up the UART in the corresponding pins like that (attached the full code):

#include <stdio.h>
#include "boards.h"
#include "app_util_platform.h"
#include "app_error.h"
#include "nrf_drv_twi.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "nrf_drv_uart.h"

#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"

static nrf_drv_uart_t m_uart = NRF_DRV_UART_INSTANCE(0);

static void uart_event_handler(nrf_drv_uart_event_t * p_event, void* p_context)
{
    if (p_event->type == NRF_DRV_UART_EVT_RX_DONE)
    {
        if (p_event->data.rxtx.bytes)
        {
            // Event to notify that data has been received
        }
    }
    else if (p_event->type == NRF_DRV_UART_EVT_ERROR)
    {
        // Event to notify that an error has occured in the UART peripheral
    }
    else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE)
    {
       // Event to notify that the last byte from FIFO has been transmitted

    }
}

static void uart_init()
{
    nrf_drv_uart_config_t uart_config = NRF_DRV_UART_DEFAULT_CONFIG;
    uart_config.baudrate = UART_BAUDRATE_BAUDRATE_Baud115200; //User defined
    uart_config.hwfc = NRF_UART_HWFC_DISABLED; //User defined
    uart_config.interrupt_priority = APP_IRQ_PRIORITY_LOWEST; //User defined
    uart_config.parity = NRF_UART_PARITY_EXCLUDED; //User defined
    uart_config.pselrxd = 3; //User defined
    uart_config.pseltxd = 4; //User defined

    uint32_t err_code = nrf_drv_uart_init(&m_uart, &uart_config, uart_event_handler);
    APP_ERROR_CHECK(err_code);
}

#define led1 15
#define led2 16
#define power_key 5
#define button 7

int main(void)
{
    APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
    NRF_LOG_DEFAULT_BACKENDS_INIT();
    
    //uart_init(); // After default definition, before Advertise Start

    /* Configure board. */
    nrf_gpio_cfg_output(power_key);
    nrf_gpio_cfg_output(led1);
    nrf_gpio_cfg_output(led2);
    nrf_gpio_pin_set(led1);
    nrf_gpio_pin_set(led2);
    nrf_gpio_pin_clear(power_key);
    nrf_delay_ms(200);
    nrf_gpio_pin_set(power_key);

    nrf_gpio_cfg_input(button, NRF_GPIO_PIN_NOPULL);
    NRF_LOG_INFO("OXEEN Init\r\n");
    NRF_LOG_FLUSH();
    /* Toggle LEDs. */
    while (true)
    { 
        if(nrf_gpio_pin_read(button) == 1){
          NRF_LOG_INFO("Button pressed!\r\n");
          NRF_LOG_FLUSH();
          nrf_gpio_pin_clear(led1);
          nrf_delay_ms(1200);
        }else{
          nrf_gpio_pin_set(led1);
        }
    }
}

But I am getting error 

<error> app: ERROR 8 [NRF_ERROR_INVALID_STATE]
at line 47 in the code attached.

I am really new in the Nordic Semiconductor environment so any kind of help would be really appreciated.

Thank you,

Toni

Parents Reply Children
No Data
Related