<?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>Callback on MTU change</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/92310/callback-on-mtu-change</link><description>Hi, 
 
 Our device nRF 52832 using connect SDK connects with the Android application. And successfully negotiates an MTU size of 247. 
 Is there any call back in the nRF SDK to which I can register to know the negotiated MTU size ? 
 nRF connect SDK 2</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 27 Sep 2022 10:36:42 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/92310/callback-on-mtu-change" /><item><title>RE: Callback on MTU change</title><link>https://devzone.nordicsemi.com/thread/388094?ContentTypeID=1</link><pubDate>Tue, 27 Sep 2022 10:36:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4d19fedf-49c6-44ed-bb29-1f63969017e8</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Sachin,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can declare the callback like this:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
{
	printk(&amp;quot;Updated MTU: TX: %d RX: %d bytes\n&amp;quot;, tx, rx);
}

static struct bt_gatt_cb gatt_callbacks = {
	.att_mtu_updated = mtu_updated
};
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you want to request the MTU&amp;nbsp;exchange from the nRF52&amp;#39;s side, you can follow my example provided in this &lt;a href="https://devzone.nordicsemi.com/guides/nrf-connect-sdk-guides/b/software/posts/building-a-bluetooth-application-on-nrf-connect-sdk-part-3-optimizing-the-connection"&gt;blog&lt;/a&gt;. The example provided at section 2.2.&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void MTU_exchange_cb(struct bt_conn *conn, uint8_t err, struct bt_gatt_exchange_params *params)
{
	if (!err) {
		LOG_INF(&amp;quot;MTU exchange done. &amp;quot;); 
		payload_length=bt_gatt_get_mtu(current_conn)-3; //3 bytes ATT header
	} else {
		LOG_WRN(&amp;quot;MTU exchange failed (err %&amp;quot; PRIu8 &amp;quot;)&amp;quot;, err);
	}
}
static void request_mtu_exchange(void)
{	int err;
	static struct bt_gatt_exchange_params exchange_params;
	exchange_params.func = MTU_exchange_cb;

	err = bt_gatt_exchange_mtu(current_conn, &amp;amp;exchange_params);
	if (err) {
		LOG_WRN(&amp;quot;MTU exchange failed (err %d)&amp;quot;, err);
	} else {
		LOG_INF(&amp;quot;MTU exchange pending&amp;quot;);
	}
	

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>