Go Down

Topic: n00b SPI problem (Read 13 times) previous topic - next topic

BLP

#10
Feb 11, 2009, 12:20 am Last Edit: Feb 11, 2009, 03:57 pm by bpeoples Reason: 1
So it's now working (hurray!)

UPDATED: Scratch that, it was actually a bad wiring problem on my part.

UPDATED 2: I'm getting weird readings, like:

MSB = 0x5
LSB = 0xFFFFE6F0

Which means my pressure is 0x5FFFFE6F0, which just seems a bit high for 1000ft above sea level?  

My temperature is reasonable (currently 22.8C), and adjusts accordingly, and my Pressure reading has jitter in it of about the right magnitude.  

The 0xFFFF in the first half of the LSB is suspicious to me, but I'm running verbatim the code posted above.


BLP

Just as an update, I have it working now!  

Here's the code I needed to do to make it work:

Code: [Select]


pressure_lsb = read_register16(PRESSURE_LSB);
pressure_lsb &= 0x0000FFFF;



Does this make any sense at all?

My read_register16 function looks thus:

Code: [Select]
float 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
   spi_transfer(register_name); //Write byte to device
   in_byte1 = spi_transfer(0x00);    
   in_byte2 = spi_transfer(0x00);
   digitalWrite(SLAVESELECT,HIGH);
   in_word = UBLB(in_byte1,in_byte2);
   return(in_word);
}


Could this be because of the cast from float to unsigned long?  I'm using Arduino 0013, did the types change between then and now?

Mersing

Hello,

I'm trying to get Temp and Pressure with a SCP1000 using the code above.

I've got
PRESSURE [123007]
TEMP F [21]
PRESSURE [123007]
TEMP F [21]

Strange values.

Below is the wiring to Arduino Pro Mini
SCK -> pin 13
MISO -> pin 12
MOSI -> pin 11
Now I got a doubt. From the program above :
SLAVESELECT 10

What is SLAVESELECT  from the SCP1000. I'm using Sparkfun breadk out, and got only CSB / DRDY.
How should I connect SLAVESELECT  ?

Thanks for your help.

Mersing.


MachineJoe

Is it possible to use 2 scp1000 sensors with a single arduino?  If so, how do you identify which is which?

kg4wsv

MOSI, MISO, and SCK are buses, but the chip select is unique for each device.  If the device is a correctly designed SPI device, just wire the second one up identical to the first, except use a different line for chip select.

-j


Go Up