Razor 9DOF IMU + scp1000 how to ?

Hello!
I'm starting my own UAV project,and I have a problem with reading scp 1000,what I would like to do using Razor 9DOF IMU(ATmega328P).They are both 3.3V.
SCP1000 has   The SPI on Razor has       Pins on Razor according to datasheet
DRDY                ----                                 --------
CSB                  reset                              I think this should be slaveselect Pin14
MISO                 MISO                              Pin16
MOSI                 MOSI                              PIn15
SCK                  SCK                                Pin17
3.3V                  3.3V                                3.3V
GND                  GND                               GND
The code Iam using

// define spi bus pins
#define SLAVESELECT 14
#define SPICLOCK 17
#define DATAOUT 15    //MOSI
#define DATAIN 16     //MISO
#define UBLB(a,b)  ( ( (a) << 8) | (b) )
#define UBLB19(a,b) ( ( (a) << 16 ) | (b) )

//Addresses
#define REVID 0x00    //ASIC Revision Number
#define OPSTATUS 0x04   //Operation Status
#define STATUS 0x07     //ASIC Status
#define START 0x0A      //Constant Readings
#define PRESSURE 0x1F   //Pressure 3 MSB
#define PRESSURE_LSB 0x20 //Pressure 16 LSB
#define TEMP 0x21       //16 bit temp

char rev_in_byte;       
int temp_in;
unsigned long pressure_lsb;
unsigned long pressure_msb;
unsigned long temp_pressure;
unsigned long pressure;

void setup()
{
  byte clr;
  pinMode(DATAOUT, OUTPUT);               
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device 
  digitalWrite(10, HIGH); //physical SS pin high before setting SPCR
 
  SPCR = B01010011; //MPIE=0, SPE=1 (on), DORD=0 (MSB first), MSTR=1 (master), CPOL=0 (clock idle when low), CPHA=0 (samples MOSI on rising edge), SPR1=0 & SPR0=0 (500kHz)
  clr=SPSR;
  clr=SPDR;
  delay(10);
  Serial.begin(9600);
  delay(500);

  Serial.println("Initialize High Speed Constant Reading Mode");
  write_register(0x03,0x09);
}

void loop()
{
 
  rev_in_byte = read_register(REVID);
 
  pressure_msb = read_register(PRESSURE);
  pressure_msb &= B00000111;
  pressure_lsb = read_register16(PRESSURE_LSB);
  pressure = UBLB19(pressure_msb, pressure_lsb);
  pressure /= 4;
 
  Serial.print("PRESSURE [");
  Serial.print(pressure, DEC);
  Serial.println("]");
 
  temp_in = read_register16(TEMP);
  temp_in = temp_in / 20;
  temp_in = ((1.8) *temp_in) + 32;
  Serial.print("TEMP F [");
  Serial.print(temp_in , DEC);
  Serial.println("]");

  delay(1500);
 
}

char spi_transfer(volatile char data)
{
  SPDR = data;              // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
  };
  return SPDR;              // return the received byte
}


char read_register(char register_name)
{
    char in_byte;
    register_name <<= 2;
    register_name &= B11111100; //Read command
 
    digitalWrite(SLAVESELECT,LOW); //Select SPI Device
    digitalWrite(10, LOW); //physical SS pin high before setting SPCR
    spi_transfer(register_name); //Write byte to device
    in_byte = spi_transfer(0x00); //Send nothing, but we should get back the register value
    digitalWrite(SLAVESELECT,HIGH);
    digitalWrite(10, HIGH); //physical SS pin high before setting SPCR
    delay(10);
    return(in_byte);
 
}

unsigned long read_register16(char register_name)
{
    byte in_byte1;
    byte in_byte2;
    float in_word;
   
    register_name <<= 2;
    register_name &= B11111100; //Read command

    digitalWrite(SLAVESELECT,LOW); //Select SPI Device
    digitalWrite(10, LOW); //physical SS pin high before setting SPCR
    spi_transfer(register_name); //Write byte to device
    in_byte1 = spi_transfer(0x00);   
    in_byte2 = spi_transfer(0x00);
    digitalWrite(SLAVESELECT,HIGH);
    digitalWrite(10, HIGH); //physical SS pin high before setting SPCR
    in_word = UBLB(in_byte1,in_byte2);
    return(in_word);
}

void write_register(char register_name, char register_value)
{
    register_name <<= 2;
    register_name |= B00000010; //Write command

    digitalWrite(SLAVESELECT,LOW); //Select SPI device
    digitalWrite(10,LOW); //physical SS pin high before setting SPCR
    spi_transfer(register_name); //Send register location
    spi_transfer(register_value); //Send value to record into register
    digitalWrite(SLAVESELECT,HIGH);
    digitalWrite(10, HIGH); //physical SS pin high before setting SPCR
}



WIth pin14 as SS there is no output data, with pin10 as SS it outputs Temp=0 Press=(random number)

Any ideas how to make things work?


Thanks in advance)
Igor.

You need to be a member of diydrones to add comments!

Join diydrones

Replies are closed for this discussion.

Replies

  • there is already an example in the latest arduino ide in the example, SPI I've got it working with it, but, I've still not got time to analyse the output yet!
This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…