Range failed when clock@MCU is 32MHz

Hi rain

The first thing to adjust is the SPI clock speeds. The SPI clock speed needs to be low enough (<3MHz) in slow mode and fast enough (~16-20 MHz) to handle quick communication with the DW1000. Typically the SPI clock speed depends on the system clock so you will probably have to adjust the clock devider to ensure optimal clock speeds. See port_set_dw1000_slowrate and port_set_dw1000_fastrate in src/platform/port.c.

If ranging still does not work, it could be the MCU is to slow to perform ranging at the required speed. You can lower the ranging interval by increasing the RX_RESPONSE_TURNAROUND macro in src/application/instance.c.

It might be interesting to look at the DW1000 examples, this explains a bit more about how the TWR works and how MCU timing impacts the ranging. The TREK1000 source code is a bit more complicated. See e.g the POLL_TX_TO_RESP_RX_DLY_UUS macro and note 4 in example 05a: TWR initiator of the DW1000 examples. These are designed to run on the same hardware as the TREK1000.

Note that we can’t assure the TREK demo will work correctly when using a 32MHz clock, though technically it should be possible we haven’t tested this afaik.