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

ble_nus_data_send() can not send data to mobile app (nRF UART v2.0)

Hi,

I am developing with nRF52832, SDK 15.3

I have an issue with sending data over NUS service. When I flash the code to nRF, it starts advertising, but when I connect to it by nRF UART v2.0 mobile app, LED 1 on DK just fast double blinks and DK disconnects my phone. My code is modified to sending data over ble_nus_data_send() every time app_timer handler is triggered. Value to be send is modified from intenger data type, to char data type, so maybe there might be the problem.

thanks for help!

static void data_send()
{
  uint32_t       err_code;
  int16_t   i = 123 ;
  char  buf[BUFSIZ];
  snprintf(buf, sizeof(buf), "%d", i);
  static uint16_t length = sizeof(buf);

      err_code =   ble_nus_data_send(&m_nus, buf, &length, m_conn_handle);

         if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) &&
                         (err_code != NRF_ERROR_NOT_FOUND) )
                    {
                        APP_ERROR_CHECK(err_code);
                    }

        NRF_LOG_INFO("Value Received !");


}

static void repeated_timer_handler(void * p_context)
{
    data_send();
}

Parents
  • Hi Pepam, 

    nRFUART v2.0 is pretty old app and is deprecated. You should test using the UART profile inside nRFToolbox or using nRFConnect app instead. 

    What you described sound like the MCU was reset due to an assertion. You may want to step into the code an debug. You can follow the debug guide here. We need to know where the assertion occurs. 

  • Hi Hung Bui,

    Thank you for answer. I solved this problem by sending an intenger data type value

    static void data_send()
    {
        uint32_t   value;
        value = 12000; // test value
        uint16_t length = sizeof(int);
        (void)ble_nus_data_send(&m_nus, (uint8_t *) &value, &length, m_conn_handle);
        NRF_LOG_INFO("ADC measuremement %d", value)
    
    }
    
    static void repeated_timer_handler(void * p_context)
    {
        data_send();
    }
    , insted of char and it works, but when i view log in nRF Toolbox, i can only see value: (hex number of my test value); please see what i have attached. Is there some way to convert this hex log value to decimal in nRF Toolbox? 

    thank you

Reply
  • Hi Hung Bui,

    Thank you for answer. I solved this problem by sending an intenger data type value

    static void data_send()
    {
        uint32_t   value;
        value = 12000; // test value
        uint16_t length = sizeof(int);
        (void)ble_nus_data_send(&m_nus, (uint8_t *) &value, &length, m_conn_handle);
        NRF_LOG_INFO("ADC measuremement %d", value)
    
    }
    
    static void repeated_timer_handler(void * p_context)
    {
        data_send();
    }
    , insted of char and it works, but when i view log in nRF Toolbox, i can only see value: (hex number of my test value); please see what i have attached. Is there some way to convert this hex log value to decimal in nRF Toolbox? 

    thank you

Children
Related