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

Need to use 2 UARTS on nrf52840

Hi everyone

The following code is initiaizing the uarts correctly,but there is unpredictable behaviour in this case.

Whenever i disable the 1 UART sensor, works fine.

but on enabling both uart sensor , one of the sensor gets stucked.

Is this code fine to use 2 uarts?

void uart_init_terra(int pin_rx,int pin_tx)
{
uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);

    const app_uart_comm_params_t comm_params =
      {
          pin_rx,
          pin_tx,
          24,//RTS_PIN_NUMBER,
          25,//CTS_PIN_NUMBER,
          UART_HWFC,
          false,
#if defined (UART_PRESENT)
          NRF_UART_BAUDRATE_57600
#endif
      };

    APP_UART_FIFO_INIT(&comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOWEST,
                         err_code);
    if(err_code==0)
     SEGGER_RTT_printf(0,"UART ERROR CODE :%d\r\n",err_code);
     else
     SEGGER_RTT_printf(0,"UART ERROR CODE :%d\r\n",err_code);
    APP_ERROR_CHECK(err_code);
    APP_ERROR_CHECK(err_code);


}

void uart_init_terra_copy(int pin_rx,int pin_tx)
{
uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);

    const app_uart_comm_params_t comm_params =
      {
          pin_rx,
          pin_tx,
          24,//RTS_PIN_NUMBER,
          25,//CTS_PIN_NUMBER,
          UART_HWFC,
          false,
#if defined (UART_PRESENT)
          NRF_UART_BAUDRATE_19200
#endif
      };

    APP_UART_FIFO_INIT(&comm_params,
                         UART_RX_BUF_SIZE,
                         UART_TX_BUF_SIZE,
                         uart_error_handle,
                         APP_IRQ_PRIORITY_LOWEST,
                         err_code);

       if(err_code==0)
     SEGGER_RTT_printf(0,"UART ERROR CODE :%d\r\n",err_code);
     else
     SEGGER_RTT_printf(0,"UART ERROR CODE :%d\r\n",err_code);
    APP_ERROR_CHECK(err_code);
    APP_ERROR_CHECK(err_code);


}

Parents Reply
  • Sensor_read function is using the uart with "uart_init_terra_copy" function and LoRa uses uart_init_terra function.

    Whenever the sensor-read function is called ,it works fine but if after that i call lora send function , it gets stucked in app_uart_get function inside the lora send function.

    However if i comment out the sensor_read function, it works fine.

                        int k = sensor_read ();
                                if (k == ERROR)
                                    {
                                        SEGGER_RTT_printf (
                                            0, "Sensor Read Fail \r\n");
                                    }
                                           
                                    
                                     test_ack=lora_send ("Test");
              SEGGER_RTT_printf(0,"ACK:%d\r\n",test_ack);
              nrf_delay_ms (15000);

Children
Related