o: ActiveSupport::Cache::Entry :@compressedF:@value"}C"wC
| main.c | ||
|---|---|---|
| 18 | 18 |
#define SPI_MODE_2 (SPI_H_TO_L) |
| 19 | 19 |
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H) |
| 20 | 20 |
|
| 21 |
float a0; |
|
| 21 |
float a0; // correctiaon coefficients
|
|
| 22 | 22 |
float b1; |
| 23 | 23 |
float b2; |
| 24 | 24 |
float c12; |
| ... | ... | |
| 38 | 38 |
spi_write(0x8A); // get LSB for a0 |
| 39 | 39 |
a0_LSB = spi_read(0x00); |
| 40 | 40 |
|
| 41 |
spi_write(0x8C); // get MSB for a0
|
|
| 41 |
spi_write(0x8C); // get MSB for b1
|
|
| 42 | 42 |
b1_MSB = spi_read(0x00); |
| 43 |
spi_write(0x8E); // get LSB for a0
|
|
| 43 |
spi_write(0x8E); // get LSB for b1
|
|
| 44 | 44 |
b1_LSB = spi_read(0x00); |
| 45 | 45 |
|
| 46 |
spi_write(0x90); // get MSB for a0
|
|
| 46 |
spi_write(0x90); // get MSB for b2
|
|
| 47 | 47 |
b2_MSB = spi_read(0x00); |
| 48 |
spi_write(0x92); // get LSB for a0
|
|
| 48 |
spi_write(0x92); // get LSB for b2
|
|
| 49 | 49 |
b2_LSB = spi_read(0x00); |
| 50 | 50 |
|
| 51 |
spi_write(0x94); // get MSB for a0
|
|
| 51 |
spi_write(0x94); // get MSB for c12
|
|
| 52 | 52 |
c12_MSB = spi_read(0x00); |
| 53 |
spi_write(0x96); // get LSB for a0
|
|
| 53 |
spi_write(0x96); // get LSB for c12
|
|
| 54 | 54 |
c12_LSB = spi_read(0x00); |
| 55 | 55 |
|
| 56 | 56 |
spi_read(0x00); |
| 57 | 57 |
output_high(CSN_SPI); |
| 58 |
|
|
| 59 |
// translate to floating point number |
|
| 58 | 60 |
|
| 59 | 61 |
a0 = ((unsigned int16) a0_MSB << 5) + (a0_LSB >> 3) + (a0_LSB & 0x07)/8.0; |
| 60 | 62 |
b1 = ((((b1_MSB & 0x1F) * 0x100) + b1_LSB) / 8192.0) - 3; |
| 61 | 63 |
b2 = ((((unsigned int16) (b2_MSB - 0x80) << 8) + b2_LSB)/ 16384.0) - 2; |
| 62 | 64 |
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 |
|
|
| 66 | 65 |
} |
| 67 | 66 |
|
| 68 | 67 |
float MPL_get_pressure() |
| ... | ... | |
| 96 | 95 |
output_high(CSN_SPI); |
| 97 | 96 |
|
| 98 | 97 |
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
| 99 |
|
|
| 100 |
printf("%lu %lu \r\n", ADC_pressure, ADC_temperature);
|
|
| 101 | 98 |
|
| 102 |
Pcomp = (a0 + (b1 + c12 * ADC_temperature) * ADC_pressure + b2 * ADC_temperature ); |
|
| 99 |
Pcomp = (a0 + (b1 + c12 * ADC_temperature) * ADC_pressure + b2 * ADC_temperature ); // compute relative compensated pressure
|
|
| 103 | 100 |
|
| 104 |
printf("%f \r\n", Pcomp);
|
|
| 101 |
return (Pcomp * ((115.0 - 50.0)/1023.0) + 50.0); // return absolute pressure |
|
| 102 |
} |
|
| 105 | 103 |
|
| 106 |
return (Pcomp * ((115.0 - 50.0)/1023.0) + 50.0); |
|
| 104 |
float MPL_get_temperature() |
|
| 105 |
{
|
|
| 106 |
unsigned int8 LSB_data, MSB_data; |
|
| 107 |
unsigned int16 ADC_temperature; |
|
| 108 |
|
|
| 109 |
output_low(CSN_SPI); //Start temperature and pressure conversion |
|
| 110 |
spi_write(0x22); |
|
| 111 |
spi_write(0x00); |
|
| 112 |
output_high(CSN_SPI); |
|
| 113 |
|
|
| 114 |
delay_ms(10); |
|
| 115 |
|
|
| 116 |
output_low(CSN_SPI); |
|
| 117 |
spi_write(0x84); |
|
| 118 |
MSB_data = spi_read(0x00); |
|
| 119 |
spi_write(0x86); // get LSB for Temperature |
|
| 120 |
LSB_data = spi_read(0x00); |
|
| 121 |
spi_read(0x00); |
|
| 122 |
output_high(CSN_SPI); |
|
| 123 |
|
|
| 124 |
ADC_temperature = (((unsigned int16) MSB_data << 8) + LSB_data ) >> 6; // conversion of 8bit registers to 16bit variable |
|
| 125 |
|
|
| 126 |
return ( ((float) ADC_temperature - 498.0)/-5.35) + 25.0; // return temperature in deg C |
|
| 107 | 127 |
} |
| 108 | 128 |
|
| 109 | 129 |
void main() |
| ... | ... | |
| 113 | 133 |
output_high(CSN_SPI); |
| 114 | 134 |
delay_ms(100); |
| 115 | 135 |
|
| 116 |
MPL_init(); |
|
| 136 |
MPL_init(); // get correction coeffivcients from the sensor
|
|
| 117 | 137 |
|
| 118 | 138 |
while(true) |
| 119 | 139 |
{
|
| 120 |
// MPL_init(); |
|
| 121 |
printf("%f \r\n", MPL_get_pressure());
|
|
| 122 |
// printf("%ld %ld %ld %ld \r\n",a0, b1, b2, c12);
|
|
| 123 |
//MPL_get_pressure(); |
|
| 124 |
|
|
| 140 |
printf("%f %f \r\n", MPL_get_pressure(), MPL_get_temperature());
|
|
| 125 | 141 |
delay_ms(500); |
| 126 | 142 |
} |
| 127 | 143 |
} |