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.

  • You will get the best throughput with S130 v2 at the master and either s110 or s130 v2 at the peripheral. S120 will not give you better throughput.

    20 byte packet is 20 bytes, a 20 character string will be 21 bytes due to the null terminator.

    Error code 7 means NRF_ERROR_INVALID_PARAM. Which is probably because length is greater than BLE_NUS_MAX_DATA_LEN (see in ble_nus_string_send function).

    Your code will most likely wait for very long time in while(true) statement in uart_send_flowcontrol(). In this case it is better to have another approach: If BLE_ERROR_NO_TX_PACKET is received store the packet in a buffer (f.ex. use app_fifo). When BLE_EVT_TX_COMPLETE is received check if there are any packets in the buffer and send them out if so.

Reply
  • You will get the best throughput with S130 v2 at the master and either s110 or s130 v2 at the peripheral. S120 will not give you better throughput.

    20 byte packet is 20 bytes, a 20 character string will be 21 bytes due to the null terminator.

    Error code 7 means NRF_ERROR_INVALID_PARAM. Which is probably because length is greater than BLE_NUS_MAX_DATA_LEN (see in ble_nus_string_send function).

    Your code will most likely wait for very long time in while(true) statement in uart_send_flowcontrol(). In this case it is better to have another approach: If BLE_ERROR_NO_TX_PACKET is received store the packet in a buffer (f.ex. use app_fifo). When BLE_EVT_TX_COMPLETE is received check if there are any packets in the buffer and send them out if so.

Children
No Data
Related