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

[nrf_gpio/app_gpiote/nrf_drv_gpiote]

Hello Nordic,

I am following example code [--ble-app-lbs-master] for my application in (keil4.6/sdk8.0.0). Its already consisting (app_gpiote), but I want to add some code module which refer (nrf_drv_gpiote). Is it compulsory to use both files or only file can be used instead of two? How can I do so?

I tried to follow some previous posts but didn't get it well. Also, I am unable to see the icon for "run-time-environment" and "software-pack" icons (showing disabled) in Keil4.6.

Please suggest~

/Thanks n Regards

  • Hi

    You can not use both app_gpiote and nrf_drv_gpiote. Both modules use the GPIOTE interrupt directly and that will result in a conflict between the two modules. You must decide if you prefer to port the ble_app_lbs_master to use nrf_drv_gpiote or if you port the code module in question to use app_gpiote.

    Porting the code module to use app_gpiote should not be hard. The following example is the ble_app_template example from SDK 8.0.0 with one button sensing added with help from app_gpiote library. When operated on PCA10028 and button 1 is pressed, LED 2 will blink. LED 1 is also lid to show that the board is advertising.

    ble_app_template_with_gpiote_setup.zip

    The app_gpiote code needed to configure a single button is:

    static app_gpiote_user_id_t           m_gpiote_user_id;
    
    nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLUP);   //Configure button pin as input
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);               //Only initialize once. Increase value of APP_GPIOTE_MAX_USERS if needed
    
    err_code = app_gpiote_user_register(&m_gpiote_user_id, 1 << BUTTON_1, 1 << BUTTON_1, gpiote_event_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = app_gpiote_user_enable(m_gpiote_user_id);
    APP_ERROR_CHECK(err_code);
    

    and the definition of the registered app_gpiote event handler which blinks the led:

    void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
    {
      nrf_gpio_pin_toggle(LED_2);
    }
    

    Update 14.8.2015 I think pack support was introduced in Keil first in version 5.x. I would recommend for you to update Keil.

    Update 20.8.2015 I also atttach an example that implements an extra app_timer. Look at the timer_init() function and application_timers_start() function. I added the "m_adc_sampling_timer_id" timer. You could do the same in your application. I have also added adc_sampling_timeout_handler which is called whenever the timer triggers. There you can write to an array and eventually check that array with a breakpoint when you have collected sufficient number of signal samples. Also remember to increase the number of APP_TIMER_MAX_TIMERS constant in order to make the extra timer work. LED_2 is toggled in the timer handler to indicate that the timer works. I have implemented this example for SDK 7.2.0, but the app_timer code should work also for SDK 8.0.0

    ble_app_bps_with_extra_app_timer.zip

    Update 24.8.2015 Here is the same example that should run directly with nRF51 SDK 8.0.0

    ble_app_bps_with_extra_app_timer__SDK_8_0_0.zip

    Update 28.8.2015 The nrf51_ble_app_lbs example uses app_button library to detect a button press. The app_button uses debounce function. The debounce function of app_button library implementation is the following procedure:

    • When a configured button is pressed, the app_button library starts a timer, with a configurable timeout.
    • when the timer times out, the state of the pressed pin is read, and an event is generated for the application which executes the registered app_button event handler.
    • The app_button event handler receives the button state which tells if the button was pressed or released.

    In order to sample the state of the configured pin, I would suggest to configure the app_button in a normal way as already done in the nrf51_ble_app_lbs example. Just set the BUTTON_DETECTION_DELAY very short in order to receive the button event (the button_event_handler in the nrf51_ble_app_lbs example) as soon as possible after button is actually pressed. When the button is pressed and an event is received in the button event handler , read the pin state multiple times and write it to an array. Read the pin value with

    nrf_gpio_pin_read(LEDBUTTON_BUTTON_PIN_NO);
    

    as done in this example. If desired, you could have e.g. 1us delay between sampling the pin by calling

    nrf_delay_us(1); 
    

    which is defined in the nrf_delay.h file. When you have filled up the array, check if all values are identical. If they are not identical, start an app_timer (use the ble_app_bps_with_extra_app_timer__SDK_8_0_0.zip example to figure out how to do that) where the app_timer event handler will repeat the same procedure, i.e. sample the same pin multiple times and then check if all values are identical. Restart the timer until the pin signal is stable.

  • Thanks @Stefan Birnir Sverrisson for well explained reply~

    I am trying to port the button bounce example [https://github.com/NordicSemiconductor/nrf51-app-button-example] with [--ble-app-lbs-master-- example] to observe the button bounce phenomenon. How can I manage "gpiote" in this case. Please highlight.

    Thanks

  • Hi HSA

    I assume you are referring to the ble_app_lbs example found on Github, am I correct. If so, this example already uses the app_button library which implements the button debounce function. So I am puzzled about why you need to integrate the nrf_app_button_example.

    Anyway, both ble_app_lbs and nrf_app_button_example are made for nRF51 SDK 8.0.0. Since both examples use the same SDK version, they both use app_gpiote and not nrf_drv_gpiote. It is first in SDK 8.1.0 that the app_button library starts to use nrf_drv_gpiote.

  • Hi @Stefan Birnir Sverrisson, Thanks for your comment. Yes, I am referring [--ble_app_lbs_example--], also, its not using nrf_drv_gpiote.x. I am just trying on my behalf to check the button_debounce working phenomenon. I want to read the pin status, when button bounc-debounce occurs.

    1. What is the need to add nrf_drv_gpiote.x in SDK8.1.0 and later versions....

    2. If the above mentioned example already having button bounce-debounce functionality, then please let me know how can I read the pin state to know the bounce-debounce. How can I see the effect of this bouncing-debouncing in this example?

    How can I read the pin state to check the bouncing-debouncing something like [0..1..0..1..0..1..1..1..1..0..1..0..1..0] when button pressed. As per my information so far, timer always check the pin status when button start pressing and keep checking the states until its get stable....isnt?

    Please suggest. Thanks a lot.

    Regards/

  • Hi HSA

    I think the debounce function in app_button is very simple. When a button is pushed the app_button library does not check the status of the pin right away, but instead starts a timer to read the status of the pin at a later time. When the timer expires, the pin state is recorded and reported to the application.

    As we discussed on your previous thread, you can read a pin state manually. You could manually set up a recurrent app_timer to read the pin state sequentially to see how the pin state behaves after pressing the pin, and report that status out on UART or RTT. That is what you want to do, am I correct?

Related