Matthias Grob & Manuel Stalder / Mbed 2 deprecated DecaWave

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
manumaet
Date:
Sun Nov 23 14:34:31 2014 +0000
Parent:
11:c87d37db2c6f
Child:
13:b4d27bf7062a
Commit message:
before fusing SENDER and RECEIVER

Changed in this revision

DW1000/DW1000.cpp Show annotated file Show diff for this revision Revisions of this file
DW1000/DW1000.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/DW1000/DW1000.cpp	Sun Nov 23 11:20:46 2014 +0000
+++ b/DW1000/DW1000.cpp	Sun Nov 23 14:34:31 2014 +0000
@@ -5,14 +5,11 @@
     spi.format(8,0);                    // Setup the spi for standard 8 bit data and SPI-Mode 0 (GPIO5, GPIO6 open circuit or ground on DW1000)
     spi.frequency(1000000);             // with a 1MHz clock rate (worked up to 49MHz in our Test)
     
-    uint16_t ldeload[] = {0x0301, 0x8000, 0x0200};
-    writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[0], 2);                 // initialise LDELOAD User Manual p22
-    writeRegister(DW1000_OTP_IF, 0x06, (uint8_t*)&ldeload[1], 2);
-    wait_us(150);
-    writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[2], 2);
+    //resetAll();                       // we can do a soft reset if we want to (only needed for debugging)
+    loadLDE();                          // important everytime DW1000 initialises/awakes otherwise the LDE algorithm must be turned of or there's receiving malfunction see User Manual LDELOAD on p22 & p158
+    writeRegister8(DW1000_SYS_CFG, 3, 0x20); // enable auto reenabling receiver after error
     
     irq.rise(this, &DW1000::ISR);       // attach Interrupt handler to rising edge
-    resetRX();
 }
 
 uint32_t DW1000::getDeviceID() {
@@ -32,7 +29,7 @@
 }
 
 float DW1000::getVoltage() {
-    uint8_t buffer[7] = {0x80, 0x0A, 0x0F, 0x01, 0x00};             // algorithm form DW1000 User Manual p57
+    uint8_t buffer[7] = {0x80, 0x0A, 0x0F, 0x01, 0x00};             // algorithm form User Manual p57
     writeRegister(DW1000_RF_CONF, 0x11, buffer, 2);
     writeRegister(DW1000_RF_CONF, 0x12, &buffer[2], 1);
     writeRegister(DW1000_TX_CAL, 0x00, &buffer[3], 1);
@@ -73,14 +70,33 @@
 }
 
 void DW1000::ISR() {
-    callbackRX();
+    uint64_t status;                                                // get the entire system status
+    readRegister(DW1000_SYS_STATUS, 0, (uint8_t*)&status, 5);
+    status &= 0xFFFFFFFFFF;                                         // only 40-Bit
+    if (status & 0x4000)
+        callbackRX();
+    if (status & 0x80)
+        ;//callbackTX();                                            // TODO: mask TX done interrupt make TX handler
 }
 
-void DW1000::resetRX() {
-    uint8_t resetrx = 0xE0;     //set rx reset
-    writeRegister(DW1000_PMSC, 3, &resetrx, 1);
-    resetrx = 0xf0;             //clear RX reset
-    writeRegister(DW1000_PMSC, 3, &resetrx, 1);
+void DW1000::loadLDE() {
+    uint16_t ldeload[] = {0x0301, 0x8000, 0x0200};                  // initialise LDE algorithm LDELOAD User Manual p22
+    writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[0], 2);        // set clock to XTAL so OTP is reliable
+    writeRegister(DW1000_OTP_IF, 0x06, (uint8_t*)&ldeload[1], 2);   // set LDELOAD bit in OTP
+    wait_us(150);
+    writeRegister(DW1000_PMSC, 0, (uint8_t*)&ldeload[2], 2);        // recover to PLL clock
+}
+
+void DW1000::resetRX() {    
+    writeRegister8(DW1000_PMSC, 3, 0xE0);   // set RX reset
+    writeRegister8(DW1000_PMSC, 3, 0xF0);   // clear RX reset
+}
+
+void DW1000::resetAll() {
+    writeRegister8(DW1000_PMSC, 0, 0x01);   // set clock to XTAL
+    writeRegister8(DW1000_PMSC, 3, 0x00);   // set All reset
+    wait_us(10);                            // wait for PLL to lock
+    writeRegister8(DW1000_PMSC, 3, 0xF0);   // clear All reset
 }
 
 // SPI Interface ------------------------------------------------------------------------------------
@@ -124,5 +140,5 @@
     }
 }
 
-void DW1000::select() { cs = 0; }    //Set CS low to start transmission
-void DW1000::deselect() { cs = 1; }    //Set CS high to stop transmission
\ No newline at end of file
+void DW1000::select() { cs = 0; }    // set CS low to start transmission
+void DW1000::deselect() { cs = 1; }    // set CS high to stop transmission
\ No newline at end of file
--- a/DW1000/DW1000.h	Sun Nov 23 11:20:46 2014 +0000
+++ b/DW1000/DW1000.h	Sun Nov 23 14:34:31 2014 +0000
@@ -70,8 +70,10 @@
         // Interrupt
         void (*callbackRX) ();
         void ISR();
-    
+
+        void loadLDE();                                                                         // load the leading edge detection algorithm to RAM, [IMPORTANT because receiving malfunction may ocur] see User Manual LDELOAD on p22 & p158
         void resetRX();
+        void resetAll();
         
         // SPI Inteface
         SPI spi;                                                                                // SPI Bus
--- a/main.cpp	Sun Nov 23 11:20:46 2014 +0000
+++ b/main.cpp	Sun Nov 23 14:34:31 2014 +0000
@@ -7,19 +7,19 @@
 
 
 uint64_t timestamp_old = 0;
-//#define SENDER
+#define SENDER
 
 void Interrupthandler() {
     /*uint8_t frameready = 0;
     dw.readRegister(DW1000_SYS_STATUS, 1, &frameready, 1);
     pc.printf("Interrupt status: %X\r\n", frameready);*/
     
-    uint16_t framelength = 0;                                       // get framelength
+    uint16_t framelength = 0;                                       // get framelength TODO: just for debugging of string
     dw.readRegister(DW1000_RX_FINFO, 0, (uint8_t*)&framelength, 2);
     framelength &= 0x03FF;
     framelength -= 2;
     
-    char* receive = dw.receiveString();
+    char* receive = dw.receiveString();                             // receive a string
     pc.printf("Received: %s %d   ", receive, framelength);
     delete[] receive;
     
@@ -35,11 +35,6 @@
     timestamp_old = timestamp;
     pc.printf("Timestamp: %lld\r\n", difference);
     
-    /*uint8_t xtalt;                            // for clock tuning
-    dw.readRegister(DW1000_FS_CTRL, 0x0E, (uint8_t*)&xtalt, 1);
-    pc.printf("XTALT: %X\r\n", xtalt);*/
-    
-    //dw.resetRX();                                                   // TODO DONE: reset was crucial because otherwise only 1 frame is received correct, cause: LDE crashing because you have to manually initialize
     dw.receiveFrame();
 }
 
@@ -53,19 +48,15 @@
     pc.printf("%d EUI register: %016llX\r\n", i, dw.getEUI());
     pc.printf("%d Voltage: %f\r\n", i, dw.getVoltage());
     
-    // read System Configuration
-    uint32_t conf = 0;
+    uint32_t conf = 0;     // read System Configuration
     dw.readRegister(DW1000_SYS_CFG, 0, (uint8_t*)&conf, 4);
     pc.printf("%d System Configuration: %X\r\n", i, conf);
     
-    wait(1);
-    
     dw.callbackRX = &Interrupthandler;
 #ifndef SENDER
     uint8_t dataframereadyinterrupt = 0x40; // only good frame 0x40 all frames 0x20
     dw.writeRegister(DW1000_SYS_MASK, 1, &dataframereadyinterrupt, 1);
     
-    // Receive something
     dw.receiveFrame();
 #endif