DW1000 UWB driver based on work of Matthias Grob & Manuel Stalder - ETH Zürich - 2015

Dependencies:   BurstSPI

Files at this revision

API Documentation at this revision

Comitter:
AndyA
Date:
Tue Apr 05 11:37:23 2016 +0000
Parent:
0:bddb8cd5e7df
Child:
3:1459d2aa6b97
Child:
16:2080adef6fa6
Commit message:
Simplified OTP;

Changed in this revision

DW1000.cpp Show annotated file Show diff for this revision Revisions of this file
DW1000.h Show annotated file Show diff for this revision Revisions of this file
--- a/DW1000.cpp	Tue Apr 05 10:51:00 2016 +0000
+++ b/DW1000.cpp	Tue Apr 05 11:37:23 2016 +0000
@@ -141,7 +141,7 @@
     writeRegister8(DW1000_TX_CAL, 0x00, 0x01);
     writeRegister8(DW1000_TX_CAL, 0x00, 0x00);
     data = readRegister8(DW1000_TX_CAL, 0x03);               // get the 8-Bit reading for Voltage
-    float Voltage = (float)(data - readOTP8(0x08)) *0.00578 + 3.3;
+    float Voltage = (float)(data - (readOTP(0x08)&0x00ff)) *0.00578 + 3.3;
     return Voltage;
 }
 
@@ -155,7 +155,7 @@
     writeRegister8(DW1000_TX_CAL, 0x00, 0x01);
     writeRegister8(DW1000_TX_CAL, 0x00, 0x00);
     data = readRegister16(DW1000_TX_CAL, 0x04);               // get the 8-Bit reading for Temperature
-    float temperature =  (float)(data - readOTP8(0x09))*0.9 + 23;
+    float temperature =  (float)(data - (readOTP(0x09) & 0x00ff))*0.9 + 23;
     return temperature;
 }
 
@@ -267,10 +267,11 @@
 
 void DW1000::loadLDOTUNE()
 {
-    uint64_t LDOTuningValue = readOTP40(0x0004);
-    if (LDOTuningValue != 0)
+    uint64_t LDOTuningValue = readOTP(0x0004);
+    if (LDOTuningValue != 0) {
+        LDOTuningValue = LDOTuningValue | ((uint64_t)(readOTP(0x0005) & 0x00ff) << 32);
         writeRegister40(DW1000_RF_CONF,DWRFCONF_RF_LDOTUNE,LDOTuningValue);
-
+    }
 }
 
 void DW1000::resetRX()
@@ -294,7 +295,7 @@
 }
 
 /// After writes have been completed reset the device.
-bool DW1000::writeOTP(uint16_t address,uint32_t data)
+bool DW1000::writeOTP(uint16_t word_address,uint32_t data)
 {
     spi.frequency(SPIRATE_OSC);             // with a 1MHz clock rate (worked up to 49MHz in our Test)
 
@@ -325,13 +326,13 @@
 
     writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x00);  //
     writeRegister32(DW1000_OTP_IF,DWOTP_OTP_WDAT,data);  //
-    writeRegister16(DW1000_OTP_IF,DWOTP_OTP_ADDR,address);  //
+    writeRegister16(DW1000_OTP_IF,DWOTP_OTP_ADDR,word_address);  //
     writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x40);  //
     writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x00);  //
     wait_ms(1);
 
     for (int i=0; i<10; i++) {
-        if (readOTP32(address) == data)
+        if (readOTP(word_address) == data)
             return true;
         writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x40);  // retry
         writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x00);
@@ -340,19 +341,10 @@
     return false;
 }
 
-uint32_t DW1000::readOTP (uint16_t word_address, uint8_t size) {
-    if (size == 1)
-      return readOTP8(word_address);
-    else if (size == 2)
-      return readOTP16(word_address);
-    else
-      return readOTP32(word_address);   
-    }
 
-
-uint32_t DW1000::readOTP32(uint16_t address)
+uint32_t DW1000::readOTP(uint16_t word_address)
 {
-    writeRegister16(DW1000_OTP_IF,DWOTP_OTP_ADDR,address); // write address
+    writeRegister16(DW1000_OTP_IF,DWOTP_OTP_ADDR,word_address); // write address
     writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x03);  // read address load
     writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x01);  // read
     uint32_t data = readRegister32(DW1000_OTP_IF,DWOTP_OTP_RDAT);
@@ -360,16 +352,6 @@
     return data;
 }
 
-uint8_t DW1000::readOTP8(uint16_t address)
-{
-    writeRegister16(DW1000_OTP_IF,DWOTP_OTP_ADDR,address); // write address
-    writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x03);  // read address load
-    writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x01);  // read
-    uint8_t data = readRegister8(DW1000_OTP_IF,DWOTP_OTP_RDAT);
-    writeRegister8(DW1000_OTP_IF,DWOTP_OTP_CTRL,0x00);  // OTP idle
-    return data;
-}
-
 void DW1000::setInterrupt(bool RX, bool TX)
 {
     writeRegister16(DW1000_SYS_MASK, 0, RX*0x4000 | TX*0x0080);  // RX good frame 0x4000, TX done 0x0080
--- a/DW1000.h	Tue Apr 05 10:51:00 2016 +0000
+++ b/DW1000.h	Tue Apr 05 11:37:23 2016 +0000
@@ -197,7 +197,7 @@
         readRegister(DW1000_RX_BUFFER, 0, buffer, length);
     }
 
-    uint32_t readOTP (uint16_t word_address, uint8_t size);
+    uint32_t readOTP (uint16_t word_address);
     bool writeOTP(uint16_t word_address,uint32_t data);                                          // program a value in the OTP. It is recommended to reset afterwards.
 
 protected:
@@ -217,13 +217,6 @@
     FunctionPointer callbackTX;                                                             // function pointer to callback which is called when successfull TX took place
     void ISR();                                                                             // interrupt handling method (also calls according callback methods)
 
-
-    // OTP
-    uint8_t readOTP8(uint16_t address);
-    uint32_t readOTP32(uint16_t address);
-    uint64_t readOTP64(uint16_t address);
-    uint64_t readOTP40(uint16_t address);
-
     // SPI Inteface
     SPI spi;                                                                                // SPI Bus
     DigitalOut cs;                                                                          // Slave selector for SPI-Bus (here explicitly needed to start and end SPI transactions also usable to wake up DW1000)