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

BLE with SPI doesn´t reconnect once bluetooth has been disabled and enabled again.

I'm currently working with nrf52832 implementing bluetooth and spi functionalities. The bluetooth connection to PC is working fine, it connects and after that starts transfering and receiving data from SPI slave. The problem comes once I decide to turn bluetooth off on the PC. It connects and disconnects constantly. It also happens once I turn off/on the power button on the SDK.

Here it is the main code and the spi configuration:

int main(void)
{
    bool erase_bonds;


    ret_code_t err_code;

    spi_configuration();

    APP_ERROR_CHECK(nrf_drv_clock_init());
    nrf_drv_clock_lfclk_request(NULL);
    
    log_init();
    

    err_code = app_timer_init();
    APP_ERROR_CHECK(err_code);


    motion_timer_init();

 
    // Initialize.
    buttons_leds_init(&erase_bonds);
    power_management_init();
    ble_stack_init();
    scheduler_init();
    gap_params_init();
    gatt_init();
    advertising_init();
    services_init();
    conn_params_init();
    peer_manager_init();
    bsp_board_init(BSP_INIT_LEDS);

    // Start execution.
    advertising_start(erase_bonds);

    // Enter main loop.
    for (;;)
    {
      if(connected){
        NRF_LOG_INFO("Connected.");

        laser_frame();  //transfer and receive spi data
       
      }

      idle_state_handle();
      nrf_delay_ms(2000);
    }
}


void spi_configuration(void){
  /* SPI Configuration */
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;
    spi_config.ss_pin   = SPI_SS_PIN;
    spi_config.miso_pin = SPI_MISO_PIN;
    spi_config.mosi_pin = SPI_MOSI_PIN;
    spi_config.sck_pin  = SPI_SCK_PIN;

    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler, NULL));

}

If spi_configuration() and laser_frame() are commented, the problem when reconnecting disappears. Any idea? Thanks!

Parents
  • Also, when I power off and then on the sdk, I get the following in loop:

    <info> app:     m_whitelist_peer_cnt 1, MAX_PEERS_WLIST 8

    <info> app: Fast advertising.

    <info> app: Connected   (the loop starts from this point)

    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102

    <info> app: Connected.

    <info> app: Fast advertising.

    <info> app: Disconnected

    <info> app: Connected

    In the PC side I appreciate that Bluetooth connection is alternating from paired to connected states.

Reply
  • Also, when I power off and then on the sdk, I get the following in loop:

    <info> app:     m_whitelist_peer_cnt 1, MAX_PEERS_WLIST 8

    <info> app: Fast advertising.

    <info> app: Connected   (the loop starts from this point)

    <info> peer_manager_handler: Connection security failed: role: Peripheral, conn_handle: 0x0, procedure: Encryption, error: 4102

    <info> app: Connected.

    <info> app: Fast advertising.

    <info> app: Disconnected

    <info> app: Connected

    In the PC side I appreciate that Bluetooth connection is alternating from paired to connected states.

Children
No Data
Related