Hi all,
I am working on a new project and I need to communicate to a sensor using I2C, then save the data on a flash (files visible on windows as mass storage via USB) and also sending UART data via BLE.
I modified the USBD_MSC SDK example to acquire the data and save them on the flash and make the files visible from windows via USB and it works as expected.
Then I modified the ble_app_uart SDK example (peripheral one) to acquire the data and send it via BT UART and it works as expected.
Now I am trying to merge the two modified working examples to have all the functionalities but the debugger stops during the uart_init() and log_init() functions with error.
I think that it is because first I initialize the UART to work with USB and then I try to initialize it a second time for BLE communication.
What is the right way to initialize all functionalities to implement both USB and BLE communication?
Following the merged code.
int main(void) { ret_code_t err_code; ret_code_t ret; static const app_usbd_config_t usbd_config = { .ev_state_proc = usbd_user_ev_handler }; ret = NRF_LOG_INIT(app_usbd_sof_timestamp_get); APP_ERROR_CHECK(ret); NRF_LOG_DEFAULT_BACKENDS_INIT(); ret = nrf_drv_clock_init(); APP_ERROR_CHECK(ret); nrf_drv_clock_lfclk_request(NULL); while(!nrf_drv_clock_lfclk_is_running()) { /* Just waiting */ } nrf_delay_ms(500); ret = app_timer_init(); APP_ERROR_CHECK(ret); fatfs_init(); ret = app_usbd_init(&usbd_config); APP_ERROR_CHECK(ret); app_usbd_class_inst_t const * class_inst_msc = app_usbd_msc_class_inst_get(&m_app_msc); ret = app_usbd_class_append(class_inst_msc); APP_ERROR_CHECK(ret); NRF_LOG_INFO("USBD MSC example started."); ret = app_usbd_power_events_enable(); APP_ERROR_CHECK(ret); twi_init(); nrf_delay_ms(500); // Initialize. uart_init(); log_init(); timers_init(); power_management_init(); ble_stack_init(); gap_params_init(); gatt_init(); services_init(); advertising_init(); conn_params_init(); // Start execution. advertising_start();
Thank you very much.
Best regards.
Luca