Help using SPI in Altimeter MS5607 and Arduino
danidub
Posts: 13
Hello again!
I'm still trying to communicate the Altimeter and the Arduino with SPI, and I made this code, that when a "0" is recieved in the serial, the arduino sends the conversion and read command to the altimeter and stores the 24 bit data of the altitude. Till now, I get the data in three bytes, but for some reason I only get 3 bytes of 11111111, 11111111, 11111111.
I post the code:
I'm still trying to communicate the Altimeter and the Arduino with SPI, and I made this code, that when a "0" is recieved in the serial, the arduino sends the conversion and read command to the altimeter and stores the 24 bit data of the altitude. Till now, I get the data in three bytes, but for some reason I only get 3 bytes of 11111111, 11111111, 11111111.
I post the code:
[/COLOR][LEFT][COLOR=#333333][FONT=Parallax]/*[/FONT][/COLOR][/LEFT] Circuit: SCK: pin 13 MISO: pin 12 MOSI: pin 11 SS: pin 9 */const int ss = 9;#include <SPI.h>//3 bytes to get the 24 bit adc readbyte byte1; byte byte2; byte byte3;void setup() { Serial.begin(9600); SPI.begin(); SPI.setBitOrder(MSBFIRST); pinMode(ss, OUTPUT);}void loop() { if (Serial.available() > 0) { byte incomingByte = Serial.read(); switch (incomingByte){ case '0': read_alt(); break; } //endswitch }//enif}//endloopvoid read_alt(){ //READ Altimeter digitalWrite(ss, LOW); 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 //print the 3 bytes in serial Serial.println(byte1, BIN); Serial.println(byte2, BIN); Serial.println(byte3, BIN); Serial.println(); //release chip, signal end transfer digitalWrite(ss, HIGH); [LEFT][COLOR=#333333][FONT=Parallax]}[/FONT][/COLOR][/LEFT][COLOR=#333333]
Comments
Here is the code again:
I will try the altimeter with the I2C mode to check it's working, then I'll post in the Arduino forums regarding communication between the two devices in SPI mode.
Thank you,
Daniel P.
I have made some little fixes in the code:
Hello Franklin I have it connected like this:
Altimeter
Arduino pin
CS
10
SDO
12
SDA
11
SCL
13
PS
GND
VIN
+5
GND
GND
Reading the datasheet I think I have to set or send some parameters but dont know how.
In the other hand, I have an I2C code that works, but 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.
Here are the two files with I2C code:
Altimeter_Arduino_10.ino
IntersemaBaro.h