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:
Mon Nov 24 14:09:49 2014 +0000
Revision:
17:8afa5f9122da
Parent:
16:96879e1c99f2
Child:
18:bbc7ca7d3a95
1021 string now works with API

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 15:e1fea7e2aff1 8 const float timeunit = 1/(128*499.2e6);
manumaet 14:8041c9b68406 9 int i=0;
manumaet 17:8afa5f9122da 10 char message[1200] = "";
manumaet 11:c87d37db2c6f 11 uint64_t timestamp_old = 0;
manumaet 14:8041c9b68406 12
manumaet 15:e1fea7e2aff1 13 //#define PINGPONG
manumaet 5:111f11c95d27 14
manumaet 6:d5864a1b9e17 15 void Interrupthandler() {
manumaet 10:d077bb12d259 16 /*uint8_t frameready = 0;
manumaet 7:e634eeafc4d2 17 dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
manumaet 10:d077bb12d259 18 pc.printf("Interrupt status: %X\r\n", frameready);*/
manumaet 10:d077bb12d259 19
manumaet 12:985aa9843c3c 20 uint16_t framelength = 0; // get framelength TODO: just for debugging of string
manumaet 10:d077bb12d259 21 dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
manumaet 10:d077bb12d259 22 framelength &= 0x03FF;
manumaet 10:d077bb12d259 23 framelength -= 2;
manumaet 10:d077bb12d259 24
manumaet 16:96879e1c99f2 25 if(framelength<200) {
manumaet 16:96879e1c99f2 26 char* receive = dw.receiveString(); // receive a string
manumaet 16:96879e1c99f2 27 pc.printf("Received: \"%s\" %d ", receive, framelength);
manumaet 16:96879e1c99f2 28 delete[] receive;
manumaet 16:96879e1c99f2 29 } else
manumaet 16:96879e1c99f2 30 pc.printf("Received! %d ", framelength);
manumaet 10:d077bb12d259 31
manumaet 11:c87d37db2c6f 32 uint64_t status;
manumaet 11:c87d37db2c6f 33 dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
manumaet 11:c87d37db2c6f 34 status &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 35 pc.printf("Status: %010llX ", status);
manumaet 11:c87d37db2c6f 36
manumaet 11:c87d37db2c6f 37 uint64_t timestamp;
manumaet 11:c87d37db2c6f 38 dw.readRegister(DW1000_RX_TIME, 0, (uint8_t*)&timestamp, 5);
manumaet 11:c87d37db2c6f 39 timestamp &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 40 uint64_t difference = timestamp - timestamp_old;
manumaet 11:c87d37db2c6f 41 timestamp_old = timestamp;
manumaet 15:e1fea7e2aff1 42 //pc.printf("Timestamp: %lld\r\n", difference);
manumaet 15:e1fea7e2aff1 43 pc.printf("Timestamp: %fs", difference*timeunit); // TODO: gives some wrong values because of timer overflow
manumaet 15:e1fea7e2aff1 44 pc.printf("\r\n");
manumaet 17:8afa5f9122da 45 dw.startRX();
manumaet 6:d5864a1b9e17 46 }
manumaet 6:d5864a1b9e17 47
manumaet 0:f50e671ffff7 48 int main() {
manumaet 0:f50e671ffff7 49 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 0:f50e671ffff7 50
manumaet 14:8041c9b68406 51 dw.setEUI(0xFAEDCD01FAEDCD01); // basic methods called to check if we have a slave
manumaet 4:6240b9c7a033 52 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 53 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 54 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 55
manumaet 12:985aa9843c3c 56 uint32_t conf = 0; // read System Configuration
manumaet 4:6240b9c7a033 57 dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
manumaet 4:6240b9c7a033 58 pc.printf("%d System Configuration: %X\r\n", i, conf);
manumaet 4:6240b9c7a033 59
manumaet 8:7a9c61242e2f 60 dw.callbackRX = &Interrupthandler;
manumaet 14:8041c9b68406 61
manumaet 14:8041c9b68406 62 // Receiver initialisation
manumaet 10:d077bb12d259 63 uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
manumaet 5:111f11c95d27 64 dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
manumaet 17:8afa5f9122da 65 dw.startRX();
manumaet 5:111f11c95d27 66
manumaet 0:f50e671ffff7 67 while(1) {
manumaet 17:8afa5f9122da 68 #if 1
manumaet 17:8afa5f9122da 69 if(i < 1200) {
manumaet 17:8afa5f9122da 70 message[i] = 48+ (i%10);
manumaet 17:8afa5f9122da 71 message[i+1] = '\0';
manumaet 17:8afa5f9122da 72 }
manumaet 16:96879e1c99f2 73
manumaet 16:96879e1c99f2 74 //wait(0.1);
manumaet 17:8afa5f9122da 75 char messagecheck[1200];
manumaet 10:d077bb12d259 76 dw.sendString(message);
manumaet 17:8afa5f9122da 77 wait_us(10000);
manumaet 10:d077bb12d259 78 dw.readRegister(DW1000_TX_BUFFER, 0, (uint8_t*)messagecheck, strlen(message)+1);
manumaet 17:8afa5f9122da 79 if (i < 200)
manumaet 17:8afa5f9122da 80 pc.printf("%d Sent: \"%s\" %d\r\n", i, messagecheck, strlen(message)+1);
manumaet 17:8afa5f9122da 81 else
manumaet 17:8afa5f9122da 82 pc.printf("%d Sent! %d\r\n", i, strlen(message)+1);
manumaet 15:e1fea7e2aff1 83
manumaet 17:8afa5f9122da 84 #endif
manumaet 15:e1fea7e2aff1 85 #if 0
manumaet 15:e1fea7e2aff1 86 pc.printf("%d Waiting... ", i);
manumaet 11:c87d37db2c6f 87 uint64_t status;
manumaet 11:c87d37db2c6f 88 dw.readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
manumaet 11:c87d37db2c6f 89 status &= 0xFFFFFFFFFF; // only 40-Bit
manumaet 11:c87d37db2c6f 90 pc.printf("Status: %010llX\r\n", status);
manumaet 15:e1fea7e2aff1 91 wait(5);
manumaet 15:e1fea7e2aff1 92 #endif
manumaet 15:e1fea7e2aff1 93 i++;
manumaet 0:f50e671ffff7 94 }
manumaet 0:f50e671ffff7 95 }