br101 / libdeca

UWB Library for Decawave/Qorvo DW3000
GNU Lesser General Public License v3.0
4 stars 1 forks source link

Getting TWR example to work #1

Closed gilbertgit closed 3 months ago

gilbertgit commented 3 months ago

Hello, I'm trying to use libdeca with my setup. I have a board with a dwm3000 and an esp32c6. Looks like SPI coms are good but I'm having a hard time getting the devices to range. Here are some of init functions:

dwmac_init(0x1234, 0x0001, 10, twr_rx_handler, timeout_cb, err_cb);
twr_init(DWT_BR_6M8, DWT_PLEN_64, DWT_PRF_64M);

 // two way ranging to two destinations
 uint16_t dst[] = {0x1001};
 twr_start(dst, 1, 1, res, sizeof(res), twr_done_cb, false);

My other device has an ID of 0x1001 and sending to 0x0001. Is this the correct approach? Here is an example of my logs are looking like:

I (400) DW3000: RESET:21 WAKEUP:22 IRQ:23
I (400) gpio: GPIO[21]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (400) gpio: GPIO[22]| InputEn: 0| OutputEn: 1| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (410) DW3000: SPI Init (MOSI:7 MISO:2 CLK:6 CS:5)
I (410) INIT: DWM INIT SUCCESS
I (420) DW3000: HW reset
I (420) gpio: GPIO[23]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:1 
I (430) DECA: DEV ID: DECA0302
I (430) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0 
I (440) DECA: config CH 9 6.8Mbps PRF 64MHz Plen 64 PAC 8
I (450) DECA: config code 11/11 SFD 65
I (450) DECA: PRE 66 (SFD 9) PHD 22 12B DATA 19 = 114 us
I (460) DECA: Init PANID: 1234 MAC: 0001
I (460) DWTASK: TASK started
I (470) TWR: delay 792 us RX delay 678 us PTO 8 (66 us)
I DECA: *** RX Timeout 2200001
E (480) TWR: RX timeout from 1001
I (490) TWR: retry 1 to 1001 after 13 ms
I DECA: *** RX Timeout 200001
I (490) timeout_cb: Timeout
E (490) TWR: RX timeout from 1001
I (490) TWR: retry 2 to 1001 after 3 ms
I DECA: *** RX Timeout 200001
I (500) timeout_cb: Timeout
E (500) TWR: RX timeout from 1001
E (510) TWR: retry limit exceeded 1001
I (510) twr_done_cb: TWR Done 1001: 65535 cm
I (520) timeout_cb: Timeout

I appreciate your help!

br101 commented 3 months ago

Is the other side in RX mode?

gilbertgit commented 3 months ago

Both of the devices are running the exact code except for the mac address on dwmac and the dst array are swapped. What's the best way to tell if a device is in RX mode.

gilbertgit commented 3 months ago

I was able to get the other device in receive mode by using dwt_rxenable(DWT_START_RX_IMMEDIATE); and it is now getting something. But it looks like it's stuck stuck when trying to respond.

I DECA: *** RX 2006f01 flags 5
E (4983) DECA: TX error seq 0 (0x4080e1a0)
E (4983) DECA:  SYS Time:       442f907a00
E (4993) DECA:  TX Time:        442ea48234
E (4993) DECA:  Diff:           ff140834 (-242 us)
E (4993) TWR: Failed to send Response to 1001
I (5003) TWR: rx_ts442ba04f01
I (5003) TWR: tx_ts442ea48234
I (5013) TWR: delay0003043333

The sender still retries as it was doing before:

I DECA: *** RX Timeout 200001
E (114053) TWR: RX timeout from 0001
I (114053) TWR: retry 1 to 0001 after 0 ms
I DECA: *** RX Timeout 200001
I (114063) timeout_cb: Timeout
E (114063) TWR: RX timeout from 0001
I (114073) TWR: retry 2 to 0001 after 8 ms
I DECA: *** RX Timeout 200001
I (114073) timeout_cb: Timeout
E (114083) TWR: RX timeout from 0001
E (114083) TWR: retry limit exceeded 0001
I (114093) twr_done_cb: TWR Done 0001: 65535 cm
I (114093) timeout_cb: Timeout

An example of what both device setups would look like would be helpful.

br101 commented 3 months ago

It seems your microcontroller is too slow to meet the timing requirements. Increase TWR_PROCESSING_TIME by at least 250 in ranging.c on both sides. It can also help to reduce the logging in dwmac_irq.c ("*** RX 2006f01 flags 5").

br101 commented 3 months ago

An example of what both device setups would look like would be helpful.

True, I added it to the README

gilbertgit commented 3 months ago

That's very helpful. Thank you for your help!

br101 commented 3 months ago

So did you get it to work finally? I'm very interested to get feedback on the usability of the library. Thanks!