AnsweredAssumed Answered

Adis16209 Problems Getting Data From It

Question asked by Messias on Dec 11, 2013
Latest reply on Jan 29, 2014 by NevadaMark

Hello!

 

I am during some days trying to put working the ADIS16209. However, I'm not getting it.

I started to try read the temperature register, but until now without success.

 

 

#include <SPI.h>

 

 

// ADIS16209 register addresses

const int X_ACCL = 0x04;

const int Y_ACCL = 0x06;

const int X_INCL = 0x0C;

const int Y_INCL = 0x0E;

const int ROT = 0x10;

const int TEMP = 0x0A;

const int SMPL_PRD = 0x36;  // Sample Rate

const int AVG_CNT = 0x38;   // Filter Configuration

 

void setup() {

  // initialize the serial communications:

  Serial.begin(57600);

 

  //////SPI SETUP/////////////

  SPI.begin();

  SPI.setClockDivider(SPI_CLOCK_DIV16);  // SPI 1MHz <--AS ON DATASHEET

  SPI.setDataMode(SPI_MODE3);  // CPOL=1 && CPHA=1 <-- AS ON DATASHEET

 

  // declare SS as output

  pinMode(SS, OUTPUT);

  digitalWrite(SS, HIGH);

  pinMode(49, OUTPUT);

  digitalWrite(49, HIGH);

 

 

  // PRINT TO SERIAL PORT 

  Serial.print("X_ACCL (mg)");

  Serial.print("\t");

  Serial.print("Y_ACCL (mg)");

  Serial.print("\t");

  Serial.print("X_INCL (grau)");

  Serial.print("\t");

  Serial.print("Y_INCL (grau)");

  Serial.print("\t");

  Serial.print("ROT (grau)");

  Serial.print("\t");

  Serial.print("TEMP (C)");

  Serial.println();

}

 

 

void loop() {

  Serial.println("TEMPERATURA: ");

  Serial.print( readTemp(), DEC); //////////TRYING READ TEMPERATURE

  Serial.println();

 

  readALLSensor();

  delay(1000);              

}

 

 

void readALLSensor() {

//  Serial.print( readRegister(X_ACCL), DEC);

//  Serial.print("\t");

//  Serial.print( readRegister(Y_ACCL), DEC);

//  Serial.print("\t");

//  Serial.print( readRegister(X_INCL), DEC);

//  Serial.print("\t");

//  Serial.print( readRegister(Y_INCL), DEC);

//  Serial.print("\t");

//  Serial.print( readRegister(ROT), DEC);

//  Serial.print("\t");

  Serial.print( readRegister(TEMP), DEC);

  Serial.println();

}

/***************************SEE THIS FUNCTION, I DID IT TO TEST THE READ OF A REGISTER*************/

float readTemp() {

  unsigned int result = 0;

  unsigned int lower = 0;

  unsigned int upper = 0;

  float result_converted = 0;

 

  digitalWrite(SS, LOW);

  delayMicroseconds(1); // Datasheet says 50 ns at least

  SPI.transfer(0x0A);  // Read the lower temperature bits

  lower = SPI.transfer(0x00);

 

  digitalWrite(SS, HIGH);

  delayMicroseconds(10);

  digitalWrite(SS, LOW);

  delayMicroseconds(1);

 

  SPI.transfer(0x0B);

  upper = SPI.transfer(0x00);

  upper = upper << 8;

  result = upper | lower;

  digitalWrite(SS, HIGH);

  delayMicroseconds(50);

 

 

    result_converted = (result & (0b0000111111111111));

    result_converted = (result_converted - 1278)*(-0.47) + 25;

 

return (result_converted);

}

 

float readRegister(byte thisRegister) {

  unsigned int upper = 0;

  unsigned int lower = 0;

  unsigned int result = 0;

  float result_converted = 0;

 

  digitalWrite(SS, LOW);

  delayMicroseconds(50);

  SPI.transfer(thisRegister);  // To put the 8th bit at 0/1 read/write: thisRegister &= ~(1u << 7)

  lower = SPI.transfer(0x00);

 

  upper = SPI.transfer(0x00);

  upper = upper << 8;

  result = upper | lower;

  digitalWrite(SS, HIGH);

  delayMicroseconds(10);

 

  //CONVERSION

  if (thisRegister == TEMP) {   // Temperature

    result_converted = (result & (0b0000111111111111));

    result_converted = (result_converted - 1278)*(-0.47) + 25;

  }

  else if ((result >> 13) & 1) {  // Inclinometer & Accelerometer

    result = result & (0b0011111111111111);

    result = ~result + 1;

    result_converted =(float)result*(-1);

    result_converted *= 0.025;

  }

  else {  // Inclinometer & Accelerometer

    result = result & (0b0011111111111111);

    result_converted = (float)result;

    result_converted *= 0.025;

  }

 

return result_converted;

}

 

I appreciate your attention and help. I already try a lot of things but without success.

 

Thank you,

Andre.

Outcomes