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

Parents
  • Hi, I did tried placing the loop in both the main and separate c file but both are not working. And yes, I did debugging using J-link. When the for loop is placed in main.c, I am able to initialise everything and return back to main but when I connect, it does not go into the on_ble_evt function case of BLE_GAP_EVT_CONNECTED to print a statement. Writing to it is not possible. When the for loop is placed in the separate BLE communication file, the same thing happens as above, except that it is not return back to main this time. No error codes were returned anywhere.

Reply
  • Hi, I did tried placing the loop in both the main and separate c file but both are not working. And yes, I did debugging using J-link. When the for loop is placed in main.c, I am able to initialise everything and return back to main but when I connect, it does not go into the on_ble_evt function case of BLE_GAP_EVT_CONNECTED to print a statement. Writing to it is not possible. When the for loop is placed in the separate BLE communication file, the same thing happens as above, except that it is not return back to main this time. No error codes were returned anywhere.

Children
No Data
Related