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

Committer:
manumaet
Date:
Thu Nov 27 19:19:35 2014 +0000
Revision:
26:a65c6f26c458
Parent:
25:d58b0595b300
Child:
27:71178fdb78e1
problems with last publish solved, first simple really working driver :)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 24:6f25ba679490 1 // by Matthias Grob & Manuel Stalder - ETH Zürich - 2015
manumaet 0:f50e671ffff7 2 #include "mbed.h"
manumaet 26:a65c6f26c458 3 #include "PC.h" // Serial Port via USB for debugging with Terminal
manumaet 0:f50e671ffff7 4 #include "DW1000.h"
manumaet 0:f50e671ffff7 5
manumaet 26:a65c6f26c458 6 //#define RECEIVER
manumaet 26:a65c6f26c458 7
manumaet 26:a65c6f26c458 8 PC pc(USBTX, USBRX, 921600); // USB UART Terminal
manumaet 26:a65c6f26c458 9 DW1000 dw(PA_7, PA_6, PA_5, PB_6, PB_9); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
manumaet 22:576ee999b004 10
manumaet 24:6f25ba679490 11 const float timeunit = 1/(128*499.2);
manumaet 14:8041c9b68406 12 int i=0;
manumaet 24:6f25ba679490 13 char message[1021] = "";
manumaet 24:6f25ba679490 14 char messageRX[1021] = "";
manumaet 24:6f25ba679490 15 uint64_t TX_timestamp;
manumaet 24:6f25ba679490 16 uint64_t RX_timestamp;
manumaet 24:6f25ba679490 17 int event_i = 0;
manumaet 24:6f25ba679490 18 char event[10][20];
manumaet 24:6f25ba679490 19 uint64_t eventtimes[10];
manumaet 14:8041c9b68406 20
manumaet 18:bbc7ca7d3a95 21 void callbackRX(int framelength) {
manumaet 26:a65c6f26c458 22 RX_timestamp = dw.getRXTimestamp();
manumaet 26:a65c6f26c458 23 dw.receiveString(messageRX);
manumaet 26:a65c6f26c458 24 #ifdef RECEIVER
manumaet 26:a65c6f26c458 25 message[0] = 'A'; // acknowledge messages
manumaet 24:6f25ba679490 26 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 27 message[i+1] = messageRX[i];
manumaet 24:6f25ba679490 28 dw.sendString(message);
manumaet 21:23bf4399020d 29 #endif
manumaet 26:a65c6f26c458 30 eventtimes[event_i] = RX_timestamp - TX_timestamp; // TODO: can give some wrong values because of timer reset after 17 seconds
manumaet 24:6f25ba679490 31 event[event_i][0] = '!';
manumaet 24:6f25ba679490 32 event[event_i][1] = 'R';
manumaet 24:6f25ba679490 33 event[event_i][2] = ' ';
manumaet 24:6f25ba679490 34 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 35 event[event_i][i+3] = messageRX[i];
manumaet 24:6f25ba679490 36 if (event_i == 8)
manumaet 24:6f25ba679490 37 event_i = 0;
manumaet 24:6f25ba679490 38 else
manumaet 24:6f25ba679490 39 event_i++;
manumaet 17:8afa5f9122da 40 dw.startRX();
manumaet 6:d5864a1b9e17 41 }
manumaet 6:d5864a1b9e17 42
manumaet 18:bbc7ca7d3a95 43 void callbackTX() {
manumaet 26:a65c6f26c458 44 TX_timestamp = dw.getTXTimestamp();
manumaet 24:6f25ba679490 45 eventtimes[event_i] = 0;
manumaet 24:6f25ba679490 46 event[event_i][0] = '!';
manumaet 24:6f25ba679490 47 event[event_i][1] = 'S';
manumaet 24:6f25ba679490 48 event[event_i][2] = ' ';
manumaet 24:6f25ba679490 49 for(int i = 0; i < 10; i++)
manumaet 24:6f25ba679490 50 event[event_i][i+3] = message[i];
manumaet 24:6f25ba679490 51 if (event_i == 8)
manumaet 24:6f25ba679490 52 event_i = 0;
manumaet 18:bbc7ca7d3a95 53 else
manumaet 24:6f25ba679490 54 event_i++;
manumaet 18:bbc7ca7d3a95 55 }
manumaet 18:bbc7ca7d3a95 56
manumaet 0:f50e671ffff7 57 int main() {
manumaet 20:257d56530ae1 58 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 20:257d56530ae1 59 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a working SPI connection
manumaet 4:6240b9c7a033 60 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 61 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 62 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 63
manumaet 26:a65c6f26c458 64 dw.setCallbacks(&callbackRX, &callbackTX);
manumaet 26:a65c6f26c458 65 dw.setInterrupt(true, true);
manumaet 17:8afa5f9122da 66 dw.startRX();
manumaet 5:111f11c95d27 67
manumaet 0:f50e671ffff7 68 while(1) {
manumaet 26:a65c6f26c458 69 for(int j = 0; j < 10; j++)
manumaet 26:a65c6f26c458 70 if(event[j][0] == '!') {
manumaet 26:a65c6f26c458 71 pc.printf("%s Time: %fus\r\n", event[j], eventtimes[j]*timeunit);
manumaet 26:a65c6f26c458 72 event[j][0] = 'X';
manumaet 24:6f25ba679490 73 }
manumaet 26:a65c6f26c458 74 #ifndef RECEIVER
manumaet 26:a65c6f26c458 75 sprintf(message, "%d", i); // send numbers to acknowledge
manumaet 26:a65c6f26c458 76 dw.sendString(message);
manumaet 26:a65c6f26c458 77 wait(1);
manumaet 17:8afa5f9122da 78 #endif
manumaet 15:e1fea7e2aff1 79 i++;
manumaet 0:f50e671ffff7 80 }
manumaet 0:f50e671ffff7 81 }