This is the DW1000 driver and our self developed distance measurement application based on it. We do this as a semester thesis at ETH Zürich under the Automatic Control Laboratory in the Department of electrical engineering.

Dependencies:   mbed

Revision:
25:d58b0595b300
Parent:
24:6f25ba679490
Child:
26:a65c6f26c458
--- a/DW1000/DW1000.cpp	Thu Nov 27 16:26:42 2014 +0000
+++ b/DW1000/DW1000.cpp	Thu Nov 27 17:51:54 2014 +0000
@@ -1,8 +1,6 @@
 #include "DW1000.h"
 
 DW1000::DW1000(PinName MOSI, PinName MISO, PinName SCLK, PinName CS, PinName IRQ) : irq(IRQ), spi(MOSI, MISO, SCLK), cs(CS) {
-    receiving = false;                  // state in the beginning is not listening for frames
-    sending = false;                    // state in the beginning is not sending anything
     callbackRX = NULL;        // TODO: setter
     callbackTX = NULL;
     
@@ -70,21 +68,18 @@
     length = ((backup & 0xFC) << 8) | (length & 0x03FF);
     writeRegister16(DW1000_TX_FCTRL, 0, length);
     
-    if (receiving) stopTRX();                                       // stop receiving if we are in this state
-    sending = true;
+    stopTRX();                                                      // stop receiving
     writeRegister8(DW1000_SYS_CTRL, 0, 0x02);                       // trigger sending process by setting the TXSTRT bit
-    if (receiving) startRX();
+    startRX();                                                      // enable receiver again
 }
 
 void DW1000::startRX() {
     //while(sending);                                                 // block until sending finished                         TODO: the right way??
-    receiving = true;
     writeRegister8(DW1000_SYS_CTRL, 0x01, 0x01);                    // start listening for preamble by setting the RXENAB bit
 }
 
-void DW1000::stopRX() {
-    receiving = false;
-    stopTRX();
+void DW1000::stopTRX() {
+    writeRegister8(DW1000_SYS_CTRL, 0, 0x40);                       // disable tranceiver go back to idle mode
 }
 
 // PRIVATE Methods ------------------------------------------------------------------------------------
@@ -95,10 +90,6 @@
     writeRegister16(DW1000_PMSC, 0, 0x0200);                        // recover to PLL clock
 }
 
-void DW1000::stopTRX() {
-    writeRegister8(DW1000_SYS_CTRL, 0, 0x40);                       // disable tranceiver go back to idle mode
-}
-
 void DW1000::resetRX() {    
     writeRegister8(DW1000_PMSC, 3, 0xE0);   // set RX reset
     writeRegister8(DW1000_PMSC, 3, 0xF0);   // clear RX reset
@@ -119,8 +110,7 @@
         writeRegister16(DW1000_SYS_STATUS, 0, 0x6F00);              // clearing of receiving status bits
     }
     if (status & 0x80) {                                            // sending complete
-        sending = false;
-        if (receiving) startRX();                                  // enable receiver again if we need to preserve state          TODO: have to do it here??
+        //startRX();                                  // enable receiver again if we need to preserve state          TODO: have to do it here??
         if (callbackTX != NULL)
             callbackTX();
         writeRegister8(DW1000_SYS_STATUS, 0, 0xF8);                 // clearing of sending status bits