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

How to change ble_app_uart example to work without LFCLK?

I'm using SDK12 and SES.

I compiled my code based on ble_app_uart example for nRF51822_QFAA and I see in Memory usage that RAM is at correct addresses (finishes at 0x20003FFF). The code runs on PCA10028 but it doesn't run on my target board that has no 32.768kHz oscillator.

I can't find how to put the controller working without LFCLK. Can anyone give a hint?

It is frustrating that I loose 90% of time looking for solutions to put things running rather than coding... very poor documentation about examples cause this!

Parents
  • Hi,

    The clock is configured in the ble_stack_init() function in main.c of the ble_app_uart example, by this code:

        nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
    
        // Initialize SoftDevice.
        SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

    The NRF_CLOCK_LFCLKSRC is defined in the board file so to use the RC oscillator instead of the LFXC, you should either update that, or simply skip it and do like this:

        nrf_clock_lf_cfg_t clock_lf_cfg = {.source        = NRF_CLOCK_LF_SRC_RC,                \
    																			 .rc_ctiv       = 16,                                 \
                                           .rc_temp_ctiv  = 1,                                  \
                                           .xtal_accuracy = NRF_CLOCK_LF_XTAL_ACCURACY_250_PPM};
    
        // Initialize SoftDevice.
        SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);

  • Hi,

    What do you do in your power_manage() function? And what else do you do in your main loop?

    In most SDK examples it enters system ON low power mode, which essentially is putting the CPU to sleep waiting for an interrupt/event. If no interrupt or event occurs, then the CPU will stay in sleep forever. This is expected behavior.

  • The power_manage() function is original: it only has _WLE instruction and I don't know what it means. Note that the code includes a TIMER interrupt that is running because the clock function is working. Also, the code runs on the DK board...! I need to run in the lowest power possible because in case of power failure, the CPU runs on a battery, therefore I must have BLE OFF and only timer running. Can I achieve low power mode if I use power_manage()?

  • Hi,

    (this post also attempts to answer questions in a few of your other recent threads, which all seem related to the same root issue).

    The _WFE() instruction is a CPU instruction telling the CPU to wait for event (interrupt). See this explanation. It will not continue form that point unless there is an interrupt.

    Based on your many threads the last few days it seems to me that you have not debugged this issue, but are simply seeing that "it is not working". You need to understand what you are doing, and you must use a debugger to see what is happening on the target device.

    You can use the nRF51 DK as a debugger for debugging your custom board by using the Debug out connector in the upper left corner of the DK. See chapter 6.10 in the nRF51 Development Kit for details. Connect this to your custom board as described in section 6.10.1. Then you can debug in the exact same way as you do if you are using the nRF51 chip on the DK itself.

    Sergio T said:
    therefore I must have BLE OFF and only timer running.

    This tells me that you have not understood how the BLE stack works. Even if you have the BLE stack enabled, and even if it is in a connection, it the CPU will sleep most of the time, as long as you put it in low power mode (by calling  sd_app_evt_wait(), which cals __WFE() internally).

    There are too many open questions here. I suggest you start debugging and try to solve issues one by one. Once you have debugged, you will know a bit more. If you still need help, then please include details about how you have debugged and tested and upload your code so that we can see what you are doing. That will reduce the number of unknowns and make it much easier for us to help you.

  • Thanks for your explanation. 
    I succeeded to put the debugger working and my code now runs without problems. Also, I don't know why but now the power_manage() routine works fine.
    You are right, I don't know how BLE stack works! And I don't want to know more than what is necessary to make it work.

    In my application I must be able to switch BLE on (advertising and communicating if connected, as you say BOLE enabled) when mains is available and BLE off (no advertising, no power consumption or BLE disabled) when mains is not available. When OFF I need that the controller runs RTC1 with the lowest consumption possible because it will run on a CR2032 battery. Actually quite simple! The problem is your information is spread and I couldn't find any document where I can find the name of the relevant routines for the application level to call so that I can do what I need to do.

  • Hi,

    Sergio T said:
    And I don't want to know more than what is necessary to make it work.

    This is not a good starting point for a successful product. I really recommend you try to learn the basics of the technologies you are using, as that will probably result in a better product.

    Sergio T said:
    When OFF I need that the controller runs RTC1 with the lowest consumption possible because it will run on a CR2032 battery. Actually quite simple

    Yes, it is :) You get this out of the box with the SDK. If you want to wake up and do tasks based on RTC1, then I suggest you use the app timer library. This is a software library that use RTC1 to make an arbitrary number of easy to use low power timers.

     Note that if you disable advertising and disconnect any active BLE connection, then you will in practice have the same current consumption as the case you describe, where you have RTC1 enabled. Therefor I suggest that you avoid "disabling BLE" if that means disabling the SoftDevice. If you mean exactly what I wrote (don't advertise, don't maintain a connection, then that is OK.

Reply
  • Hi,

    Sergio T said:
    And I don't want to know more than what is necessary to make it work.

    This is not a good starting point for a successful product. I really recommend you try to learn the basics of the technologies you are using, as that will probably result in a better product.

    Sergio T said:
    When OFF I need that the controller runs RTC1 with the lowest consumption possible because it will run on a CR2032 battery. Actually quite simple

    Yes, it is :) You get this out of the box with the SDK. If you want to wake up and do tasks based on RTC1, then I suggest you use the app timer library. This is a software library that use RTC1 to make an arbitrary number of easy to use low power timers.

     Note that if you disable advertising and disconnect any active BLE connection, then you will in practice have the same current consumption as the case you describe, where you have RTC1 enabled. Therefor I suggest that you avoid "disabling BLE" if that means disabling the SoftDevice. If you mean exactly what I wrote (don't advertise, don't maintain a connection, then that is OK.

Children
Related