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

Send and receive UART from two nrf52840 DK

Hi, newbe here, using Segger Embedded Studios, two nrf52840 DKs, SDK 17.0.0, and a whole lotta enthusiasm!

I am developing a custom solution based on the ble_app_uart (central and peripheral) examples. What I needed was to send uint8_t data from one nrf52840 DK to another. I discovered the use of the ble_nus_data_send() function in the peripheral example. I created a timer based handler function that sends data every two seconds.

Here is the data_send_handler function in the peripheral: (sensor_value is a uint8_t global variable - for now it is a constant (eg. 122) but in the future I wish to send SAADC). This is the main addition to the example. The other is creating a timer etc..

static void data_send_handler(void * p_context)
{
    ret_code_t err_code;

    static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];

    data_array[0] = sensor_value;

    err_code = ble_nus_data_send(&m_nus, data_array[0], sizeof(uint8_t), m_conn_handle);
    if (err_code != NRF_SUCCESS &&
        err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
        err_code != NRF_ERROR_INVALID_STATE &&
        err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
    {
        APP_ERROR_CHECK(err_code);
    }
    NRF_LOG_INFO("%d", sensor_value);
    nrf_gpio_pin_clear(LED);
}

I have not encountered any issues with this so far, the program compiles without errors and is able to connect to the central without issues.

On the central nRF52840 DK, I flashed the device with the ble_app_uart_c example without changes. With this setup, I was expecting to receive the sensor value on the central side, but all I get is random characters (shown in figure below).

I looked everywhere to get an idea of why this is happening, but I cannot understand the reason.

Would be great to know why!
TIA!

Related