蓝点DWM1000 模块已经打样测试完毕,有兴趣的能够申请购买了,更多信息参见 蓝点论坛 app
正文:函数
这一篇内容主要是经过官方源码理解SS-TWR 细节测试
代码下载连接:https://download.csdn.net/download/duanfei255/10787882this
全部代码使用方法:复制example 中的main.c到Keil MDK工程目录,便可编译出不一样的工程spa
使用开发环境:Keil MDK .net
对应与SS-TWR工程一共有两个文件夹,分别是ex_06a_ss_twr_init 和 ex_05b_ds_twr_resp。 其中ex_06a_ss_twr_init 对应于上一节原理分析中的DeciveA 而 ex_05b_ds_twr_resp 对应于DeviceB。code
分别编译下载到两个模块便可经过液晶查看两者直接的距离。orm
这里留空,认为全部人都使用过Keil - MDKblog
下面分析代码:ip
DWM1000 代码全部都遵循以下原则: 初始化 + 任务循环(例如测距)。
下面摘录ex_06a_ss_twr_init 初始化代码(基本全部DWM1000 工程的初始化代码都是同样的) 在SS-TWR中会调用一些API,占到经常使用API 90%
1 int main(void) 2 { 3 /* Start with board specific hardware init. */ 4 peripherals_init(); 5 6 /* Display application name on LCD. */ 7 lcd_display_str(APP_NAME); 8 9 /* Reset and initialise DW1000. 10 * For initialisation, DW1000 clocks must be temporarily set to crystal speed. After initialisation SPI rate can be increased for optimum 11 * performance. */ 12 reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */ 13 spi_set_rate_low(); 14 dwt_initialise(DWT_LOADUCODE); 15 spi_set_rate_high(); 16 17 /* Configure DW1000. See NOTE 6 below. */ 18 dwt_configure(&config); 19 20 /* Apply default antenna delay value. See NOTE 2 below. */ 21 dwt_setrxantennadelay(RX_ANT_DLY); 22 dwt_settxantennadelay(TX_ANT_DLY); 23 24 /* Set expected response's delay and timeout. See NOTE 1 and 5 below. 25 * As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */ 26 dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); 27 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);
上面初始化分为两部分,一部分是STM32 相关的初始化,例如设定IO SPI OLED等等
1 /* Start with board specific hardware init. */ 2 peripherals_init(); 3 4 /* Display application name on LCD. */ 5 lcd_display_str(APP_NAME); 6 7 spi_set_rate_low(); 8 spi_set_rate_high();
这里通常不须要更改,除非针对不一样的板子IO 发生变化或者更改液晶驱动。 关于SPI 速率设定,因为DWM1000初始化以前SPI 不能全速运行,因此开始的时候须要低速SPI,而待DWM1000 初始化完,能够全速运行了。
1 reset_DW1000(); /* Target specific drive of RSTn line into DW1000 low for a period. */ 2 dwt_initialise(DWT_LOADUCODE); 3 /* Configure DW1000. See NOTE 6 below. */ 4 dwt_configure(&config); 5 6 /* Apply default antenna delay value. See NOTE 2 below. */ 7 dwt_setrxantennadelay(RX_ANT_DLY); 8 dwt_settxantennadelay(TX_ANT_DLY); 9 10 /* Set expected response's delay and timeout. See NOTE 1 and 5 below. 11 /* As this example only handles one incoming frame with always the same delay and timeout, those values can be set here once for all. */ 12 dwt_setrxaftertxdelay(POLL_TX_TO_RESP_RX_DLY_UUS); 13 dwt_setrxtimeout(RESP_RX_TIMEOUT_UUS);
前面三个函数进行DWM1000 初始化,一般状况下无需修改。
note:全部以dwt_ 开头的函数均为DWM1000 官方标准API。
后面四个标准API 比较重要,设定很差距离测试不许是小,极可能没法测距。
先说前两个 setrxantennadelay/settxantennadelay 从字面意思就能够理解,这个是设定天线延时的。 在原理分析过程当中明确到,DWM1000 能够精确知道无线信号什么时候到达,而无线信号经过天线接收,而后送给DWM1000模块,天线收到信号到送给DWM1000 这个是花费时间的,一样,当发送的时候也是,DWM1000 只知道本身将数据送出去,送给天线的时间,而天线收到信号到发射到空中也是须要时间的。 前者称为rxantennadelay 后者称为txantennadelay。而这两个值一般较大,并且基本认为是同样的。
后面会有一节专门分析antennadelay 以及 软件设定技巧以及相关校准(calibration)
在一次SS-TWR测距中,有两条无线消息,全部须要
接着上一节原理 Tround - Treplay - DeciveA txantennadelay - DeciveB rxantennadelay - DeciveB txantennadelay - DeciveA rxantennadelay 才是无线信号真正在空中传输时间。
后面两个是控制射频接收开启时间以及timeout的。 当DWM1000 发送一条信息后,若是明确知道收到信息的其它模块会回复一条信息,那么就须要在发送后打开接收器。固然能够选择当即打开接收器,可是根据实验数据大概估计会回复数据的时刻,能够延时一段时间在打开接收器,这个延时设定就setrxaftertxdelay。 接上面,打开接收器就在等数据,若是等不到就过段时间自动关闭接收器,不能一直无限期等下去啊,这个时间段就是setrxtimeout设定的。
实验过程有时忘记加setrxaftertxdelay 或者timeout 设置的时间过短,均可能致使没法收到信息而报错。