NordicSemiconductor / pc-nrfconnect-rssi

RSSI Viewer app for nRF Connect for Desktop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NORDIC - nrf52840 In our application we need to receive data from two uart together

GianmarcoMicrotech opened this issue · comments

Dear Sir,
we are developing an application on the nRF52840 kit with SDK 15.0.0. We are using Keil as compiler. In our application we need to receive data from two uart together. If we use only one uart the application work fine, but if we add the second uart the firmware have a strange behavior: one of the two uart after a certain time stops to work. The time and the uart that stops are not always the same, it seems casual.
What can happen?
Attached you can find the files main.c, the nrf_serial library and the file sdk_config.h.
Please, help us because we are very worry, we need to complete the project soon.

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

#include "nrf.h"
#include "nrf_drv_clock.h"
#include "nrf_gpio.h"
#include "nrf_delay.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_drv_power.h"
#include "nrf_serial.h"
#include "app_timer.h"


#include "app_error.h"
#include "app_util.h"
#include "boards.h"

/** @file
 * @defgroup nrf_serial_example main.c
 * @{
 * @ingroup nrf_serial_example
 * @brief Example of @ref nrf_serial usage. Simple loopback.
 *
 */

#define OP_QUEUES_SIZE          3
#define APP_TIMER_PRESCALER     NRF_SERIAL_APP_TIMER_PRESCALER

static void sleep_handler(void)
{
    __WFE();
    __SEV();
    __WFE();
}

NRF_SERIAL_DRV_UART_CONFIG_DEF ( m_uart0_drv_config,
                      RX_PIN_NUMBER, TX_PIN_NUMBER,
                      RTS_PIN_NUMBER, CTS_PIN_NUMBER,
                      NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
                      NRF_UART_BAUDRATE_9600,
											UART_DEFAULT_CONFIG_IRQ_PRIORITY);

NRF_SERIAL_DRV_UART_CONFIG_DEF ( m_serial_uart_badge_reading_drv_config ,
                      3 , 4 ,	// Rx pin = P0.03 -- Tx pin = P0.04
                      RTS_PIN_NUMBER , CTS_PIN_NUMBER ,
                      NRF_UART_HWFC_DISABLED , NRF_UART_PARITY_EXCLUDED ,
                      NRF_UART_BAUDRATE_115200 ,
                      UART_DEFAULT_CONFIG_IRQ_PRIORITY ) ; 

#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32

NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);

NRF_SERIAL_QUEUES_DEF ( serial_uart_badge_reading_queues , SERIAL_FIFO_TX_SIZE , SERIAL_FIFO_RX_SIZE ) ;

#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1

NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);

// Configuro i buffer delle seriali	
NRF_SERIAL_BUFFERS_DEF ( serial_uart_badge_reading_buffs , SERIAL_BUFF_TX_SIZE , SERIAL_BUFF_RX_SIZE ) ;

NRF_SERIAL_CONFIG_DEF(serial_config, NRF_SERIAL_MODE_IRQ,
                      &serial_queues, &serial_buffs, NULL, sleep_handler);
											
											// Configuro le seriali											
NRF_SERIAL_CONFIG_DEF ( serial_uart_badge_reading_config , NRF_SERIAL_MODE_IRQ ,
                        &serial_uart_badge_reading_queues , &serial_uart_badge_reading_buffs , NULL , sleep_handler ) ;	// sostituito NULL ( il secondo ) a sleep_handlerù
												
NRF_SERIAL_UART_DEF ( serial_uart , 0 ) ;

NRF_SERIAL_UART_DEF ( serial_uart_badge_reading , 1 ) ;

char	buff_received_uart_badge [ 30 ] = "" ;
char	tmp_buff_debug  [ 50 ] = "" ;
char	UID_badge [ 10 ] = "" ;

int main(void)
{
    ret_code_t ret ;
		ret_code_t ret_loop ;
	
    ret = nrf_drv_clock_init();
    APP_ERROR_CHECK(ret);
    ret = nrf_drv_power_init(NULL);
    APP_ERROR_CHECK(ret);

    nrf_drv_clock_lfclk_request(NULL);
    ret = app_timer_init();
    APP_ERROR_CHECK(ret);

    // Initialize LEDs and buttons.
    bsp_board_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS);

    ret = nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
    APP_ERROR_CHECK(ret);
	
    // Inizializzo la seriale 	
    ret = nrf_serial_init ( &serial_uart_badge_reading , &m_serial_uart_badge_reading_drv_config , &serial_uart_badge_reading_config ) ;
    APP_ERROR_CHECK(ret);
	
    static char tx_message[] = "Hello nrf_serial 1!\n\r";

    ret = nrf_serial_write(&serial_uart,
                           tx_message,
                           strlen(tx_message),
                           NULL,
                           NRF_SERIAL_MAX_TIMEOUT);
													 
    APP_ERROR_CHECK(ret);	

    while (true)
    {
        char a ;

        /********************* Seriale 1. *********************
        */
        ret_loop = nrf_serial_read ( &serial_uart_badge_reading , &a , sizeof ( a ) , NULL , 5 ) ;

        if ( ret_loop == NRF_SUCCESS )
        {		
            ( void ) nrf_serial_write ( &serial_uart , &a , sizeof ( a ) , NULL , 0 ) ;
            nrf_serial_flush ( &serial_uart_badge_reading , 5 ) ;

        }					

        char c ;

        /********************* Seriale 2. *********************
        */
        ret = nrf_serial_read ( &serial_uart , &c , sizeof ( c ) , NULL , 5 ) ;        			

        if ( ret == NRF_SUCCESS )
        {
            ( void ) nrf_serial_write ( &serial_uart , &c , sizeof ( c ) , NULL , 0 ) ;
            nrf_serial_flush ( &serial_uart , 5 ) ;	

        }

    }

}

/** @} */

Hi @GianmarcoMicrotech ,
Is your application based on our https://github.com/NordicSemiconductor/pc-nrfconnect-core?
If yes, do you mean that you are selecting two uart devices in the same app from the selector at the top left as in this rssi app?
If no, then the issue does not belong to here. I suggest you to ask at https://devzone.nordicsemi.com/

Hi @GianmarcoMicrotech ,

Please note that the firmware code provided by this repo is a humble effort by non-embedded developers and is only here for reference.

As I understand your issue here is with the usage of nRF SDK to utilise two UARTs of the kit, which has been discussed on devzone.

Also note that if you are about to use the UARTs in an nRFConnect Desktop app like the RSSI app here, the framework at the moment does not provide a straightforward way of selecting more than one device. Feel free to open a separate issue regarding this if needed.