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

LED Handling UART

Hello All,

I am designing one custom board where i want to Handle the LEDS, Like in Nrf51DK when we connect through UART_APP from smartphone blinking LED1 on DK gets constant. Where in the program i can control the LED.?

thanks in advance and for your time and help

Parents
  • Hi Pavan!

    I don't know what SDK you are working with. But I have based my answer on the ble_app_uart example in SDK v12.3.0 (Although it might not be any difference from earlier versions.)

    How the LED 1 is behaving is handled multiple places. One example is the function in your code that handles the advertising events:

    static void on_adv_evt(ble_adv_evt_t ble_adv_evt)  
        uint32_t err_code;
        switch (ble_adv_evt)
        {
            case BLE_ADV_EVT_FAST:
                err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING);
                APP_ERROR_CHECK(err_code);
                break;
            case BLE_ADV_EVT_IDLE:
                sleep_mode_enter();
                break;
            default:
                break;
        }
    

    There you can see that when the event BLE_ADV_EVT_FAST is passed to your application,
    err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING) will make LED 1 indicate that the device is advertising.

    There is also a function in your code that handles the application's SoftDevice events. Here is a small snipped:

    static void on_ble_evt(ble_evt_t * p_ble_evt)
        uint32_t err_code;
        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GAP_EVT_CONNECTED:
                err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
                APP_ERROR_CHECK(err_code);
                m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
                break; // BLE_GAP_EVT_CONNECTED
        }
    

    There you can see that LED 1 will indicate that the device is in a connected state when receiving the BLE_GAP_EVT_CONNECTED event. You can change how the LEDs will behave in these event handlers. Else you can remove it from the event handlers, and define how the LEDs should behave somewhere else in your code. You can read more about the predefined BSP indication states here. You can also change the advertising LED in bsp_config.h:

    #define BSP_LED_INDICATE_INDICATE_ADVERTISING BSP_BOARD_LED_0
    

    However, when making your own custom board, there would be a few things to keep in mind if you want to use the Board Support Package (BSP). The easiest way to control the LEDs on a custom board would probably be to use the nrf_gpio interface directly. You can read more about how to do this in this answer.

    This turned out to be a pretty general answer, as I don't know exactly what you want to do. If you have any more specific problems, you are welcome to ask in the comments below.

    Best regards,
    Joakim

  • Dear Sir,

    Thank you for your information.

    I am also using same SDK on my board , Actually my requirement is like when i power on the board LED should start blinking i.e which indicates the advertising mode. when i connect through the smartphone app lets say using UART_BLE app LED should in GLOW(on) state until i disconnect . do you have any code for such application?

Reply Children
No Data
Related