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

Cannot call my function inside the SoftDevice ble_evt_handler: ble_evt_dispatch()

Hi,

I'm using nRF51822 in my senior project (some kind of BLE wearable device).

I'm trying to call my function inside the ble_evt_dispatch() function but it doesn't work. My function was called but it's never returned.

static void ble_evt_dispatch(ble_evt_t * p_ble_evt) // this function is called by SoftDevice
{
    dm_ble_evt_handler(p_ble_evt);
    ble_conn_params_on_ble_evt(p_ble_evt);
    on_ble_evt(p_ble_evt);
    ble_advertising_on_ble_evt(p_ble_evt);

    printf("Hello\n");    // I can print some text.
    test_function();      // I can even call my other functions.
    mpuGetAccel(x, y, z); // But this function nerver returned.
}

The function is used to get sensors' value. It uses TWI to talk to the sensors. If I put the function somewhere else, it works.

int main(void)
{
    // some initialization ...

    mpuGetAccel(x, y, z); // put the function here, works!!

    while (true) {
        power_manage(); // wait for a BLE event.

        mpuGetAccel(x, y, z); // put the function here, works too!!
    }

    return 0;
}

This is a part of mpuGetAccel() implementation.

uint8_t size;
uint8_t errCode;

buffer[0] = regAddr;

app_twi_transfer_t const transfers[] =
{
    APP_TWI_WRITE(MPU9250_ADDR, buffer, 1, 0),
    APP_TWI_READ(MPU9250_ADDR, buffer, 1, 0)
};

size = sizeof(transfers) / sizeof(transfers[0]);

if ((errCode = app_twi_perform(&m_app_twi, transfers, size, NULL)) != NRF_SUCCESS) {
    printf("TWI Perform Error: %d\n", errCode);
    return false;
}

return true;

Has anyone got this problem before? Does it has something to do with Interrupt or TWI scheduler? If so, do you have any suggestion?


By the way, these are my source code.

main.c helmet_sensor_unit_service.h helmet_sensor_unit_service.c mpu9250.h mpu9250.c

Related