Help: MS5607 Altimeter using SPI, C Code, and Propeller Activity Board
c07Brian.Kester
Posts: 36
I am trying to get the MS5607 Altimeter to work using the SPI Mode in C code on the Propeller Activity Board. A picture of the setup and the current (messy) iteration of the code are attached. I also attached the datasheet (it is not currently available on the Parallax website), and a screenshot of the output. I am pulling in numbers from the PROM and ADC, but they do not appear to be reasonable. The math for the conversion is probably also off, because I was not sure of the best way to implement the exponentials, so I used the pow() function from math.h after testing its basic functionality and ability to give reasonable integer results for basic calculations. At the very least, the SENS variable calculation is wrong, but I am not sure where the problem is happening and it is hard to believe the D1 and D2 numbers being read from the sensor. I would appreciate any help in identifying what I may be doing wrong. I am including a stripped-down version of my code in text form below. I am using Simple IDE and the associated libraries for all my coding. I started with the SPI tutorial for the Accelerometer module and used that as the basic template for this project. The code below does not include any loops or writing to the SD card yet because I wanted to get data that made sense first before adding on those layers... the loops and SD card writing are commented out in the attached code.
#include "simpletools.h" // Include simpletools lib const int SDI=3; // Chip SDI/SDA pin const int SDO=1; // Chip SDO pin const int SCL=5; // Chip CLK pin const int CS=0; // Chip CS pin const int PS=8; // Chip PS pin const int pt=500; // Pause time between data points const int RESET = 0x1E; // Reset command const int ADCread = 0x00; // ADC Read command const int PROMreadC1 = 0xA2; // Prompt read PROM C1 const int PROMreadC2 = 0xA4; // Prompt read PROM C2 const int PROMreadC3 = 0xA6; // Prompt read PROM C3 const int PROMreadC4 = 0xA8; // Prompt read PROM C4 const int PROMreadC5 = 0xAA; // Prompt read PROM C5 const int PROMreadC6 = 0xAC; // Prompt read PROM C6 const int ConvertD1 = 0x48; // Convert D1 for ADC read (OSR=4096) const int ConvertD2 = 0x58; // Convert D2 for ADC read (OSR=4096) unsigned int Cread(int READ); //Function prototype /* Initialize calculation values */ unsigned long int D1, D2; signed long int dT, TEMP, P; signed long long int OFF, SENS; unsigned int c1, c2, c3, c4, c5, c6; int main() // Main function { low(PS); // Select SPI Protocol high(CS); // CS high (inactive) low(CS); shift_out(SDI, SCL, MSBFIRST, 8, RESET); // Reset to ensure coeff loaded into PROM high(CS); pause(500); c1 = Cread(PROMreadC1); //Reads c1 value c2 = Cread(PROMreadC2); //Reads c2 value c3 = Cread(PROMreadC3); //Reads c3 value c4 = Cread(PROMreadC4); //Reads c4 value c5 = Cread(PROMreadC5); //Reads c5 value c6 = Cread(PROMreadC6); //Reads c6 value print("%cc1 = %d, c2 = %d, c3 = %d \n", HOME, c1, c2, c3); print("c4 = %d, c5 = %d, c6 = %d\n", c4, c5, c6); /* Read digital pressure and temperature value */ low(CS); // CS low selects chip shift_out(SDI, SCL, MSBFIRST, 8, ConvertD1); // Prompt D1 ADC conversion high(CS); pause(100); low(CS); shift_out(SDI, SCL, MSBFIRST, 8, ADCread); // Prompt D1 ADC read D1 = shift_in(SDO, SCL, MSBPOST, 24); // Read D1 value high(CS); low(CS); shift_out(SDI, SCL, MSBFIRST, 8, ConvertD2); // Prompt D2 ADC conversion high(CS); pause(100); low(CS); shift_out(SDI, SCL, MSBFIRST, 8, ADCread); // Prompt D1 ADC read D2 = shift_in(SDO, SCL, MSBPOST, 24); // Read D2 value high(CS); // De-select chip print("D1=%d, D2=%d\n", D1, D2); /* Calculate temperature */ dT=D2-(c5*pow(2,8)); // Difference between actual and ref temp TEMP=2000+((dT*c6)/pow(2,23)); // Actual Temperature print("dT = %d, TEMP = %d\n", dT, TEMP); /* Calculate temperature-compensated pressure */ OFF=(c2*pow(2,17))+((c4*dT)/pow(2,6)); SENS=c1*pow(2,16)+(c3*dT)/pow(2,7); P=(D1*SENS/pow(2,21)-OFF)/pow(2,15); print("OFF=%d, SENS=%d, P=%d\n", OFF, SENS, P); } unsigned int Cread(int READ) { unsigned int C; low(CS); shift_out(SDI, SCL, MSBFIRST, 8, READ); // Prompt Coeff PROM read C = shift_in(SDO, SCL, MSBPOST, 16); // Read coeff value high(CS); return C; }Personal notes: I am pretty new to this community, only having been working on this for the last couple weeks. The purpose of this project is to make sensors available for students for launching high altitude balloons. I don't necessarily need the altitude calculations to work because I could have the students do that as part of the post-processing, but ideally, I would like to do the altitude calculations on-board so the students could compare them to post-processing. So far, I have successfully implemented the 3-axis gyroscope (L3G4200D) and 3-axis accelerometer (MMA7455) sensor modules.
Comments
Board not yet assembled