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

Adding accelerometer value to own service

Hi, Im trying to add accelerometer value to my own service. The device is advertising, When I connect to the nRF Connect application, I can not see my service, the status says disconnected. 

This is the timer event handler I use in the program

static void timer_timeout_handler(void * p_context)
{
// Acquire accelerometer data
MPU6050_ReadAcc(AccValue); // accelerometer read
acc[0] = AccValue[0];
acc[1] = AccValue[1];
acc[2] = AccValue[2];

characteristic_accel_update(&m_our_service, acc);
}

If I  line comment my accelerometer read function, The app works fine, I can see the service and its characters at the nrf connect (without accel values). How can I include my accelerometer read function into my program without crashing the app? 

Parents Reply Children
  • I can run a debugger. RTT on debugger terminal shows this,

    <info> app_timer: RTC: initialized.
    <debug> nrf_sdh: State request: 0x00000000
    <debug> nrf_sdh: Notify observer 0x00030234 => ready
    <debug> nrf_sdh: State change: 0x00000000
    <debug> nrf_sdh: State change: 0x00000001
    <debug> nrf_sdh_ble: RAM starts at 0x20002260
    <info> app: started.
    <info> app: Fast advertising.

    Nothing after this.

    If you can't run a debugger, could you raise a GPIO line before calling it, and lower that line upon return?

    I don't understand what you are trying to say. Can you please explain a little more elaborately?

  • With a debugger, set a breakpoint after your call to MPU6050_ReadAcc() and see if it is hit (or not; if you are in "DEBUG" mode the program will enter a loop).

    Or, put an NRF_LOG_INFO() trace message before and after your call to MPU6050_ReadAcc(), to confirm your program flow... does your routine return, or do you fall into a crash-loop?

    My "GPIO line" suggestion is moot, since you can run a debugger and see log outputs (if you couldn't, I was suggesting that you could control a GPIO pin, and watch it with an oscilloscope or logic analyzer, to determine whether or not your code was hit, and if there was a reasonably short or unreasonably long time taken to run your accelerometer reading routine)

  • If I enable the accelerometer read function, I can not connect the device with the nrf connect app. The device stays in advertising mode. The program does not enter the timer_timout_handler where the accelerometer function is called. 

    I think my twi configuration is interrupting softdevice. I changed the interrupt priority from high to low and medium. Nothing works. Do you have any suggestions? I can share my code if necessary.

  • Im happy to say that the project is complete. Thank you for your support. You may close this ticket.

Related