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

app_uart_put() check that is transmmited all bytes from FIFO?

Hi i have tried with uart example and need to change baudrate after the some string is transmmited over UARTS TX. Is it possible to somehow that to check that all bytes from FIFO are transmmited?

Parents
  • for solving this in ble_app_uart example in uart_event_handle function add  case APP_UART_TX_EMPTY:  and you can do everything what you want later  if you must to do something when this event happens. 

    P.S. when you start app this evens happens you must add some condition :) that you handle later 

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
               // data_array[index] = data_array[index] & 0x7f;
                index++;
    
                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(data_array, index);
                          bsp_board_led_invert(2);
                        do
                        {
                            uint16_t length = (uint16_t)index;
                            err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                            if ((err_code != NRF_ERROR_INVALID_STATE) &&
                                (err_code != NRF_ERROR_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_RESOURCES);
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            case APP_UART_TX_EMPTY:
                if(data[0] == 'q' && data[1] == 'r'){
                bsp_board_led_invert(3);
                }
                break;
    
            default:
                break;
        }
    }

Reply
  • for solving this in ble_app_uart example in uart_event_handle function add  case APP_UART_TX_EMPTY:  and you can do everything what you want later  if you must to do something when this event happens. 

    P.S. when you start app this evens happens you must add some condition :) that you handle later 

    void uart_event_handle(app_uart_evt_t * p_event)
    {
        static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
        static uint8_t index = 0;
        uint32_t       err_code;
    
        switch (p_event->evt_type)
        {
            case APP_UART_DATA_READY:
                UNUSED_VARIABLE(app_uart_get(&data_array[index]));
               // data_array[index] = data_array[index] & 0x7f;
                index++;
    
                if ((data_array[index - 1] == '\n') ||
                    (data_array[index - 1] == '\r') ||
                    (index >= m_ble_nus_max_data_len))
                {
                    if (index > 1)
                    {
                        NRF_LOG_DEBUG("Ready to send data over BLE NUS");
                        NRF_LOG_HEXDUMP_DEBUG(data_array, index);
                          bsp_board_led_invert(2);
                        do
                        {
                            uint16_t length = (uint16_t)index;
                            err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
                            if ((err_code != NRF_ERROR_INVALID_STATE) &&
                                (err_code != NRF_ERROR_RESOURCES) &&
                                (err_code != NRF_ERROR_NOT_FOUND))
                            {
                                APP_ERROR_CHECK(err_code);
                            }
                        } while (err_code == NRF_ERROR_RESOURCES);
                    }
    
                    index = 0;
                }
                break;
    
            case APP_UART_COMMUNICATION_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_communication);
                break;
    
            case APP_UART_FIFO_ERROR:
                APP_ERROR_HANDLER(p_event->data.error_code);
                break;
    
            case APP_UART_TX_EMPTY:
                if(data[0] == 'q' && data[1] == 'r'){
                bsp_board_led_invert(3);
                }
                break;
    
            default:
                break;
        }
    }

Children
No Data
Related