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:
10:d077bb12d259
Parent:
8:7a9c61242e2f
Child:
11:c87d37db2c6f
--- a/DW1000/DW1000.cpp	Thu Nov 20 16:00:34 2014 +0000
+++ b/DW1000/DW1000.cpp	Fri Nov 21 14:33:23 2014 +0000
@@ -37,13 +37,26 @@
     return Voltage;
 }
 
-void DW1000::sendFrame(char* message, int length) {
-    writeRegister(DW1000_TX_BUFFER, 0, (uint8_t*)message, length);  // fill buffer
+void DW1000::sendString(char* message) {
+    sendFrame((uint8_t*)message, strlen(message)+1);
+}
+
+char* DW1000::receiveString() {
+    uint16_t framelength = 0;                                       // get framelength
+    readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
+    framelength = (framelength & 0x03FF) - 2;                       // take only the right bits and subtract the 2 CRC Bytes
+    char* receive = new char[framelength];                          // get data from buffer
+    readRegister(DW1000_RX_BUFFER, 0, (uint8_t*)receive, framelength);
+    return receive;
+}
+
+void DW1000::sendFrame(uint8_t* message, int length) {
+    writeRegister(DW1000_TX_BUFFER, 0, message, length);  // fill buffer
     
     uint16_t framelength = length+2;                                // put length of frame including 2 CRC Bytes
-    writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1);
+    writeRegister(DW1000_TX_FCTRL, 0, (uint8_t*)&framelength, 1);   // TODO: make that bigger frames than 256 can be sent
     
-    writeRegister8(DW1000_SYS_CTRL, 0, 0x02);                       // trigger sending process by setting the TXSTRT bit
+    //writeRegister8(DW1000_SYS_CTRL, 0, 0x02);                       // trigger sending process by setting the TXSTRT bit
 }
 
 void DW1000::receiveFrame() {
@@ -62,13 +75,18 @@
 }
 
 // SPI Interface ------------------------------------------------------------------------------------
+uint8_t DW1000::readRegister8(uint8_t reg, uint16_t subaddress) {
+    uint8_t result;
+    readRegister(reg, subaddress, &result, 1);
+    return result;
+}
+
 void DW1000::writeRegister8(uint8_t reg, uint16_t subaddress, uint8_t buffer) {
     writeRegister(reg, subaddress, &buffer, 1);
 }
 
 void DW1000::readRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length) {
     setupTransaction(reg, subaddress, false);
-    
     for(int i=0; i<length; i++)     // get data
         buffer[i] = spi.write(0x00);
     deselect();
@@ -76,7 +94,6 @@
 
 void DW1000::writeRegister(uint8_t reg, uint16_t subaddress, uint8_t *buffer, int length) {
     setupTransaction(reg, subaddress, true);
-    
     for(int i=0; i<length; i++)     // put data
         spi.write(buffer[i]);
     deselect();