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

AVR UART regarding RTS/CTS

I am using a nRF51 dongle as a BLE tranciever and using UART to communicate with an 8bit AVR. I used BLE_APP_UART peripheral example and mostly just changed the pins used for commuincation from the USB pins to some GPIO pins, and added the segger RTT. I am using a logic level converter to interface with the AVR which is running at 5 volts.

For reasons the dongle crashes if i send messages too fast, and I am thinking it might got something to do with that I disabled flow control on the dongle, since the AVR don't have it.

I have hooked up a com cable to listen on the UART line to verify that only the nRF is crashing and not the AVR as well. It crashes even if the cable is not connected as well, so it's not causing it.

The error I get when debugging is 3004, from main.c line 426 which is here:

    /**@snippet [Handling the data received over UART] */
    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]));
                index++;
    
                if ((data_array[index - 1] == '\n') || (index >= (BLE_NUS_MAX_DATA_LEN)))
                {
                    err_code = ble_nus_string_send(&m_nus, data_array, index);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
error trigger->       APP_ERROR_CHECK(err_code);
                    }

I'm not sure how to go about this, I sort of need to get these messages faster than once per second so i'd appreciate some clues on to how to proceed

Parents
  • The issue is not with the UART, but with the BLE link. You are sending too many packets and the ble_nus_string_send(..) function is returning BLE_ERROR_NO_TX_PACKETS (error code 0x3004, previously called BLE_ERROR_NO_TX_BUFFERS). The error code originally comes from the sd_ble_gatts_hvx(..) function which is called inside ble_nus_string_send(..).

    See for example this post on how to handle this error code and send large amount of data. You should also make sure that the UART buffer (defined in APP_UART_FIFO_INIT) is large enough to buffer the data that are to be sent over BLE.

  • The example referred to in the post I linked to is from ble_app_hrs example. But the function ble_hrs_heart_rate_measurement_send(..) will call sd_ble_gatts_hvx(..) just as ble_nus_string_send(..) is doing.

    The UART example will only divide the input over uart in packets of 20 bytes and send it over BLE. If you implement the "flow control" in the link, the example will max the throughput as long as UART bitrate is larger than BLE bitrate.

    If your connection interval is over 200ms and the number of packets you can send per connection event is low (this is for most part limited by the central, take a look at this post), you may not be able to get that throughput.

Reply
  • The example referred to in the post I linked to is from ble_app_hrs example. But the function ble_hrs_heart_rate_measurement_send(..) will call sd_ble_gatts_hvx(..) just as ble_nus_string_send(..) is doing.

    The UART example will only divide the input over uart in packets of 20 bytes and send it over BLE. If you implement the "flow control" in the link, the example will max the throughput as long as UART bitrate is larger than BLE bitrate.

    If your connection interval is over 200ms and the number of packets you can send per connection event is low (this is for most part limited by the central, take a look at this post), you may not be able to get that throughput.

Children
No Data
Related