Go Down

Topic: SPI read problem, IMU unit ADIS16354 (Read 2331 times) previous topic - next topic

Graynomad

Did you try increasing the delay?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Nick Gammon


I do not have where or how to check if it works correctly.
...
If it helped someone, I do not know much about at that.


I don't know here if he is saying it works, it doesn't work, or he doesn't know if it works or not.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Graynomad

Rob Gray aka the GRAYnomad www.robgray.com

mmichalll

#18
Sep 11, 2011, 02:16 pm Last Edit: Sep 11, 2011, 08:01 pm by mmichalll Reason: 1
My code work.
Reading the values, but I do not know if the correct.
I modifi code, i read x, y, z accel,, x, y, z gyro,, and x,y,z temperature.
I increase delay slightly.

Here is code: code work read values - values ??probably are not all right
Code: [Select]
/*
Arduino Duemilanove and Tri axis senzor ADIS16354
Datasheet:
http://www.analog.com/static/imported-files/data_sheets/ADIS16354.pdf

pin 10               CS -     SS - vo?ba SPI zariadenia            
pin 11               DIN -    MOSI - Master-out, Slave-in - digitálny vstup, slúži na zápis dát z Arduina do senzora  
pin 12               DOUT -   MISO - Master-in, Slave out - digitálny výstup, slúži na ?ítanie dát zo senzora do Arduina
pin 13               SCK -    SCLK - Serial clock - nastavenie hodín a frekvencie
*/

#include <SPI.h>

int ss=10; // vyberieme SPI zariadenie, kedže sa používa iba jedno bude stále  táto hodnota nastavená na 10
byte ax, ay, az;
byte gx, gy, gz;
byte tx, ty, tz;
word datax, datay, dataz;
word dataxg, datayg, datazg;
word dataxt, datayt, datazt;
word data;

void setup()
{
 Serial.begin (9600);
 pinMode(ss, LOW); // používa sa pin 10
 SPI.begin(); // inicialuzuje sa SPI
 SPI.setDataMode(SPI_MODE3);
 SPI.setBitOrder(MSBFIRST);  // is MSBFIRST correct ??
 // senzor posle najskor MSB (most significant byte) bit ako prvý
digitalWrite (SMPL_PRD, 0x0A);
//SPI.transfer(0x0a);  // set the IMU to read so the next command will get valid data
//SPI.transfer(0x0b);
}

void loop()
{
//=================================================
// Accelerometer read data
//=================================================
//read x accel
digitalWrite(ss,LOW);
delayMicroseconds(160);
ax=SPI.transfer(0x0a);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
datax=(ax<<8);
Serial.print("X Accel: ");
Serial.print(datax, DEC);
Serial.print("\t");
delay(200);
//=================================================
//read y accel
digitalWrite(ss,LOW);
delayMicroseconds(160);
ay=SPI.transfer(0x0c);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
datay=(ay<<8);
Serial.print("Y Accel: ");
Serial.print((ay<<8), DEC);
Serial.print("\t");
delay(200);
//=================================================
//read z accel
digitalWrite(ss,LOW);
delayMicroseconds(160);
az=SPI.transfer(0x0e);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
dataz=(az<<8);
Serial.print("Z Accel: ");
Serial.println((az<<8), DEC);
delay(200);

//=================================================
// Gyroscope read data
//=================================================

//read x gyro
digitalWrite(ss,LOW);
delayMicroseconds(160);
gx=SPI.transfer(0x04);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
dataxg=(gx<<8);
Serial.print("X Gyro: ");
Serial.print(dataxg, DEC);
Serial.print("\t");
delay(200);
//=================================================
//read y gyro
digitalWrite(ss,LOW);
delayMicroseconds(160);
gy=SPI.transfer(0x06);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
datayg=(gy<<8);
Serial.print("Y Gyro: ");
Serial.print((gy<<8), DEC);
Serial.print("\t");
delay(200);
//=================================================
//read Z gyro
digitalWrite(ss,LOW);
delayMicroseconds(160);
gz=SPI.transfer(0x08);
delayMicroseconds(160);
digitalWrite(ss,HIGH);
datazg=(gz<<8);
Serial.print("Z Gyro: ");
Serial.println((gz<<8), DEC);
delay(200);

//=================================================
// Temperature read data --- ?ítanie teploty
//=================================================

//read x temp
digitalWrite(ss,LOW);
delayMicroseconds(200);
tx=SPI.transfer(0x10);
delayMicroseconds(200);
digitalWrite(ss,HIGH);
dataxt=(tx<<8);
Serial.print("X Teplota: ");
Serial.print((tx<<8), DEC);
Serial.print("\t");
delay(200);
//=================================================
//read y temp
digitalWrite(ss,LOW);
delayMicroseconds(200);
ty=SPI.transfer(0x12);
delayMicroseconds(200);
digitalWrite(ss,HIGH);
datayt=(ay<<8);
Serial.print("Y Teplota: ");
Serial.print((ty<<8), DEC);
Serial.print("\t");
delay(200);
//=================================================
//read z temp
digitalWrite(ss,LOW);
delayMicroseconds(200);
tz=SPI.transfer(0x14);
delayMicroseconds(200);
digitalWrite(ss,HIGH);
datazt=(tz<<8);
Serial.print("Z Teplota: ");
Serial.println((tz<<8), DEC);
delay(200);
}

Here is the result when the sensor is in peace:
Code: [Select]
X Accel: 0 Y Accel: 0 Z Accel: -16640
X Gyro: 60928 Y Gyro: -18688 Z Gyro: -27392
X Teplota: -32768 Y Teplota: 512 Z Teplota: -32768
X Accel: 15616 Y Accel: -32768 Z Accel: 13568
X Gyro: 48896 Y Gyro: -17152 Z Gyro: -16640
X Teplota: -512 Y Teplota: -32768 Z Teplota: 1280
X Accel: 32768 Y Accel: 14848 Z Accel: -32768
X Gyro: 9728 Y Gyro: -18688 Z Gyro: -31488
X Teplota: -16640 Y Teplota: -256 Z Teplota: -32768

Here is the result when the sensor moves:
Code: [Select]
X Accel: 0 Y Accel: 0 Z Accel: 0
X Gyro: 64512 Y Gyro: 5632 Z Gyro: -16384
X Teplota: -21760 Y Teplota: -16384 Z Teplota: -24064
X Accel: 49152 Y Accel: 15616 Z Accel: -16384
X Gyro: 35328 Y Gyro: -1280 Z Gyro: -25088
X Teplota: -14592 Y Teplota: -17408 Z Teplota: -16384
X Accel: 16640 Y Accel: -16384 Z Accel: 14592
X Gyro: 64512 Y Gyro: -1024 Z Gyro: -768
X Teplota: -29440 Y Teplota: -2048 Z Teplota: 0
X Accel: 0 Y Accel: 15616 Z Accel: 0
X Gyro: 0 Y Gyro: 0 Z Gyro: 0
X Teplota: 0 Y Teplota: 0 Z Teplota: 0
X Accel: 0 Y Accel: -16384 Z Accel: 14592
X Gyro: 63744 Y Gyro: 2048 Z Gyro: 0
X Teplota: 0 Y Teplota: -3072 Z Teplota: -12032

Almost the same values.

Here is arduino code  http://arduino.cc/forum/index.php/topic,13298.0.html
There is described the function which reads 8 bits and 16 bits back.(I tried this function but without result)
It is the fifth report.

BTW: I find site http://www.gammon.com.au/forum/?id=10979
I try code from this side modify to my senzor. Here is code:
Code: [Select]
byte ss=10; //CS pin 10
byte dataxg;
#include <SPI.h>
#define XGYRO_OUT 0x04

void xgyro_out (const byte ss, unsigned int address, byte * dataxg, unsigned int length)
{
 if (length == 0)  // don't bother if nothing to do
    return;

 digitalWrite (ss, LOW);     // select device
 SPI.transfer (XGYRO_OUT);       // read mode
 SPI.transfer (address >> 8);    // high-order address byte
 SPI.transfer (address & 0x04);  // low-order address byte
 for ( ; length ; --length)
   *dataxg++ = SPI.transfer (0);     // data byte
 digitalWrite (ss, HIGH);    // deselect device
}

void setup()
{
 Serial.begin (9600);
 pinMode(ss, HIGH); // používa sa pin 10
 SPI.begin(); // inicialuzuje sa SPI
 SPI.setDataMode(SPI_MODE3);
 SPI.setClockDivider(SPI_CLOCK_DIV64);
 SPI.setBitOrder(MSBFIRST);
}
void loop()
{
char buf [100];
xgyro_out (ss, 100, (byte *) buf, sizeof buf);
Serial.print("X Gyro: ");
Serial.print(buf);
Serial.println("\t");
delay(200);
}

Code work, but results are very wild :(
Code: [Select]
X Gyro: ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÂ
X Gyro:
X Gyro:
X Gyro: ÿ
X Gyro:
X Gyro: ÿ
X Gyro:
X Gyro: À

Khyzer

Hello everyone,

I have been trying to do something similar to what is written in this post and stuck with the same problem as mentioned here. I am unable to read the sensor data sent back from the sensor. I am using ADIS16210 accelerometer sensor which is connected to Arduino UNO board through SPI pins.

I am trying to get the Product ID of the sensor by accessing its PROD_ID register, According to oscilloscope waveform output of my program I am able to see register address being sent at the MOSI pin as request but on MOSI I always see same output waveform (reflecting 0x40) and on serial monitor it shows 1024 always. please refer to the attached code and let me know how to get the value from sensor and display it on my serial monitor. If you are successful in getting response from Arduino then please le me know how to write code for that part i.e reading bytes from the slave device. I feel that's the tricky part for SPI communication.


As per datasheet  =(I have raised the CS pin after each 16 bit cycle and introduced a delay of 45us to avoid minimum stall time of the sensor. Please refer to page 4 & 7 of the datasheet at below link for more understanding.

http://www.analog.com/en/mems-sensors/low-g-accelerometers/adis16210/products/product.html

Please let me know if you require more information

Thanks,

Syed

Code: [Select]
digitalWrite(CS, LOW);
  digitalWrite(AVG_CNT,0x09);
 
  //Before communication starts, the Chip Select pin needs to be set high.
 
  digitalWrite(CS, HIGH);
 
delay(45); 

}



void loop()

{
 
digitalWrite(CS, LOW);
SPI.transfer(0x56); // 0x56 for PROD_ID, 0x04 for XACCL_OUT, 0x06 for YACCL_OUT, 0x08 for ZACCL_OUT
SPI.transfer(0);
delay(45);
digitalWrite(CS, HIGH);
delay(45);
digitalWrite(CS, LOW);

byte resultHigh = SPI.transfer(0x00);
byte resultLow = SPI.transfer(0x00);

delay(45);
digitalWrite(CS, HIGH);
delay(45);

unsigned int result = (resultHigh << 8) | resultLow;


delay(45);
Serial.print(result);
Serial.print('\n');


delay(1000);

}

Go Up