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

How to use "ble_nus_string_send correctly" ?

Hello everybody, I try to send nus_string data. I bought different inputs and outputs like this;

INPUT;

while(ble_nus_string_send(&m_nus, (uint8_t *)"aaaaaaaaaaaaaaa", (uint16_t *)17) != NRF_SUCCESS);   // I wrote "a" 17 times

OUTPUT;

"aaaaa" received       // Send 5 times "a"

INPUT;

while(ble_nus_string_send(&m_nus, (uint8_t *)"aaaaaaaaaaaaaaaaa", (uint16_t *)19) != NRF_SUCCESS);     //I wrote "a" 19 times

OUTPUT;

There is no response!

1-Why do I see 5 characters when I enter 17 characters?

2-Why do not I see anything when I enter 19 characters?

3-How do I enter any characters and see all of it?

Thank you :)

Parents
  • Hi,

    For debugging I suggest to make the length parameter be the size of the string, the length of the two strings above seems to be 15 and 17, not 17 and 19?

    Can you use "abcde.." instead so we may see if it's the first or last bytes that is missing?

    Have you checked the baudrate is correct and possible tried to disable hardware flow control?

    I assume there is no assert occuring here on either sides of the link?

    Finally, for testing you may also remove power_manage() to see if that make any difference.

    Hopefully one of these changes will change behaviour and identify the cause. 

  • Blank character should not be a problem, I am more concerned about the 2 non-defined characters that I can't see from the string. 

  • Original code like this;

    while(ble_nus_string_send(&m_nus, (uint8_t *)"serial no updated", (uint16_t *)17) != NRF_SUCCESS);

    and I received "seria"

  • // <o> NRF_SDH_BLE_GAP_EVENT_LENGTH - The time set aside for this connection on every connection interval in 1.25 ms units. 
    #ifndef NRF_SDH_BLE_GAP_EVENT_LENGTH
    #define NRF_SDH_BLE_GAP_EVENT_LENGTH 3
    #endif

    Could it be an effect of this setting?

  • Try this:

    APP_TIMER_DEF(send_some_uart_data);    /**< Some timer */
    
    void send_some_uart_data_handler(void * p_context)
    {
        ret_code_t err_code;
        
        uint8_t string[] = "serial updated\n\r";
        uint16_t length = sizeof(string);
        
        do
        {
            
            err_code = ble_nus_string_send(&m_nus, string, &length);
            if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
            {
                APP_ERROR_CHECK(err_code);
            }
        } while (err_code == NRF_ERROR_BUSY);    
    }
    
    void send_some_data_uart_init(void)
    {
        app_timer_create(&send_some_uart_data,APP_TIMER_MODE_REPEATED, send_some_uart_data_handler);
        app_timer_start(send_some_uart_data, APP_TIMER_TICKS(1000), NULL);
    }
    
    // Call send_some_data_uart_init(); in main() to run send_some_uart_data_handler() at configured internal.
    

Reply
  • Try this:

    APP_TIMER_DEF(send_some_uart_data);    /**< Some timer */
    
    void send_some_uart_data_handler(void * p_context)
    {
        ret_code_t err_code;
        
        uint8_t string[] = "serial updated\n\r";
        uint16_t length = sizeof(string);
        
        do
        {
            
            err_code = ble_nus_string_send(&m_nus, string, &length);
            if ( (err_code != NRF_ERROR_INVALID_STATE) && (err_code != NRF_ERROR_BUSY) )
            {
                APP_ERROR_CHECK(err_code);
            }
        } while (err_code == NRF_ERROR_BUSY);    
    }
    
    void send_some_data_uart_init(void)
    {
        app_timer_create(&send_some_uart_data,APP_TIMER_MODE_REPEATED, send_some_uart_data_handler);
        app_timer_start(send_some_uart_data, APP_TIMER_TICKS(1000), NULL);
    }
    
    // Call send_some_data_uart_init(); in main() to run send_some_uart_data_handler() at configured internal.
    

Children
Related