DW1000测距例程问题笔记

说明

在做DW1000的驱动移植测试时遇到了很多问题,这里记录下

SPI问题

SPI问题的驱动移植是比较常见的难点,Decawave的示例驱动只有基于STM32平台的,对于大部分人在使用其他平台时都要重新实现SPI的驱动
常见的问题在于SPI的读写不通,这个需要通过对芯片寄存器进行读写测试并配合逻辑分析仪来对SPI时序进行分析来确认。

uint8 dataA[20] = {0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
uint8 dataB[20];

dwt_writetodevice(0x21, 0, 20, &dataA[0]);
dwt_readfromdevice(0x21, 0, 20, &dataB[0]);
			

可以参考上述代码对0x21寄存器(DW1000中的数据缓存寄存器)进行读写回读来确认基本的SPI通信是否正常

另外,需要确保高速SPI和低速SPI切换接口正常,芯片默认的SPI速率为3Mhz以下,需要进行初始化后才能支持到20Mhz,对于某些应用场景,高速SPI是必须的

/* @fn      port_set_dw_ic_spi_slowrate
 * @brief   set 2MHz
 * */
void port_set_dw_ic_spi_slowrate(void);

/* @fn      port_set_dw_ic_spi_fastrate
 * @brief   set 16MHz
 * */
void port_set_dw_ic_spi_fastrate(void);

测距例程的时序

一般来讲,SPI通了就可以正常的跑通Simple TX/RX例程。但是对于测距例程DW Ranging可能还是会跑不通,这个往往是由于时序问题导致的异常。
常见的是rsp端在第一次接收到数据后,准备进行延迟发送时出现发送失败

/* Set send time for response. See NOTE 9 below. */
resp_tx_time = (poll_rx_ts + (POLL_RX_TO_RESP_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8;
dwt_setdelayedtrxtime(resp_tx_time);

/* Set expected delay and timeout for final message reception. See NOTE 4 and 5 below. */
dwt_setrxaftertxdelay(RESP_TX_TO_FINAL_RX_DLY_UUS);
dwt_setrxtimeout(FINAL_RX_TIMEOUT_UUS);

/* Write and send the response message. See NOTE 10 below.*/
tx_resp_msg[ALL_MSG_SN_IDX] = frame_seq_nb;
dwt_writetxdata(sizeof(tx_resp_msg), tx_resp_msg, 0); /* Zero offset in TX buffer. */
dwt_writetxfctrl(sizeof(tx_resp_msg), 0, 1); /* Zero offset in TX buffer, ranging. */
ret = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED);

/* If dwt_starttx() returns an error, abandon this ranging exchange and proceed to the next one. See NOTE 11 below. */
if (ret == DWT_ERROR)
{
  continue;
}

即最后的调用starttx函数会失败

nt dwt_starttx(uint8 mode)
{
    int retval = DWT_SUCCESS ;
    uint8 temp  = 0x00;
    uint16 checkTxOK = 0 ;

    if(mode & DWT_RESPONSE_EXPECTED)
    {
        temp = (uint8)SYS_CTRL_WAIT4RESP ; // Set wait4response bit
        pdw1000local->wait4resp = 1;
    }

    if (mode & DWT_START_TX_DELAYED)
    {
        // Both SYS_CTRL_TXSTRT and SYS_CTRL_TXDLYS to correctly enable TX
        temp |= (uint8)(SYS_CTRL_TXDLYS | SYS_CTRL_TXSTRT) ;
        dwt_write8bitoffsetreg(SYS_CTRL_ID, SYS_CTRL_OFFSET, temp);
        checkTxOK = dwt_read16bitoffsetreg(SYS_STATUS_ID, 3); // Read at offset 3 to get the upper 2 bytes out of 5
        if ((checkTxOK & SYS_STATUS_TXERR) == 0) // Transmit Delayed Send set over Half a Period away or Power Up error (there is enough time to send but not to power up individual blocks).
        {
            retval = DWT_SUCCESS ; // All okay
        }
        else
        {
            // If HPDWARN or TXPUTE are set this indicates that the TXDLYS was set too late for the specified DX_TIME.
            // remedial action is to cancel delayed send and report error
            dwt_write8bitoffsetreg(SYS_CTRL_ID, SYS_CTRL_OFFSET, (uint8)SYS_CTRL_TRXOFF);
            retval = DWT_ERROR ; // Failed !
						
        }
    }
    else
    {
        temp |= (uint8)SYS_CTRL_TXSTRT ;
        dwt_write8bitoffsetreg(SYS_CTRL_ID, SYS_CTRL_OFFSET, temp);
    }

    return retval;

} // end dwt_starttx()

如果查看函数执行过程发现是checkTxOK标志失败,并且把这个标志位读出来发现是0x08的话,那就说明是出现了HPDWARN错误

即发送时间太晚了,延迟时间结束了都还没发,因此需要增加延迟时间,让发送能来得及

/* UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor.
 * 1 uus = 512 / 499.2 ?s and 1 ?s = 499.2 * 128 dtu. */
#define UUS_TO_DWT_TIME 65536

/* Delay between frames, in UWB microseconds. See NOTE 4 below. */
/* This is the delay from Frame RX timestamp to TX reply timestamp used for calculating/setting the DW1000's delayed TX function. This includes the
 * frame length of approximately 2.46 ms with above configuration. */
 #define POLL_RX_TO_RESP_TX_DLY_UUS 4600	//default:2600
/* This is the delay from the end of the frame transmission to the enable of the receiver, as programmed for the DW1000's wait for response feature. */
#define RESP_TX_TO_FINAL_RX_DLY_UUS 500		//default:500
/* Receive final timeout. See NOTE 5 below. */
#define FINAL_RX_TIMEOUT_UUS 5300					//default:3300
/* Preamble timeout, in multiple of PAC size. See NOTE 6 below. */
#define PRE_TIMEOUT 800									 //default:8

即类似与DW Raging测距例程中的上述参数

对于直接用例程的参数还跑不通的,要注意下SPI速率是否设置的和例程一致,例程中会有将SPI速率进行切换到高速或者低速的操作,要是没有实现高速SPI切换的接口也会导致时序错误

其他建议

Decawave对于常见的问题有总结出排查参考手册,可以在官网上下载APS022_Debugging-DW1000-Based-Products-and-Systems_v1.3这份文档来参考

posted on 2023-02-01 17:50  不回本不改名  阅读(876)  评论(0编辑  收藏  举报

导航