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!