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

Bluetooth not connecting after inclusion of UART module in HID example. Its urgent.

I'm trying to combine hid keyboard with .../peripheral/uart example. 

Only after the bluetooth connection is established between host (PC) & nrf DK, I want to continuously send data received from uart (connected to microcontroller) to host machine. This data needs to be sent in input report. 

But if I merge the uart peripheral with hid keyboard, the bluetooth does not connect at all.

I have pasted the changes I have made to specific functions/ files. Can you check at your end?

void uart_error_handle(app_uart_evt_t * p_event)
{
	if (p_event->evt_type == APP_UART_DATA_READY)
    {
		if(flag == 1)
		{
			while (app_uart_get(&cr) != NRF_SUCCESS){};
			if (cr == '9')
			{
				bsp_board_led_invert(1);
				nrf_delay_ms(500);
			}
		}
		//while (app_uart_put('?') != NRF_SUCCESS);
	}
/*	else if (p_event->evt_type == APP_UART_TX_EMPTY)
    {
        while (app_uart_put('?') != NRF_SUCCESS);
    }*/
    else if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
        APP_ERROR_HANDLER(p_event->data.error_code);
    }	
}

static void uart_init(void)
{
	uint32_t err_code;
	const app_uart_comm_params_t comm_params = 
	{
          RX_PIN_NUMBER,
          TX_PIN_NUMBER,
          0,/*RTS_PIN_NUMBER,*/
          0,/*CTS_PIN_NUMBER,*/
          UART_HWFC,
          false,
          NRF_UART_BAUDRATE_460800
      };
    APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOWEST, err_code);
	APP_ERROR_CHECK(err_code);
}

static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
{
    ret_code_t err_code;
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            NRF_LOG_INFO("Connected");
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
            APP_ERROR_CHECK(err_code);
			flag = 1;
            break;
        case BLE_GAP_EVT_DISCONNECTED:
            NRF_LOG_INFO("Disconnected");
            // Dequeue all keys without transmission.
            (void) buffer_dequeue(false);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            // Reset m_caps_on variable. Upon reconnect, the HID host will re-send the Output report containing the Caps lock state.
//            m_caps_on = false;
            // disabling alert 3. signal - used for capslock ON
            err_code = bsp_indication_set(BSP_INDICATE_ALERT_OFF);
            APP_ERROR_CHECK(err_code);
			flag = 0;
            break; // BLE_GAP_EVT_DISCONNECTED

int main(void)
{
    bool erase_bonds;
    log_init();
//	Data_Init();
    timers_init();
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    scheduler_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    sensor_simulator_init();
    conn_params_init();
    buffer_init();
    peer_manager_init();
    NRF_LOG_INFO("HID Keyboard example started.");
    timers_start();
    advertising_start(erase_bonds);
	uart_init();
    for (;;)
    {
        idle_state_handle();
    }
}

Rest things are just as is from ../peripheral/uart code.

I also made changes to sdkconfig.h

5355.sdk_config.h

Parents
  • I am having the same struggle. When I add

    static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_NUS_SERVICE, NUS_SERVICE_UUID_TYPE}};

    to the HID example it crashes things immediately. I understand that the HID is a 16 bit UUID and the NUS_SERVICE is a 32 bit UUID.

    I haven't figured out how to understand the error codes at this point. It is really frustrating. I followed the basic debugging tutorial but I keep getting a break point with a question mark? I am not sure where I turn optimization off at, I have tried to find it. I have been scouring these tutorials and posts but no luck piecing it together as of yet.

    Have you found a solution for this yet?

    SDK15.2, Segger Embedded

  • Hi,

    As wrote to , you need to debug the issue to understand what is going on first. Since you use SES, you should start by selecting the Debug build configuration in the dropdown usually located in the upper left of the screen. That will turn off optimization and define DEBUG. Then you should observe the log output (UART or RTT), and this will tell you if an error has been detected, and if so, where and with what error code. This is always the first step.

    Without seeing the error message, we can only guess, but generally, you need to adjust the memory configuration of the SoftDevice if you add more services, since it will need more RAM. It might be that you need to increase NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE or NRF_SDH_BLE_VS_UUID_COUNT in your projects sdk_config.h. Debugging will tell you which of these. Note that if you do, you also have to adjust the application RAM start address and size, since the SoftDevice RAM usage increases.

Reply
  • Hi,

    As wrote to , you need to debug the issue to understand what is going on first. Since you use SES, you should start by selecting the Debug build configuration in the dropdown usually located in the upper left of the screen. That will turn off optimization and define DEBUG. Then you should observe the log output (UART or RTT), and this will tell you if an error has been detected, and if so, where and with what error code. This is always the first step.

    Without seeing the error message, we can only guess, but generally, you need to adjust the memory configuration of the SoftDevice if you add more services, since it will need more RAM. It might be that you need to increase NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE or NRF_SDH_BLE_VS_UUID_COUNT in your projects sdk_config.h. Debugging will tell you which of these. Note that if you do, you also have to adjust the application RAM start address and size, since the SoftDevice RAM usage increases.

Children
Related