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? 

  • Hello, 

    The technical support team is currently low staffed due to Christmas holidays and the response time is therefor much longer than usual.


    Please provide more information on what SDK you are using, and what application you are running. 

    Thank you!  

    Kind regards,
    Øyvind

  • I'm using SDK 17.0.2. I'm trying to send accelerometer data through BLE. I followed BLE characteristics tutorial to develop my project. The code works fine, the problem occurs when I include the accelerometer read function in the code.To verify the problem, instead of sending accelerometer data, I sent dummy data. The data received without a problem. When I include my sensor read function into the code, the problem occurs. I have included the sniffer packets below, please have a look at them.                 

    sniffer1.pcapng

  • If MPU6050_ReadAcc(AccValue) crashes, or if it takes too much time to perform, that could explain why your device disconnects.

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

  • 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)

Related