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 20 16:00:34 2014 +0000
Revision:
9:c8839de428ac
Parent:
8:7a9c61242e2f
Child:
10:d077bb12d259
wroking sender and receiver with interrupt

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 8:7a9c61242e2f 8 #define SENDER
manumaet 5:111f11c95d27 9
manumaet 6:d5864a1b9e17 10 void Interrupthandler() {
manumaet 7:e634eeafc4d2 11 uint8_t frameready = 0;
manumaet 7:e634eeafc4d2 12 dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
manumaet 8:7a9c61242e2f 13 pc.printf("Interrupt status: %X\r\n", frameready);
manumaet 7:e634eeafc4d2 14 // get data from buffer
manumaet 7:e634eeafc4d2 15 uint8_t receive[20] = "NOTHING IN!!";
manumaet 7:e634eeafc4d2 16 dw.readRegister(DW1000_RX_BUFFER, 0, receive, 20);
manumaet 8:7a9c61242e2f 17 pc.printf("Message received: %s\r\n", receive);
manumaet 7:e634eeafc4d2 18 dw.resetRX();
manumaet 8:7a9c61242e2f 19 dw.receiveFrame();
manumaet 6:d5864a1b9e17 20 }
manumaet 6:d5864a1b9e17 21
manumaet 0:f50e671ffff7 22 int main() {
manumaet 4:6240b9c7a033 23 int i=0;
manumaet 0:f50e671ffff7 24 pc.printf("DecaWave 0.1\r\nup and running!\r\n");
manumaet 0:f50e671ffff7 25
manumaet 0:f50e671ffff7 26 dw.setEUI(0xFAEDCD01FAEDCD01);
manumaet 4:6240b9c7a033 27 pc.printf("%d DEVICE_ID register: 0x%X\r\n", i, dw.getDeviceID());
manumaet 4:6240b9c7a033 28 pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
manumaet 4:6240b9c7a033 29 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 0:f50e671ffff7 30
manumaet 4:6240b9c7a033 31 // read System Configuration
manumaet 4:6240b9c7a033 32 uint32_t conf = 0;
manumaet 4:6240b9c7a033 33 dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
manumaet 4:6240b9c7a033 34 pc.printf("%d System Configuration: %X\r\n", i, conf);
manumaet 4:6240b9c7a033 35
manumaet 7:e634eeafc4d2 36 wait(1);
manumaet 5:111f11c95d27 37
manumaet 8:7a9c61242e2f 38 dw.callbackRX = &Interrupthandler;
manumaet 9:c8839de428ac 39 #ifndef SENDER
manumaet 5:111f11c95d27 40 uint8_t dataframereadyinterrupt = 0x20; // only good frame would be 0x40
manumaet 5:111f11c95d27 41 dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
manumaet 7:e634eeafc4d2 42
manumaet 7:e634eeafc4d2 43 // Receive something
manumaet 8:7a9c61242e2f 44 dw.receiveFrame();
manumaet 5:111f11c95d27 45 #endif
manumaet 5:111f11c95d27 46
manumaet 0:f50e671ffff7 47 while(1) {
manumaet 0:f50e671ffff7 48 i++;
manumaet 0:f50e671ffff7 49
manumaet 5:111f11c95d27 50 # ifdef SENDER // to make one node sender and one receiver
manumaet 0:f50e671ffff7 51 // Send something
manumaet 8:7a9c61242e2f 52 char message[20];
manumaet 4:6240b9c7a033 53 sprintf((char*)message, "HELLO WORLD! %d", i);
manumaet 4:6240b9c7a033 54 dw.sendFrame(message, 20);
manumaet 0:f50e671ffff7 55
manumaet 9:c8839de428ac 56 uint8_t messagecheck[20];
manumaet 4:6240b9c7a033 57 dw.readRegister(DW1000_TX_BUFFER, 0, messagecheck, 20);
manumaet 9:c8839de428ac 58 pc.printf("Message in buffer: %s\r\nSending...\r\n", messagecheck);
manumaet 9:c8839de428ac 59 /*for(int i=0; i<10; i++) { // to control Voltage
manumaet 9:c8839de428ac 60 pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
manumaet 9:c8839de428ac 61 wait(0.2);
manumaet 9:c8839de428ac 62 }*/
manumaet 9:c8839de428ac 63 wait(0.1);
manumaet 8:7a9c61242e2f 64 #else
manumaet 8:7a9c61242e2f 65 pc.printf("%d Waiting...\r\n", i);
manumaet 8:7a9c61242e2f 66 wait(5);
manumaet 0:f50e671ffff7 67 # endif
manumaet 4:6240b9c7a033 68
manumaet 0:f50e671ffff7 69 }
manumaet 0:f50e671ffff7 70 }