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

NRF52832 MESH with UART

want to add UART communication to nRF52832 with mesh enable.

I have added,

  • nrf_drv_uart.c
  • nrfc_prs.c
  • nrfc_uart.c
  • nrfc_uarte.c

files into nRF_Drivers folder in project and added User include directories for them and also I have added

  • app_fifo.c
  • app_uart_fifo.c
  • retarget.c

files into nRF_Libraries folder in project and added User include directories also for them

In sdk_config.h I have made following settings,

  • NRFX_UARTE_ENABLED 1
  • NRFX_UARTE0_ENABLED 1
  • NRFX_UART_ENABLED 1
  • NRFX_UART0_ENABLED 1
  • NRFX_PRS_ENABLED 1
  • NRFX_PRS_BOX_4_ENABLED 1

and

  • UART_EASY_DMA_SUPPORT 1
  • UART_LEGACY_SUPPORT 1

And project also compiled after setting above configurations.

Code I made as follow (Modified version on light switch server )


#include "app_uart.h"


#if defined (UART_PRESENT)
#include "nrf_uart.h"
#endif
#if defined (UARTE_PRESENT)
#include "nrf_uarte.h"
#endif


#define UART_TX_BUF_SIZE                256                                         /**< UART TX buffer size. */
#define UART_RX_BUF_SIZE                256   


/*
other functions same as light switch server example

*/

void uart_event_handle(app_uart_evt_t * p_event)
{
    static uint8_t data_array[50];
    static uint8_t index = 0;
    uint32_t       err_code;
    
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Handler\n");
    //__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "evt %d\n", p_event->evt_type);

    switch (p_event->evt_type)
    {
        
        case APP_UART_DATA_READY:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "app data ready\n");
            UNUSED_VARIABLE(app_uart_get(&data_array[index]));
            index++;

            if (data_array[index - 1] == '\n') 
            {
                if (index > 1)
                {
                    /*
                        Need to implement the function in here
                    
                    */
                    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Receive\n");
                }

                index = 0;
            }
            break;

        case APP_UART_COMMUNICATION_ERROR:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Communication ERROR\n");
            APP_ERROR_HANDLER(p_event->data.error_communication);
            break;

        case APP_UART_FIFO_ERROR:
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "FIFO ERROR\n");
            APP_ERROR_HANDLER(p_event->data.error_code);
            break;

        default:
            break;
    }
}


static void uart_init(void)
{

//    #define RX_PIN_NUMBER  8
//    #define TX_PIN_NUMBER  7
//    #define CTS_PIN_NUMBER 6
//    #define RTS_PIN_NUMBER 5
    uint32_t                     err_code;
    app_uart_comm_params_t const comm_params =
    {
        .rx_pin_no    = RX_PIN_NUMBER,
        .tx_pin_no    = TX_PIN_NUMBER,
        .rts_pin_no   = NULL,           //RTS_PIN_NUMBER,
        .cts_pin_no   = NULL,           //CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
#if defined (UART_PRESENT)
        .baud_rate    = NRF_UART_BAUDRATE_9600
#else
        .baud_rate    = NRF_UART_BAUDRATE_9600
#endif
    };

    APP_UART_FIFO_INIT(&comm_params,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,     //NRF_MESH_IRQ_PRIORITY_LOWEST,    //
                       err_code);
    APP_ERROR_CHECK(err_code);
}

/*
initilize uart_init inside initializer
*/

static void initialize(void)
{ 
    uart_init();
    __LOG_INIT(LOG_SRC_APP | LOG_SRC_ACCESS | LOG_SRC_BEARER, LOG_LEVEL_INFO, LOG_CALLBACK_DEFAULT);
    __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "----- BLE Mesh Light Switch Server Demo -----\n");

    ERROR_CHECK(app_timer_init());
    hal_leds_init();

#if BUTTON_BOARD
    ERROR_CHECK(hal_buttons_init(button_event_handler));
#endif

    ble_stack_init();

#if MESH_FEATURE_GATT_ENABLED
    gap_params_init();
    conn_params_init();
#endif

    mesh_init();
    
}

Following result got through debugging,

<t:          0>, main.c,  438, ----- BLE Mesh Light Switch Server Demo -----
<t:      13810>, main.c,  380, Initializing and adding models
<t:      13813>, main.c,  224, App OnOff Model Handle: 2
<t:      18763>, main.c,  479, Device UUID : 005955AA00000000E5F8D4197B5E9BA2
<t:     245432>, main.c,  308, Handler
<t:     245433>, main.c,  331, Communication ERROR
<t:     245436>, app_error_weak.c,  119, Mesh error 4 at 0x00000000 (:0)

according to above result once development board receive a signal through RX pin uart_event_handler function calls as expected, and inside that handler I got APP_UART_COMMUNICATION_ERROR

So what would be the cause for this error.

Is there any .c file missing or something with the code

Parents
  • Hi Edvin,

    As you said my APP_COMMUNICATION_ERROR error code is 4. So according to "nRF52832 Objective Product Specification" ERRORSRC register value is 0b0100. It mean It should be framing error. 

    In my case RX pin isn't in floating and it's baud rate is 9600 and other MCU also send data in that baud rate. 

    I tried different methods to overcome this issue, increased buffer size, enable internal pullups but nothing work for me.

    So do you have any suggestion for this issue ?

Reply
  • Hi Edvin,

    As you said my APP_COMMUNICATION_ERROR error code is 4. So according to "nRF52832 Objective Product Specification" ERRORSRC register value is 0b0100. It mean It should be framing error. 

    In my case RX pin isn't in floating and it's baud rate is 9600 and other MCU also send data in that baud rate. 

    I tried different methods to overcome this issue, increased buffer size, enable internal pullups but nothing work for me.

    So do you have any suggestion for this issue ?

Children
Related