<?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>Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100264/synchronisation-errors-with-distance-measurement-dm</link><description>Hello and thank you for your help. 
 
 I am working on a project that requires a separate initiator and reflector for MCPD distance measurement. I believe the sample assumes a dual initiator-reflector role for all devices involved in the measurement.</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Sep 2023 13:57:25 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100264/synchronisation-errors-with-distance-measurement-dm" /><item><title>RE: Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/thread/447759?ContentTypeID=1</link><pubDate>Tue, 26 Sep 2023 13:57:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cf54baf-dd05-4752-a9f0-beca2f1f43e0</guid><dc:creator>ptejasv</dc:creator><description>&lt;p&gt;I used the same method as the DM sample, connection oriented BLE with&amp;nbsp;dm_request_add() triggered as part of the advertising callbacks.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On the initiator side, I called&amp;nbsp;&lt;span&gt;dm_request_add() in the callback for matching scan filters:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;bool handle_adv(struct bt_data *data, void *user_data) {
	struct dm_request req;

    switch(data-&amp;gt;type) {
		case BT_DATA_UUID128_ALL:
			bt_addr_le_copy(&amp;amp;req.bt_addr, user_data);
			req.role = DM_ROLE_INITIATOR;
			req.ranging_mode = DM_RANGING_MODE_MCPD;
			req.rng_seed = sys_cpu_to_le32(RNG_SEED);
			req.start_delay_us = 0;
			req.extra_window_time_us = 0;

			dm_request_add(&amp;amp;req); // this is where dm is triggered
			break;
	}

	return true;
}

static void scan_filter_match(struct bt_scan_device_info *device_info,
					struct bt_scan_filter_match *filter_match,
					bool connectable)
{
	bt_addr_le_t addr;

	bt_addr_le_copy(&amp;amp;addr, device_info-&amp;gt;recv_info-&amp;gt;addr);
	bt_data_parse(device_info-&amp;gt;adv_data, handle_adv, &amp;amp;addr);
}

BT_SCAN_CB_INIT(scan_cb, scan_filter_match, NULL, NULL, NULL);&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;On the reflector side, it&amp;#39;s called during&amp;nbsp;the&amp;nbsp;extended&amp;nbsp;advertising&amp;nbsp;callback for when the reflector&amp;#39;s BLE advertisement is scanned:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void adv_scanned_cb(struct bt_le_ext_adv *adv,
			struct bt_le_ext_adv_scanned_info *info) {
	struct dm_request req;

	bt_addr_le_copy(&amp;amp;req.bt_addr, info-&amp;gt;addr);
	req.role = DM_ROLE_REFLECTOR;
	req.ranging_mode = DM_RANGING_MODE_MCPD;
	req.rng_seed = sys_cpu_to_le32(RNG_SEED);
	req.start_delay_us = 0;
	req.extra_window_time_us = 0;

	dm_request_add(&amp;amp;req);
}

const static struct bt_le_ext_adv_cb adv_cb = {
	.scanned = adv_scanned_cb,
};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;adv_cb is just from the external advertisement creation in start_adv().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;err = bt_le_ext_adv_create(adv_param, &amp;amp;adv_cb, &amp;amp;adv);&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I stuck to what the sample used, but there might be&amp;nbsp;other ways to do it.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/thread/447612?ContentTypeID=1</link><pubDate>Tue, 26 Sep 2023 05:04:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c99f0c52-ed7e-4bfd-9b38-57891f84c325</guid><dc:creator>syed_</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/ptejasv"&gt;ptejasv&lt;/a&gt;&amp;nbsp; have you used connection oriented or connection less&amp;nbsp;ble communication?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If Connection oriented, then can you please suggest when to trigger dm_add_request() on both sides.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;syed&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/thread/428589?ContentTypeID=1</link><pubDate>Thu, 01 Jun 2023 03:54:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f77c0b7d-03f5-4ae5-8430-a510b56414ed</guid><dc:creator>ptejasv</dc:creator><description>&lt;p&gt;I tried that and everything seems to work fine now. I didn&amp;#39;t realise it was that trivial of an error. Thanks for your help anyway!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/thread/428410?ContentTypeID=1</link><pubDate>Wed, 31 May 2023 10:48:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0a907f3a-bb76-47e3-96a1-174e9793feef</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Let me know&amp;nbsp;if you&amp;#39;re still having trouble after setting the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/others/dm.html#c.dm_request.rng_seed"&gt;rng_seed&lt;/a&gt;&amp;nbsp;values identical on initiator and reflector!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Synchronisation errors with Distance Measurement (DM)</title><link>https://devzone.nordicsemi.com/thread/428357?ContentTypeID=1</link><pubDate>Wed, 31 May 2023 08:55:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e44c269e-c89e-412f-97ad-0eb2999bd1af</guid><dc:creator>ptejasv</dc:creator><description>&lt;p&gt;I just re-read the documentation and realised the rng seed should be the same on both initiator and reflector. Will update once I fix that issue.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>