This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

BLE blinky using NRF Connect SDK

Hi 

 I need to Send one character from mobile. based on the character I need to glow the LEDs which is placed on DK. How can I achieve this is there any sample available for reference?

Thanks & Regards

Navin

  • Hi Navin,

    I recommend you use the ble/peripheral_uart sample, and merge it with this UART topic from Nordics Academy where you can toggle the lights with input from a terminal.
    Check these samples out one by one first before you merge them and see they work. Then move on to integrating the functions from the Academy-sample into the peripheral sample.

    Let me know if this is of any help!

    Kind regards,
    Andreas

  • Hi andreas,

    I have already checked those sample. Actually, i don't know where the data is received in that from ble. If I understand that i can do it other things.

    Thanks & Regards,

    Navin

  • Hi Navin,

    Mr.NCK said:
    I have already checked those sample.

    Thats good.

    Mr.NCK said:
    Actually, i don't know where the data is received in that from ble.

    I am not sure if I understand what you mean by this, so I am going to answer the two things I think you might be meaning. Please correct me if I have misunderstood.

    1) Did you mean that you built, flashed and tried the "Testing" steps in the sample and did not see any data? 

    2) Did you mean that you don't see where in the code the ble data is sent? If so, the received part of the code can be seen at line 451 in function "static void bt_receive_cb(...)"  the sample, which uses Nordic UART Service (NUS), where you can see more details on how to receive the data in nus.c.

    Let me know if this helped clarify things for you or if I misunderstood what you did not understand.

    Kind regards,
    Andreas

  • HI andreas,

     Point 2 was right, I have check the below mentioned lines

    static void bt_receive_cb(struct bt_conn *conn, const uint8_t *const data,
    uint16_t len)
    {
    int err;
    char addr[BT_ADDR_LE_STR_LEN] = {0};

    bt_addr_le_to_str(bt_conn_get_dst(conn), addr, ARRAY_SIZE(addr));

    LOG_INF("Received data from: %s", log_strdup(addr));

    for (uint16_t pos = 0; pos != len;) {
    struct uart_data_t *tx = k_malloc(sizeof(*tx));

    if (!tx) {
    LOG_WRN("Not able to allocate UART send data buffer");
    return;
    }

    /* Keep the last byte of TX buffer for potential LF char. */
    size_t tx_data_size = sizeof(tx->data) - 1;

    if ((len - pos) > tx_data_size) {
    tx->len = tx_data_size;
    } else {
    tx->len = (len - pos);
    }

    memcpy(tx->data, &data[pos], tx->len);

    pos += tx->len;

    /* Append the LF character when the CR character triggered
    * transmission from the peer.
    */
    if ((pos == len) && (data[len - 1] == '\r')) {
    tx->data[tx->len] = '\n';
    tx->len++;
    }

    err = uart_tx(uart, tx->data, tx->len, SYS_FOREVER_MS);
    if (err) {
    k_fifo_put(&fifo_uart_tx_data, tx);

    }

    }
    }

    In the above lines, where can I check the received values? Kindly explain the flow.

    Thanks & Regards

    Navin

  • Hi,

    The function that sends the bytes through UART is uart_tx(..). You can check the values by performing the steps in the testing part of the documentation for the sample aswell as reading up on how tx and rx in UART works in this thorough guide

    Kind regards 

    Andreas

Related