thotro / arduino-dw1000

A library that offers functionality to use Decawave's DW1000 chips/modules with Arduino.
Apache License 2.0
517 stars 288 forks source link

DW1000.cpp: SPI data not read correctly for extended adresses #36

Closed greymfm closed 7 years ago

greymfm commented 9 years ago

readBytes is not setting the extended address bit correctly:

This is the corrected code:

     static const byte EXT_ADDR = 0x80; // extended address
      .......

        } else {
            header[1] = EXT_ADDR | (byte)offset;
            header[2] = (byte)(offset >> 7);
            headerLen+=2;
        }

I found it out by verifying the sent data (in writeBytes) by reading back the written data.

wr@23:4=> 70,88,
wr@23:C=> 7,A9,2,25,
wr@23:12=> 35,0,
wr@27:2=> 1,0,
wr@27:4=> 87,0,
wr@27:6=> 20,0,
wr@27:8=> 2D,0,1A,31,
wr@27:26=> 28,0,
wr@2E:806=> D,
  ERROR: 0,
wr@2E:1806=> 7,16,
  ERROR: 0,AD,
wr@2E:2804=> 8E,42,
  ERROR: 0,0,
greymfm commented 9 years ago

BTW: accuracy seem to incease by this fix because otherwise the tuning parameters are not written correctly to the chip :) (UPDATE: please ignore this comment, I think I'm wrong here)

thotro commented 9 years ago

Hi there,

sorry for delay and thanks for your help in debugging!

Although I did not yet have time to verify this extended address issue, your "corrected" code seems to be equal to the one in already in place. Your EXT_ADDR is equal to the currently used WRITE constant.

Did I miss something? ;-) Please clarify and many thanks!

Cheers, Thomas

greymfm commented 9 years ago

For extended addresses, regardless of read/write, bit 7 of Octet 2 must be set (page 12 in user manual). In the current code, it's not set for read operations, and so the read fails (PS: try to write and read back an extended address).

thotro commented 9 years ago

Uh, oh! Thx! Will fix it.