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:
22:576ee999b004
Parent:
21:23bf4399020d
Child:
23:661a79e56208
--- a/main.cpp	Wed Nov 26 12:10:09 2014 +0000
+++ b/main.cpp	Thu Nov 27 13:28:18 2014 +0000
@@ -3,7 +3,10 @@
 #include "DW1000.h"
 
 PC          pc(USBTX, USBRX, 921600);   // USB UART Terminal
-DW1000      dw(D11, D12, D13, D10, D14);     // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
+DW1000      dw(PA_7, PA_6, PA_5, PB_6, PB_9);     // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
+
+Timer       LocalTimer;                 // debuging timer
+int         old_time = 0;
 
 const float timeunit = 1/(128*499.2e6);
 int i=0;
@@ -16,8 +19,8 @@
     if (framelength < 200) {
         char* receive = dw.receiveString();                             // receive a string
         pc.printf("Received: \"%s\" %d ", receive, framelength);
+        pc.printf("Status: %010llX  ", dw.getStatus());
 #if 0
-        pc.printf("Status: %010llX  ", dw.getStatus());
         sprintf(message, "ACK \"%s\"", receive);
         dw.sendString(message);
         wait(0.1);
@@ -33,17 +36,18 @@
 }
 
 void callbackTX() {
-    TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0);
-    char messagecheck[1021];
+    //TX_timestamp = dw.readRegister40(DW1000_TX_TIME, 0);
+    /*char messagecheck[1021];
     dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, 1021);
     if (i < 200)
         pc.printf("%d Sent: \"%s\" %d ", i, messagecheck, strlen(messagecheck)+1);
     else
-        pc.printf("%d Sent! %d ", i, strlen(messagecheck)+1);
-    pc.printf("Status: %010llX\r\n", dw.getStatus());
+        pc.printf("%d Sent! %d ", i, strlen(messagecheck)+1);*/
+    pc.printf("SENT!! Status: %010llX Time: %d\r\n", dw.getStatus(), LocalTimer.read_us()-old_time);
 }
 
 int main() {
+    LocalTimer.start();
     pc.printf("DecaWave 0.1\r\nup and running!\r\n");  
     dw.setEUI(0xFAEDCD01FAEDCD01);                  // basic methods called to check if we have a working SPI connection
     pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
@@ -54,21 +58,26 @@
     dw.callbackTX = &callbackTX;
     
     // Receiver initialisation
-    dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4000); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
+    dw.writeRegister16(DW1000_SYS_MASK, 0, 0x4080); //| 0x0080); // TODO: RX only good frame 0x4000, RX all frames 0x2000, TX done 0x0080
     dw.startRX();
     
     while(1) {
 #if 1
-        wait(10);
-        sprintf(message, "Hi %d", i);
-        dw.sendString(message);
-        wait(0.3);
+        //sprintf(message, "Hi %d", i);
+        sprintf(message, "012345678901234567890123456789012345678");
+        if ((i % 10) > 5) {
+            dw.sendString(message);
+            old_time = LocalTimer.read_us();
+            dw.writeRegister8(DW1000_SYS_CTRL, 0, 0x02);
+            pc.printf("%d Sent: \"%s\" %d \r\n", i, message, strlen(message)+1);
+        }
 #endif
 #if 0
         pc.printf("%d Waiting... %d %d ", i, dw.receiving, dw.sending);
-        pc.printf("Status: %010llX\r\n", dw.getStatus());
         wait(5);
 #endif
+        wait(0.2);
+        //pc.printf("Status: %010llX\r\n", dw.getStatus());
         i++;
     }
 }
\ No newline at end of file