<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Data Loss With Nordic Uart Service</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/109034/data-loss-with-nordic-uart-service</link><description>We are developing our code based on the peripheral UART (NUS) example and are currently testing the baseline before applying our own changes. I have 2x nrf52840-DK boards, one for peripheral and another for central. We are using nrfConnect SDK 2.5.0.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 08 Mar 2024 13:15:55 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/109034/data-loss-with-nordic-uart-service" /><item><title>RE: Data Loss With Nordic Uart Service</title><link>https://devzone.nordicsemi.com/thread/472958?ContentTypeID=1</link><pubDate>Fri, 08 Mar 2024 13:15:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0017219-5c0c-4787-a248-e0e10a88eeb2</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;The BLE link is considered reliable. That is, if a packet fails to reach the receiver after a specified number of retransmissions, the link will be considered lost, and a disconnect event will be triggered. Therefore, it is much more likely that data loss is occurring somewhere&amp;nbsp;in the UART data handling before the data is passed to your sender thread.&lt;/p&gt;
[quote user=""]Are there known data loss issues with the peripheral UART driver?[/quote]
&lt;p&gt;Please try to enable UART byte counting in HW for both projects by adding&amp;nbsp;&lt;span&gt;CONFIG_UART_0_NRF_HW_ASYNC&lt;/span&gt;&lt;span&gt;=y and&amp;nbsp;&lt;/span&gt;&lt;span&gt;CONFIG_UART_0_NRF_HW_ASYNC_TIMER&lt;/span&gt;&lt;span&gt;=1 to your prj.conf files.&lt;/span&gt;(&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/26fd55e0a750305fbd5d9db750225d7e707458ae/drivers/serial/Kconfig.nrfx_uart_instance#L45"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/26fd55e0a750305fbd5d9db750225d7e707458ae/drivers/serial/Kconfig.nrfx_uart_instance#L45&lt;/a&gt;)&amp;nbsp;&lt;/p&gt;
[quote user=""]Do I need to increase buffers somewhere else in order to send 250 byte data; presumably I&amp;nbsp;should&amp;nbsp;to increase the MTU, please provide a link on how to do that.[/quote]
&lt;p&gt;To support longer att MTUs, you can add these kconfig symbols to your prj.conf file (copied from throughput sample):&lt;/p&gt;
&lt;p&gt;CONFIG_BT_BUF_ACL_TX_SIZE=502&lt;/p&gt;
&lt;p&gt;CONFIG_BT_BUF_ACL_RX_SIZE=502&lt;/p&gt;
&lt;p&gt;CONFIG_BT_L2CAP_TX_MTU=498&lt;/p&gt;
&lt;p&gt;Effective data payload is att MTU - 3. You can add the following code to your project to get a callback after the MTU has been negotiated:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
	LOG_INF(&amp;quot;MTU Updated: tx %d, rx %d&amp;quot;, tx, rx);
}

static struct bt_gatt_cb gatt_cb = {
	.att_mtu_updated = att_mtu_updated,
};

int main(void)
{
    ...
    err = bt_enable(NULL);
	if (err) {
		LOG_INF(&amp;quot;Bluetooth init failed (err %d)&amp;quot;, err);
		return 0;
	}
	
	/* Register att MTU updated callback. Must be done after bt_enable() */
	bt_gatt_cb_register(&amp;amp;gatt_cb);
    ...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Alternatively, you can check the att MTU size during the connection using&amp;nbsp;bt_gatt_get_mtu():&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint16_t max_pkt_len = bt_gatt_get_mtu(current_conn) - 3;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;In addition, you may add&amp;nbsp;&lt;/span&gt;&lt;span&gt;CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 if you want to support longer radio packet lengths (is 27 by default).&lt;/span&gt;&lt;/p&gt;
[quote user=""]Should I switch to indications? If I use indications I understand I cannot send more data until I get the peer acknowledgement. But what happens if that acknowledgment never comes? Should I resend after a timeout?[/quote]
&lt;p&gt;&lt;span&gt;Notifications are still acknowledged by the receiver, but by the link layer and not by the application. The Bluetooth stack will not send the next notification packet until a previous notification has been received.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Vidar&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;strong&gt;EDIT: &lt;/strong&gt;The application should also request the HFXO oscillator when the UART is enabled to ensure a stable clock source for the baud rate generator. Otherwise, the baud rate generator will&amp;nbsp;run off&amp;nbsp;the less accurate internal RC oscillator&amp;nbsp;&lt;a title="64 MHz internal oscillator (HFINT)" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/clock.html?cp=5_0_0_4_3_3_0#unique_49915259"&gt;(HFINT)&lt;/a&gt;.&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The HFXO can be requested with this code snippet:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/5e0199b154f9e457d5ec091734c517916f0be9b5/samples/peripheral/radio_test/src/main.c#L11"&gt;https://github.com/nrfconnect/sdk-nrf/blob/5e0199b154f9e457d5ec091734c517916f0be9b5/samples/peripheral/radio_test/src/main.c#L11&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>