Line 54... |
Line 54... |
54 |
c12_LSB = spi_read(0x00); |
54 |
c12_LSB = spi_read(0x00); |
55 |
|
55 |
|
56 |
spi_read(0x00); |
56 |
spi_read(0x00); |
57 |
output_high(CSN_SPI); |
57 |
output_high(CSN_SPI); |
58 |
|
58 |
|
59 |
a0 = (a0_MSB << 5) + (a0_LSB >> 3) + (a0_LSB & 0x07)/8.0; |
59 |
a0 = ((unsigned int16) a0_MSB << 5) + (a0_LSB >> 3) + (a0_LSB & 0x07)/8.0; |
60 |
b1 = ((((b1_MSB & 0x1F) * 0x100) + b1_LSB) / 8192.0) - 3; |
60 |
b1 = ((((b1_MSB & 0x1F) * 0x100) + b1_LSB) / 8192.0) - 3; |
61 |
b2 = ((((b2_MSB - 0x80) << 8) + b2_LSB)/ 16384.0) - 2; |
61 |
b2 = ((((unsigned int16) (b2_MSB - 0x80) << 8) + b2_LSB)/ 16384.0) - 2; |
62 |
c12 =(((c12_MSB * 0x100) + c12_LSB)/16777216.0); |
62 |
c12 =(((c12_MSB * 0x100) + c12_LSB)/16777216.0); |
- |
|
63 |
|
- |
|
64 |
printf("%4.3f %1.5f %1.5f %1.9f \r\n", a0, b1, b2, c12); |
- |
|
65 |
|
63 |
} |
66 |
} |
64 |
|
67 |
|
65 |
float MPL_get_pressure() |
68 |
float MPL_get_pressure() |
66 |
{ |
69 |
{ |
67 |
unsigned int8 LSB_data, MSB_data; |
70 |
unsigned int8 LSB_data, MSB_data; |
Line 80... |
Line 83... |
80 |
MSB_data = spi_read(0x00); |
83 |
MSB_data = spi_read(0x00); |
81 |
spi_write(0x82); // get LSB for Pressure |
84 |
spi_write(0x82); // get LSB for Pressure |
82 |
LSB_data = spi_read(0x00); |
85 |
LSB_data = spi_read(0x00); |
83 |
output_high(CSN_SPI); |
86 |
output_high(CSN_SPI); |
84 |
|
87 |
|
85 |
printf("%lX %lX\r\n", MSB_data, LSB_data); |
- |
|
86 |
ADC_pressure = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
88 |
ADC_pressure = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
87 |
|
89 |
|
88 |
output_low(CSN_SPI); |
90 |
output_low(CSN_SPI); |
89 |
spi_write(0x84); |
91 |
spi_write(0x84); |
90 |
MSB_data = spi_read(0x00); |
92 |
MSB_data = spi_read(0x00); |
91 |
spi_write(0x86); // get LSB for Temperature |
93 |
spi_write(0x86); // get LSB for Temperature |
92 |
LSB_data = spi_read(0x00); |
94 |
LSB_data = spi_read(0x00); |
93 |
spi_read(0x00); |
95 |
spi_read(0x00); |
94 |
output_high(CSN_SPI); |
96 |
output_high(CSN_SPI); |
95 |
|
97 |
|
96 |
printf("%lX %lX\r\n", MSB_data, LSB_data); |
- |
|
97 |
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
98 |
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
98 |
|
99 |
|
99 |
printf("%lu %lu \r\n", ADC_pressure, ADC_temperature); |
100 |
printf("%lu %lu \r\n", ADC_pressure, ADC_temperature); |
100 |
|
101 |
|
101 |
Pcomp = (a0 + (b1 + c12 * ADC_temperature) * ADC_pressure + b2 * ADC_temperature ); |
102 |
Pcomp = (a0 + (b1 + c12 * ADC_temperature) * ADC_pressure + b2 * ADC_temperature ); |
102 |
|
103 |
|
- |
|
104 |
printf("%f \r\n", Pcomp); |
- |
|
105 |
|
103 |
return (Pcomp * ((115.0 - 50.0)/1023.0) + 50.0); |
106 |
return (Pcomp * ((115.0 - 50.0)/1023.0) + 50.0); |
104 |
} |
107 |
} |
105 |
|
108 |
|
106 |
void main() |
109 |
void main() |
107 |
{ |
110 |
{ |