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

Applying Timer Example to Uart Example

Hi.

Thank you for your hard work.

I would like to apply the Timer example to the Uart example in SDK 15.2.0.

It was able to build without any problems before the timer was applied, but there are some problems after the application of timer example.

For your information, The model I use is nRF52840 Dongle.

To solve this problem, In sdk_config.h, I set the value of "TIMER_ENABLE",  "TIMER1_ENABLE" to 1 and make a instance with this method "NRF_DRV_TIMER_INSTANCE(1)".

Contents of error is

implicit declaration of function 'nrf_drv_timer_init'; did you mean 'nrf_drv_timer_uninit'? [-Wimplicit-function-declaration]

Output/ble_app_uart_pca10056_s140 Release/Obj/main.o: in function `main':

undefined reference to `nrf_drv_timer_init'

C:\nRF5_SDK_15.2.0_modified\examples\ble_peripheral\ble_app_uart/main.c:757: undefined reference to `nrfx_timer_extended_compare'

C:\nRF5_SDK_15.2.0_modified\examples\ble_peripheral\ble_app_uart/main.c:759: undefined reference to `nrfx_timer_enable'

The example code I brought and used is as follows.

#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_timer.h"
#include "bsp.h"
#include "app_error.h"

const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(1);

/**
 * @brief Handler for timer events.
 */
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
    static uint32_t i;
    uint32_t led_to_invert = ((i++) % LEDS_NUMBER);

    switch (event_type)
    {
        case NRF_TIMER_EVENT_COMPARE0:
            bsp_board_led_invert(led_to_invert);
            break;

        default:
            //Do nothing.
            break;
    }
}


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
    uint32_t time_ticks;
    uint32_t err_code = NRF_SUCCESS;

    //Configure all leds on board.
    bsp_board_init(BSP_INIT_LEDS);

    //Configure TIMER_LED for generating simple light effect - leds on board will invert his state one after the other.
    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
    APP_ERROR_CHECK(err_code);

    time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);

    nrf_drv_timer_extended_compare(
         &TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    nrf_drv_timer_enable(&TIMER_LED);

    while (1)
    {
        __WFI();
    }
}

I checked the related Q&A on this homepage, but there was no result.

I would appreciate your reply.

Thank you for read it.

Parents Reply Children
Related