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 periheral uart

Hi,

On the nRF5340-DK, i'm succesfuly using the example code:

https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/samples/bluetooth/peripheral_uart/README.html

..now i would like to alter some..

in the    void ble_write_thread(void), 

I would like just to send some test data  (using the bt_nus_send()  ),  So not using the fifo_rx_data.

Therefore  i would like, NOT use the waiting for   uart data :    ( struct uart_data_t *buf = k_fifo_get(&fifo_uart_rx_data,  K_FOREVER); )

Directly using    bt_nus_send()  is not OK.
it is necessary to have in the nRF-connect app,  to enable the notify of the TX-Characteristic.
So i must DETECT the Enabled Tx Charateristic first, after that i can use the    bt_nus_send()
The question:  How to dectect (within this periheral uart code)    that the    TX-Characteristic is enabled ??
Best Regards,
Theo
NOTE: Using the uart..  , in the nRF-connect app you first have to enable the TX-Characteristic, then you fill in some data, then the     fifo_rx_data  becomes filled, therfore in this case   bt_nus_send()  works.

  • Hello,

    If your question is in fact how to know when the central has enabled the notifications for your tx characteristic, then please check out nus.c, and see where the service is declared using:

    /* UART Service Declaration */
    BT_GATT_SERVICE_DEFINE(nus_svc,
    BT_GATT_PRIMARY_SERVICE(BT_UUID_NUS_SERVICE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_TX,
    			       BT_GATT_CHRC_NOTIFY,
    			       BT_GATT_PERM_READ,
    			       NULL, NULL, NULL),
    	BT_GATT_CCC(nus_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
    	BT_GATT_CHARACTERISTIC(BT_UUID_NUS_RX,
    			       BT_GATT_CHRC_WRITE |
    			       BT_GATT_CHRC_WRITE_WITHOUT_RESP,
    			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE,
    			       NULL, on_receive, NULL),
    );

    On the line BT_GATT_CCC(nus_ccc_cfg_changed, BT_GATT_PERM_READ | |BT_GATT_PERM_WRITE), nus_ccc_cfg_changed is the callback whenever notifications are enabled/disabled for the TX characteristic. Looking at this callback which is implemented in the same file (nus.c), it will trigger a callback if the callback nus_cb.send_enabled() is set.

    This is set in bt_nus_init(). 

    Looking at where bt_nus_init() is called from main.c, you can see that nus_cb is also declared in main.c:

    static struct bt_nus_cb nus_cb = {
    	.received = bt_receive_cb,
    };

    however, only the .received is populated, and hence the .send_enabled() callback is not pupulated, and not called when the nus_ccc_cfg_changed is triggered.

    Try replacing:

    static struct bt_nus_cb nus_cb = {
    	.received = bt_receive_cb,
    };

    with:

    void bt_send_enabled(enum bt_nus_send_status status)
    {
        LOG_INF("notification callback");
        LOG_INF("notifications %s", (status==BT_NUS_SEND_STATUS_ENABLED)?"enabled":"disabled");
    }
    
    static struct bt_nus_cb nus_cb = {
    	.received = bt_receive_cb,
        .send_enabled = bt_send_enabled,
    };

    It should print in the log whenever the notification status changes, and whether it is enabled or disabled.

    Best regards,

    Edvin

  • Hi,

    Thanks Edvin.

    For now i did 'bypass' the problem, by sending a own command/data (Via the RX-charactaristic)) to set an EnableFlag to start the sending of Data via the TX-Charateristic.

    Im very happy with you answer, i wil look into it in more detail later.

    Manny thanks Edvin,

    Best Regards,

    Theo 

  • Hi Edvin,

    I did replace co cod as you mentioned. 

    It Works OK !!

    Thank you,

    Regards,

    Theo 

Related