BLE Peripheral to Central Data Transmission Issue

Hi,

We're planning to integrate ble_app_uart and ble_app_uart_c into our project. Before integration, we tested the ble_app_uart example code on one development board. After powering it up, we connected the board using the nRF Connect app and were able to send and receive data.

For the next test, we flashed ble_app_uart_c onto one development board for the central part and ble_app_uart onto another for the peripheral. Upon powering both boards, they connected via BLE, and we could send data from the central to the connected peripheral device. However, we couldn't send data from the peripheral to the central. What could be the issue?

When we turned off the central development board and connected the ble_app_uart-flashed peripheral board to the nRF Connect app, we were able to send and receive data between the app and the board.

Project Details:

  • SDK: nRF5 SDK 17.0.2
  • IDE: SEGGER Embedded Studio 5.42a
  • Controller: nRF52832
  • Development boards: PCA10040 NRF52832

Thank you for your support.

Best regards, SILTVM

  •  

    I just made some necessary modifications to the ble_app_uart example code. These modifications involved the UART event handler and the NUS data handler.

    void uart_handler(app_uart_evt_t * p_event)
    {
        if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
        {
            printf("entered in uart communication error\n");
            APP_ERROR_HANDLER(p_event->data.error_communication);
        }
        else if (p_event->evt_type == APP_UART_FIFO_ERROR)
        {
            printf("entered in uart fifo error\n ");
            APP_ERROR_HANDLER(p_event->data.error_code);
        }
    
       else if (p_event->evt_type == APP_UART_DATA_READY)
        {    
            UNUSED_VARIABLE(app_uart_get(&uart_receive[UartDataCount++]));
            printf("uart : %s\n",uart_receive);
        }
    }
    
    
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    
       memset(BLEDataBuff,0,sizeof(BLEDataBuff));
       if (p_evt->type == BLE_NUS_EVT_RX_DATA)
        {
            uint32_t err_code;
              uint32_t ResponseCode=0;
             char TempData[64];
            NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
            NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    
            for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
            {
              BLEDataBuff[i]=(p_evt->params.rx_data.p_data[i]);
            }
              printf("\nBLEDataBuff : %s\n ",BLEDataBuff);
        }
    }
    
    int main(void)
    {
        bool erase_bonds;
        uart_init();
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
        printf("\r\nUART started.\r\n");
        NRF_LOG_INFO("Debug logging for UART over RTT started.");
        advertising_start();
        uint16_t length;
         while(1)
         {
    
            if (strlen(uart_receive))
            {
              printf("uart_receive : %s\n",uart_receive);
              length=strlen(uart_receive);
              ble_nus_data_send(&m_nus, uart_receive, &length, m_conn_handle);
              memset(uart_receive,0,sizeof(uart_receive));
              UartDataCount=0;
    
            }
            nrf_delay_ms(1000);
    
         }
    
    }
    
    

    now the code is works . 

    when receives a uart data send to connected central device . 

    when receives a ble data print it on the console log .  

  • hello siltvm,

    I am also trying to send data central to peripheral and peripheral to central, and i try same sample code and also try your suggestion which you give here,
    but facing issue in uart_receive, UartDataCount, BLEDataBuff syntax 
    can you please provide me definition of this terms? 

    Note: I use same sample code and same SDK and Segger embedded studio version. 

    ERROR MESSAGE:

    'uart_receive' undeclared (first use in this function)

    'UartDataCount' undeclared (first use in this function)

    'BLEDataBuff' undeclared (first use in this function)

    'uart_receive' undeclared (first use in this function)

    'UartDataCount' undeclared (first use in this function)

  •  ,

    Can you please describe more specifically the changes you made, and the errors you are facing due to the undeclared buffers like uart_receive, BLEDataBuff, and the undeclared variable UartDataCount?

    Can you add this globally:


    unsigned char UartDataCount = 0;
    char uart_receive[64];
    char BLEDataBuff[247];

    And then rebuild the code. Kindly check if the error is still occurring.

  • Thanks for replay siltvm,

    I am made changes in my ble_app_uart (peripheral side code), and i made changes as you mention above. The same changes i made in same file.
    The central side ble_app_uart_c file i flash in nrf52832 as it is given in SDK without changes.

    Now, after this implementation when i connect my nrf52 device with mobile application then it's receives data and show on serial monitor, but not able to send data to mobile application.
    After that i am trying with 2 nrf52832 device, one is central role and another is in peripheral role with same code, but in this case peripheral not receives data which send by central device and also central not receives data.

    Again i tell you, central side code is without changes, and made changes as you mention above in peripheral side code.

    Guide me to made bi-directional communication bridge between central and peripheral.   

  •  ,Can you be able to attach your peripheral code? Then I will review it and try to find the reason for this issue .

Related