The led is not blinking or turning on in nrf52840 dk board

Hi I am trying to do the led blinking in nrf52840 but the led is not even turning on i have given the code below can any body help me out.

nrf_gpio_cfg_output(14);

nrf_gpio_cfg_output(15);

nrf_gpio_cfg_output(16);
nrf_gpio_cfg_output(13);
while (true)
{

nrf_gpio_pin_clear(13);
nrf_gpio_pin_set(14);
nrf_gpio_pin_set(15);
nrf_gpio_pin_set(16);
printf("Ae\r\n");
nrf_delay_ms(100);

}

Parents
  • thankyou for the reply i am just trying to just on the first led which is given to 13 my full code is as follows even i tried the led blinky example though the led is not blinking. the below is my full code for led burning but it is not working

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "nrf.h"
    #include "bsp.h"


    #include "nrf_drv_ppi.h"
    #include "nrf_drv_timer.h"


    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"

    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif


    //#define ENABLE_LOOPBACK_TEST /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */

    #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */

    void uart_error_handle(app_uart_evt_t * p_event)
    {
         if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
    APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
    APP_ERROR_HANDLER(p_event->data.error_code);
    }
    }


    #ifdef ENABLE_LOOPBACK_TEST
    /* Use flow control in loopback test. */
    #define UART_HWFC APP_UART_FLOW_CONTROL_ENABLED

    /** @brief Function for setting the @ref ERROR_PIN high, and then enter an infinite loop.
    */
    static void show_error(void)
    {

    bsp_board_leds_on();
    while (true)
    {
    // Do nothing.
    }
    }


    /** @brief Function for testing UART loop back.
    * @details Transmitts one character at a time to check if the data received from the loopback is same as the transmitted data.
    * @note @ref TX_PIN_NUMBER must be connected to @ref RX_PIN_NUMBER)
    */
    static void uart_loopback_test()
    {
    uint8_t * tx_data = (uint8_t *)("\r\nLOOPBACK_TEST\r\n");
    uint8_t rx_data;

    // Start sending one byte and see if you get the same
    for (uint32_t i = 0; i < MAX_TEST_DATA_BYTES; i++)
    {
    uint32_t err_code;
    while (app_uart_put(tx_data[i]) != NRF_SUCCESS);

    nrf_delay_ms(10);
    err_code = app_uart_get(&rx_data);

    if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
    {
    show_error();
    }
    }
    return;
    }
    #else
    /* When UART is used for communication with the host do not use flow control.*/
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    #endif


    /**
    * @brief Function for main application entry.
    */


    int main(void)
    {
    uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    const app_uart_comm_params_t comm_params =
    {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    UART_HWFC,
    false,
    #if defined (UART_PRESENT)
    NRF_UART_BAUDRATE_115200
    #else
    NRF_UARTE_BAUDRATE_115200
    #endif
    };

    APP_UART_FIFO_INIT(&comm_params,
    UART_RX_BUF_SIZE,
    UART_TX_BUF_SIZE,
    uart_error_handle,
    APP_IRQ_PRIORITY_LOWEST,
    err_code);

    APP_ERROR_CHECK(err_code);

    #ifndef ENABLE_LOOPBACK_TEST
    printf("\r\nUART example started.\r\n");


    nrf_gpio_cfg_output(13);
    NRF_LOG_INFO("SAADC HAL simple example started.");
    while (true)
    {

    nrf_gpio_pin_clear(13);

    printf("Ae\r\n");
    nrf_delay_ms(100);

    }
    #else

    // This part of the example is just for testing the loopback .
    while (true)
    {
    uart_loopback_test();
    }
    #endif
    }

Reply
  • thankyou for the reply i am just trying to just on the first led which is given to 13 my full code is as follows even i tried the led blinky example though the led is not blinking. the below is my full code for led burning but it is not working

    #include <stdbool.h>
    #include <stdint.h>
    #include <stdio.h>
    #include "app_uart.h"
    #include "app_error.h"
    #include "nrf_delay.h"
    #include "nrf_gpio.h"
    #include "nrf.h"
    #include "bsp.h"


    #include "nrf_drv_ppi.h"
    #include "nrf_drv_timer.h"


    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"

    #if defined (UART_PRESENT)
    #include "nrf_uart.h"
    #endif
    #if defined (UARTE_PRESENT)
    #include "nrf_uarte.h"
    #endif


    //#define ENABLE_LOOPBACK_TEST /**< if defined, then this example will be a loopback test, which means that TX should be connected to RX to get data loopback. */

    #define MAX_TEST_DATA_BYTES (15U) /**< max number of test bytes to be used for tx and rx. */
    #define UART_TX_BUF_SIZE 256 /**< UART TX buffer size. */
    #define UART_RX_BUF_SIZE 256 /**< UART RX buffer size. */

    void uart_error_handle(app_uart_evt_t * p_event)
    {
         if (p_event->evt_type == APP_UART_COMMUNICATION_ERROR)
    {
    APP_ERROR_HANDLER(p_event->data.error_communication);
    }
    else if (p_event->evt_type == APP_UART_FIFO_ERROR)
    {
    APP_ERROR_HANDLER(p_event->data.error_code);
    }
    }


    #ifdef ENABLE_LOOPBACK_TEST
    /* Use flow control in loopback test. */
    #define UART_HWFC APP_UART_FLOW_CONTROL_ENABLED

    /** @brief Function for setting the @ref ERROR_PIN high, and then enter an infinite loop.
    */
    static void show_error(void)
    {

    bsp_board_leds_on();
    while (true)
    {
    // Do nothing.
    }
    }


    /** @brief Function for testing UART loop back.
    * @details Transmitts one character at a time to check if the data received from the loopback is same as the transmitted data.
    * @note @ref TX_PIN_NUMBER must be connected to @ref RX_PIN_NUMBER)
    */
    static void uart_loopback_test()
    {
    uint8_t * tx_data = (uint8_t *)("\r\nLOOPBACK_TEST\r\n");
    uint8_t rx_data;

    // Start sending one byte and see if you get the same
    for (uint32_t i = 0; i < MAX_TEST_DATA_BYTES; i++)
    {
    uint32_t err_code;
    while (app_uart_put(tx_data[i]) != NRF_SUCCESS);

    nrf_delay_ms(10);
    err_code = app_uart_get(&rx_data);

    if ((rx_data != tx_data[i]) || (err_code != NRF_SUCCESS))
    {
    show_error();
    }
    }
    return;
    }
    #else
    /* When UART is used for communication with the host do not use flow control.*/
    #define UART_HWFC APP_UART_FLOW_CONTROL_DISABLED
    #endif


    /**
    * @brief Function for main application entry.
    */


    int main(void)
    {
    uint32_t err_code;

    bsp_board_init(BSP_INIT_LEDS);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    const app_uart_comm_params_t comm_params =
    {
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    UART_HWFC,
    false,
    #if defined (UART_PRESENT)
    NRF_UART_BAUDRATE_115200
    #else
    NRF_UARTE_BAUDRATE_115200
    #endif
    };

    APP_UART_FIFO_INIT(&comm_params,
    UART_RX_BUF_SIZE,
    UART_TX_BUF_SIZE,
    uart_error_handle,
    APP_IRQ_PRIORITY_LOWEST,
    err_code);

    APP_ERROR_CHECK(err_code);

    #ifndef ENABLE_LOOPBACK_TEST
    printf("\r\nUART example started.\r\n");


    nrf_gpio_cfg_output(13);
    NRF_LOG_INFO("SAADC HAL simple example started.");
    while (true)
    {

    nrf_gpio_pin_clear(13);

    printf("Ae\r\n");
    nrf_delay_ms(100);

    }
    #else

    // This part of the example is just for testing the loopback .
    while (true)
    {
    uart_loopback_test();
    }
    #endif
    }

Children
  • Nagaraj JP said:
    thankyou for the reply

    No problem at all, I am happy to help!

    Nagaraj JP said:
    i am just trying to just on the first led which is given to 13 my full code is as follows even i tried the led blinky example though the led is not blinking.

    Please use the Insert -> Code option when sharing code on the forum. This drastically increases its readability.
    Are you saying that you tried the Blinky example, but it did not work? Did you not see the leds blink in sequence? Could you confirm that the program was successfully flashed and running on your DK?

    Best regards,
    Karl

Related