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

Data rate problem

Hi,

I use the peripheral ble_app_uart with nRF52832 (Murata module). The nRF52832 is connected to another MCU, STM32L476, via UART. 

I develop using IAR.

I have a couple of problems, but first I'll explain what changes I've made to the code.

The connection between the peripheral and central is controlled by the external MCU (STM32L476), once a connection is made the peripheral sends a packet to the external MCU, and if the user approves the connection the external MCU will send a packet back, after that an IO port is set and normal communication between peripheral and central is starting.

I use hardware flow control on both peripheral and central.

I have 2 rates of data, the normal one is 42 bytes every one second, the second is 906 bytes every 220msec.

When ox_conn_mode = 3 there's a BLE connection between the peripheral and central, but data from the UART will not be sent to the central until the connection is approved.

When ox_conn_mode = 4 the connection is approved and data from the UART is sent to the central, here is when I encounter 2 problems:

Problem 1

the first packet sent via UART in peripheral to the central is of 6 bytes and it is received correctly, right after that 45 bytes are sent every 1 second, but on the terminal at the central side, I see that 18 bytes are received, and the rest are received on the next second (when the new 45 bytes are sent) with only the fist part of the next packet.

Like this:

16/07/2018 12:40:55.553 [RX] - FB FA 06 00 11 00 - This is the first 6 bytes
16/07/2018 12:41:00.652 [RX] - FB FA 2D 00 0B 00 00 00 00 40 00 02 00 00 01 00 00 00 - This is the first part of the 45 bytes packet
16/07/2018 12:41:01.706 [RX] - 00 00 00 00 00 00 7B 01 E5 56 A1 06 00 00 82 F1 3B 00 00 00 00 00 00 00 00 00 7C FB FA 2D 00 0B 00 00 00 00 40 00 02 00 00 00 00 00

So above in green is the packet from the first second, and in red the packet from the second second, this pattern repeats.

I need the entire packet sent every 1 second to be received at the same time and not have part of it delayed for 1 second.

Problem 2:

Once I try to send the 906 bytes the terminal in the central side receives 20-40 bytes and stops. The peripheral code is not stuck in error, but there is no data sent between the peripheral and central.

I have the follwing defined:

#define MIN_CONN_INTERVAL MSEC_TO_UNITS(20, UNIT_1_25_MS) 
#define MAX_CONN_INTERVAL MSEC_TO_UNITS(75, UNIT_1_25_MS)

If I try to set min = 5 and max = 20 (in both central and peripheral) the peripheral gets NRF_FAULT_ID_SDK_ERROR

I am not a BLE expert and any help will be appreciated

Peripheral uart_event_handle:

void uart_event_handle(app_uart_evt_t *p_event)
{
  static uint8_t data_array[BLE_NUS_MAX_DATA_LEN]; // 245 bytes length buffer
  static uint16_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 (4 == ox_conn_mode) // In Approved connection mode -> Pass the byte to the BLE
      {
        //Transmit the received byte over BLE

        err_code = ble_nus_data_send(&m_nus, data_array, &index, m_conn_handle);

        if (NRF_SUCCESS == err_code)
          index = 0;
      }
      // Data format from STM: Header: FAFB, Length 16bit, Command ID 16 bit, Data. 6 bytes and data.
      // Check the connection mode
      else if (3 == ox_conn_mode)
      {
        if (5 < index) // Got more than 5 bytes
        {
          if ((0xFB == data_array[0]) && (0xFA == data_array[1]) &&
              (0x06 == data_array[2]) && (0x00 == data_array[3]) &&
              (0x11 == data_array[4]) && (0x00 == data_array[5]) )
          {
            ox_conn_mode = 4; // Connection confirmed
            app_timer_stop(m_ox_con_tmr);
            nrf_gpio_pin_write(2, 1); // Doron - Set the connection PIO.
          }
          else if ((0xFB == data_array[0]) && (0xFA == data_array[1]) &&
                   (0x06 == data_array[2]) && (0x00 == data_array[3]) &&
                   (0x12 == data_array[4]) && (0x00 == data_array[5]) )
          {

            app_timer_stop(m_ox_con_tmr);   //Connection deny
            err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_CONTROLLER_BUSY);
          }

          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;

    default:
      break;
  }
}

In the Central I have the following defined:

#define ECHOBACK_BLE_UART_DATA  1 

This is the Central uart_event_handle:

void uart_event_handle(app_uart_evt_t *p_event)
{
  static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
  static uint16_t index = 0;
  uint32_t ret_val;

  switch (p_event->evt_type)
  {
    /**@snippet [Handling data from UART] */
    case APP_UART_DATA_READY:
      UNUSED_VARIABLE(app_uart_get(&data_array[index]));
      index++;

      do
      {
        ret_val = ble_nus_c_string_send(&m_ble_nus_c, data_array, index);

        if ( (ret_val != NRF_ERROR_INVALID_STATE) && (ret_val != NRF_ERROR_BUSY) )
        {
          APP_ERROR_CHECK(ret_val);
        }
      } while (ret_val == NRF_ERROR_BUSY);

      index = 0;

      break;

    /**@snippet [Handling data from UART] */
    case APP_UART_COMMUNICATION_ERROR:
      NRF_LOG_ERROR("Communication error occurred while handling UART.");
      APP_ERROR_HANDLER(p_event->data.error_communication);
      break;

    case APP_UART_FIFO_ERROR:
      NRF_LOG_ERROR("Error occurred in FIFO module used by UART.");
      APP_ERROR_HANDLER(p_event->data.error_code);
      break;

    default:
      break;
  }
}

Thank you

Related