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:
Sun Nov 23 14:34:31 2014 +0000
Revision:
12:985aa9843c3c
Parent:
11:c87d37db2c6f
Child:
13:b4d27bf7062a
before fusing SENDER and RECEIVER

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manumaet 0:f50e671ffff7 1 #include "mbed.h"
manumaet 0:f50e671ffff7 2 #include "PC.h" // Serial Port via USB for debugging with Terminal
manumaet 0:f50e671ffff7 3 #include "DW1000.h"
manumaet 0:f50e671ffff7 4
manumaet 0:f50e671ffff7 5 PC pc(USBTX, USBRX, 921600); // USB UART Terminal
manumaet 7:e634eeafc4d2 6 DW1000 dw(D11, D12, D13, D10, D14); // SPI1 on Nucleo Board (MOSI, MISO, SCLK, CS, IRQ)
manumaet 0:f50e671ffff7 7
manumaet 11:c87d37db2c6f 8
manumaet 11:c87d37db2c6f 9 uint64_t timestamp_old = 0;
manumaet 12:985aa9843c3c 10 #define SENDER
manumaet 5:111f11c95d27 11
manumaet 6:d5864a1b9e17 12 void Interrupthandler() {
manumaet 10:d077bb12d259 13 /*uint8_t frameready = 0;
manumaet 7:e634eeafc4d2 14 dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
manumaet 10:d077bb12d259 15 pc.printf("Interrupt status: %X\r\n", frameready);*/
manumaet 10:d077bb12d259 16
manumaet 12:985aa9843c3c 17 uint16_t framelength = 0; // get framelength TODO: just for debugging of string
manumaet 10:d077bb12d259 18 dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
manumaet 10:d077bb12d259 19 framelength &= 0x03FF;
manumaet 10:d077bb12d259 20 framelength -= 2;
manumaet 10:d077bb12d259 21
manumaet 12:985aa9843c3c 22 char* receive = dw.receiveString(); // receive a string
manumaet 11:c87d37db2c6f 23 pc.printf("Received: %s %d ", receive, framelength);
manumaet 10:d077bb12d259 24 delete[] receive;
manumaet 10:d077bb12d259 25
manumaet 11:c87d37db2c6f 26 uint64_t status;
manumaet 11:c87d37db2c6f 27 dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
manumaet 11:c87d37db2c6f 28 status &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 29 pc.printf("Status: %010llX ", status);
manumaet 11:c87d37db2c6f 30
manumaet 11:c87d37db2c6f 31 uint64_t timestamp;
manumaet 11:c87d37db2c6f 32 dw.readRegister(DW1000_RX_TIME, 0, (uint8_t*)&timestamp, 5);
manumaet 11:c87d37db2c6f 33 timestamp &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 34 uint64_t difference = timestamp - timestamp_old;
manumaet 11:c87d37db2c6f 35 timestamp_old = timestamp;
manumaet 11:c87d37db2c6f 36 pc.printf("Timestamp: %lld\r\n", difference);
manumaet 11:c87d37db2c6f 37
manumaet 8:7a9c61242e2f 38 dw.receiveFrame();
manumaet 6:d5864a1b9e17 39 }
manumaet 6:d5864a1b9e17 40
manumaet 0:f50e671ffff7 41 int main() {
manumaet 4:6240b9c7a033 42 int i=0;
manumaet 10:d077bb12d259 43 char message[1024] = "";
manumaet 0:f50e671ffff7 44 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 0:f50e671ffff7 45
manumaet 0:f50e671ffff7 46 dw.setEUI(0xFAEDCD01FAEDCD01);
manumaet 4:6240b9c7a033 47 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 48 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 49 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 50
manumaet 12:985aa9843c3c 51 uint32_t conf = 0; // read System Configuration
manumaet 4:6240b9c7a033 52 dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
manumaet 4:6240b9c7a033 53 pc.printf("%d System Configuration: %X\r\n", i, conf);
manumaet 4:6240b9c7a033 54
manumaet 8:7a9c61242e2f 55 dw.callbackRX = &Interrupthandler;
manumaet 9:c8839de428ac 56 #ifndef SENDER
manumaet 10:d077bb12d259 57 uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
manumaet 5:111f11c95d27 58 dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
manumaet 7:e634eeafc4d2 59
manumaet 8:7a9c61242e2f 60 dw.receiveFrame();
manumaet 5:111f11c95d27 61 #endif
manumaet 5:111f11c95d27 62
manumaet 0:f50e671ffff7 63 while(1) {
manumaet 0:f50e671ffff7 64 i++;
manumaet 5:111f11c95d27 65 # ifdef SENDER // to make one node sender and one receiver
manumaet 11:c87d37db2c6f 66 //message[i-1] = 'O';
manumaet 11:c87d37db2c6f 67 //message[i] = '\0';
manumaet 11:c87d37db2c6f 68 sprintf((char*)message, "HELLO WORLD! %d", i);
manumaet 11:c87d37db2c6f 69 //if (i < 200)
manumaet 11:c87d37db2c6f 70 pc.printf("%d Message: \"%s\" %d\r\n", i, message, strlen(message)+1);
manumaet 11:c87d37db2c6f 71 //else
manumaet 11:c87d37db2c6f 72 //pc.printf("%d Message: %d\r\n", i, strlen(message)+1);
manumaet 10:d077bb12d259 73 dw.sendString(message);
manumaet 0:f50e671ffff7 74
manumaet 10:d077bb12d259 75 char messagecheck[1024];
manumaet 10:d077bb12d259 76 dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
manumaet 11:c87d37db2c6f 77 //if (i < 200)
manumaet 10:d077bb12d259 78 pc.printf("%d Buffer: \"%s\" %d\r\n", i, messagecheck, strlen(messagecheck)+1);
manumaet 11:c87d37db2c6f 79 //else
manumaet 11:c87d37db2c6f 80 //pc.printf("%d Buffer: %d\r\n", i, strlen(messagecheck)+1);
manumaet 9:c8839de428ac 81 /*for(int i=0; i<10; i++) { // to control Voltage
manumaet 9:c8839de428ac 82 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 9:c8839de428ac 83 wait(0.2);
manumaet 9:c8839de428ac 84 }*/
manumaet 11:c87d37db2c6f 85 //if (i<27)
manumaet 11:c87d37db2c6f 86 wait(1);
manumaet 11:c87d37db2c6f 87 //else
manumaet 11:c87d37db2c6f 88 //wait(3);
manumaet 8:7a9c61242e2f 89 #else
manumaet 11:c87d37db2c6f 90 pc.printf("%d Waiting... ", i);
manumaet 11:c87d37db2c6f 91
manumaet 11:c87d37db2c6f 92 uint64_t status;
manumaet 11:c87d37db2c6f 93 dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
manumaet 11:c87d37db2c6f 94 status &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 95 pc.printf("Status: %010llX\r\n", status);
manumaet 11:c87d37db2c6f 96
manumaet 10:d077bb12d259 97 wait(1);
manumaet 0:f50e671ffff7 98 # endif
manumaet 4:6240b9c7a033 99
manumaet 0:f50e671ffff7 100 }
manumaet 0:f50e671ffff7 101 }