system
August 27, 2012, 8:37pm
1
Hello, I'm stucked in this issue 5 months ago, I really need help, this is the problem, I have to connect the Altimeter MS5607 with my Arduino UNO and using SPI, after trying so many times, I'm really MAD! haha
I think there is a way if I start from the I2C code (I'll paste the example for I2C that works, files taken from Microcontroller KickStarts | LEARN.PARALLAX.COM ):
I really need it to be using SPI Protocoll
I have it connected like this:
Altimeter Arduino pin
CS 10
SDO 12
SDA 11
SCL 13
PS GND
VIN +5
GND GND
Here are the two files with I2C code:
Altimeter_Arduino_10.ino
#include <Wire.h>#include "IntersemaBaro.h"
Intersema::BaroPressure_MS5607B baro(true);
void setup() {
Serial.begin(9600);
baro.init();
}
void loop() {
int alt = baro.getHeightCentiMeters();
Serial.print("Centimeters: ");
Serial.print((float)(alt));
Serial.print(", Feet: ");
Serial.println((float)(alt) / 30.48);
delay(400);
}
the other file is attached named: IntersemaBaro.h (this is the important file)
I need to connect it using SPI for my project, perhaps from the I2C code we can get the logic to make the communication for SPI.
Any ideas?
Thank you
IntersemaBaro.h (9 KB)
system
August 27, 2012, 9:19pm
3
Thanks, and I know, the problem is that I have tryed with some code without success:
I think I'm missing some parameters specified in the datasheet
/*
Circuit:
SCK: pin 13
MISO: pin 12
MOSI: pin 11
SS: pin 10
*/
const int ss = 10;
#include <SPI.h>
//3 bytes to get the 24 bit adc read
byte byte1;
byte byte2;
byte byte3;
void setup() {
Serial.begin(9600);
pinMode(ss, OUTPUT);
SPI.begin();
SPI.setBitOrder(MSBFIRST);
}
void loop() {
if (Serial.available() > 0) {
byte incomingByte = Serial.read();
switch (incomingByte){
case '0':
read_alt();
break;
} //endswitch
}//enif
}//endloop
void read_alt()
{
//READ Altimeter
digitalWrite(ss, LOW);
delay(100);
SPI.transfer(0x50); //ADC conversion command
delay(1);
// and store read data into three bytes
byte1 = SPI.transfer(0x00);//ADC conversion read command, first 8 bits
byte2 = SPI.transfer(0x00);//ADC conversion read command, second 8 bits
byte3 = SPI.transfer(0x00);//ADC conversion read command, third 8 bits
//release chip, signal end transfer
digitalWrite(ss, HIGH);
//print the 3 bytes in serial
Serial.println(byte1, BIN);
Serial.println(byte2, BIN);
Serial.println(byte3, BIN);
Serial.println();
}
That's why I think, starting from the I2C code.
system
August 28, 2012, 2:24pm
4
Any ideas? need help on this one please!
Daniel
danidub:
Any ideas? need help on this one please!
What results do you get when you run that sketch?
Still looking for the answer?
Hint:
Keep shifting the SPI buffer with a null value instead of the ADC Read command!