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

ble communication in a separate C file

I would like to separate the BLE communication from the main.c and place it to a separate file. I followed the example of the default ble_app_template as well as nordic's services tutorial to create the BLE. It is working perfectly well when calling of it is from main.c.

However, when I tried to put the BLE main initialization and stuff at a separate file, the code is able to compile and download but it is not working as intended. The problem seems to be the for loop here:

for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }

I tried placing it either at main.c or the separated BLE file and it still does not make BLE work as intended. It does advertise itself and my app can connect to it, but nothing else such as read or write can be done (previously was working when in main.c file).

In the separate BLE file meant for BLE communication, the following are done:

void ble_com(void)
{
    uint32_t err_code;
    
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    APP_ERROR_CHECK(err_code);
    
    for (;;)
    {
        if (NRF_LOG_PROCESS() == false)
        {
            power_manage();
        }
    }
}

I am using IAR workbench with nRF51DK. Pleas help, thank you.

Edit: Uploaded the ble and main files. ble_comm.c main.c

Related