fork of Sam Grove's library

Fork of ADIS16488 by Sam Grove

Files at this revision

API Documentation at this revision

Comitter:
raprism
Date:
Tue Jan 10 22:22:51 2017 +0100
Parent:
2:e2e5e40668bf
Commit message:
- added ADIS16485 as correct model type
- removed redundant SPI writes

Changed in this revision

Adis16488.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e2e5e40668bf -r 4420cf0e0b74 Adis16488.cpp
--- a/Adis16488.cpp	Sat Apr 27 23:12:44 2013 +0000
+++ b/Adis16488.cpp	Tue Jan 10 22:22:51 2017 +0100
@@ -19,7 +19,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
- 
+
 #include "Adis16488.h"
 
 uint16_t const GYRO_REGS[]    = {0x1000, 0x1200, 0x1400, 0x1600, 0x1800, 0x1A00};
@@ -36,7 +36,7 @@
     _cs = &cs;
     _rst = &rst;
     _dr = &dr;
-    
+
     return;
 }
 
@@ -45,65 +45,67 @@
     _dr->mode(PullDown);
     _rst->write(0);
     _cs->write(0);
-    
-    _spi->format(16,3);
-    _spi->frequency(10000000);
-    
+
+    //_spi->format(16, 3); // needs to be done with spi.format()!
+    _spi->frequency(2000000);
+
     return;
 }
 
 void Adis16488::enable(void)
 {
     LOG("Preparing the ADIS16488 IMU\n");
-    
+
     _rst->write(1);
     wait(1.0);
-    
+
     writeRegister(0x8000);
-    writeRegister(0x7e00);
+    //writeRegister(0x7e00);
     uint16_t id;
-    readRegister(0x7e00, id);
-    if(id != 0x4068)
+    readRegister(0x7e00, id); // actually writes also to register!
+    if(id != 0x4068 && id != 0x4065)
     {
         ERROR("Product ID doesn't match, %04X\n", id);
     }
-    LOG("Product ID is %04X\n", id);
-    
+    LOG("Product ID is %05u (%04X).\n", id, id);
     //this result correctly returns 0x4068 as per the ADIS16488 specification
-    //get the SERIAL_NUM (page 4, reg: 0x20)  
+
+    //get the SERIAL_NUM (page 4, reg: 0x20)
     writeRegister(0x8004);     //first change the page to page 4
     writeRegister(0x2000);     //send the register to get on the next write
     uint16_t serial_num;
     readRegister(0x2000, serial_num);
     LOG("IMU serial number is %04X\n", serial_num);
-    
+
     writeRegister(0x8003);     //change to page 3
-    writeRegister(0x7800);     //get FIRMWARE_REV
+    //writeRegister(0x7800);     //get FIRMWARE_REV
     uint16_t rev;
     readRegister(0x7800, rev);
     LOG("Firmware revision %04X\n", rev);
-    
-    writeRegister(0x7A00);     //get FIRMWARE_DM
+
+    //writeRegister(0x7A00);     //get FIRMWARE_DM
     uint16_t rev_dm;
     readRegister(0x7A00, rev_dm);
-    
-    writeRegister(0x7C00);     //get FIRMWARE_YR
+
+    //writeRegister(0x7C00);     //get FIRMWARE_YR
     uint16_t rev_yr;
     readRegister(0x7C00, rev_yr);
-    LOG("Frimware date/month/year is %02X/%02X/%04X\n", ((rev_dm>>8)&0xff), (rev_dm&0xff), rev_yr);
-    
-    //change the DECRATE to 98.4 Hz (this is also in page 3)
+    LOG("Firmware date.month.year is %02X/%02X/%04X\n", (rev_dm&0xff), ((rev_dm>>8)&0xff), rev_yr);
+
+    // change the DEC_RATE (this is also in page 3)
+    // sampling rate is 2460/(DEC_RATE+1)Hz
+    // so for 0x17: 102.5 Hz
     writeRegister(0x8C17);     //write high byte  (only page number can be written in a single byte)
-    writeRegister(0x8D00);     //write the low byte of DECRATE
-    
+    writeRegister(0x8D00);     //write the low byte of DEC_RATE
+
     // using varf...
 //    writeRegister(0x86CD);     //write high byte to register 0x06
 //    writeRegister(0x8700);     //write the low byte of 00 to registed 0x07
     writeRegister(0x8000);     //change to page 0
-    
-    // configred so IRQ is allowed
+
+    // configured so IRQ is allowed
     _dr->rise(this, &Adis16488::drHandler);
-    
+
     return;
 }
 
@@ -114,12 +116,12 @@
 }
 
 void Adis16488::readRegister(uint16_t const reg, uint16_t &data)
-{    
+{
     _cs->write(0);
     _spi->write(reg);
     data = _spi->write(reg);
     _cs->write(1);
-    
+
     return;
 }
 
@@ -128,7 +130,7 @@
     _cs->write(0);
     _spi->write(reg);
     _cs->write(1);
-    
+
     return;
 }
 
@@ -160,7 +162,6 @@
     {
         readRegister(DELTVEL_REGS[i], deltvel.data[i]);
     }
-    
+
     return;
 }
-