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

UART Implementation connection issue

Hi, I am learning how to implement Long Range on the UART central and peripheral examples using SDK 17.0.0. The error I am facing is that the debug terminal shows

[ app_timer: RTC:initialized

app: Debug logging for UART over RTT started.

app: Connected

app: Disconnected ]

The connection state switched immediately. The issue I think I face is about the high packet error rate : here

Will changing the dbm to 8 (max dBm for nRF52840) resolve this? And how to apply sd_ble_gap_tx_power_set() to the codes because I cannot find the function in the UART despite searching the whole file, any place I can learn to do this and if doing so will resolve the issue I am facing? Thank you.

Parents
  • Hi

    Yes, I can see the debug messages, but there aren't any errors or disconnect messages there. 

    As for why you don't see the UART messages, are you positive that they aren't sent from the central, or that they don't show up in the terminal on the peripheral side? By "not consistent" do you mean that some of the messages do appear, while others don't? At what range and in what environment are you seeing this packet loss?

    Best regards,

    Simon

Reply
  • Hi

    Yes, I can see the debug messages, but there aren't any errors or disconnect messages there. 

    As for why you don't see the UART messages, are you positive that they aren't sent from the central, or that they don't show up in the terminal on the peripheral side? By "not consistent" do you mean that some of the messages do appear, while others don't? At what range and in what environment are you seeing this packet loss?

    Best regards,

    Simon

Children
  • Hi Simonr, I managed to find out the issue. It lies within the code. (index >= (m_ble_nus_max_data_len) causing messages to be sent every 20 inputs. Thank you for the guidance,

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint16_t index = 0;
        uint32_t ret_val;
    
        switch (p_event->evt_type)
        {
            /**@snippet [Handling data from UART] */
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
                index++;
    
                if ((data_array[index - 1] == '\n') || (index >= (m_ble_nus_max_data_len)))
                {
                    NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                    NRF_LOG_HEXDUMP_DEBUG(data_array, index);
    
                    do
                    {
                        ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, index);
                        if ( (ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_RESOURCES) )
                        {
                            APP_ERROR_CHECK(ret_val);
                        }
                    } while (ret_val == NRF_ERROR_RESOURCES);
    
                    index = 0;
                }
                break;
    
            /**@snippet [Handling data from UART] */
            case APP_UART_COMMUNICATION_ERROR:
                NRF_LOG_ERROR("Communication error occurred while handling UART.");
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                NRF_LOG_ERROR("Error occurred in FIFO module used by UART.");
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            default:
                break;
        }
    }

Related