51 uint16_t pressure = 0x0000;
57 pressure = (uint16_t) (press_msb << 8);
58 pressure &= (0xFF00 | ((uint16_t) (press_lsb)));
59 pressure = 0x03FF & (pressure >> 6);
66 uint16_t temperature = 0x0000;
73 temperature = (uint16_t) (temp_msb << 8);
74 temperature &= (0xFF00 | ((uint16_t) (temp_lsb)));
75 temperature = 0x03FF & (temperature >> 6);
79 void mpl115a_read_coefficients(
void) {
84 for (i = 0; i < 6; i++) {
85 coeff_tmp_msb =
mpl115a_cmd(coefficients[i].addr[0]);
86 coeff_tmp_lsb =
mpl115a_cmd(coefficients[i].addr[1]);
87 uart_TXchar(coeff_tmp_msb);
88 uart_TXchar(coeff_tmp_lsb);
91 coefficients[i].value = (int16_t) (coeff_tmp_msb << 8);
92 coefficients[i].value &= (0xFF00 | ((int16_t) (coeff_tmp_lsb)));
97 int16_t mpl115a_get_Pcomp(
void) {
98 int32_t tmp1_val, tmp2_val, tmp3_val;
101 uint16_t temperature = 0x0000;
102 uint16_t pressure = 0x0000;
111 temperature = (uint16_t) (msb << 8);
112 temperature &= (0xFF00 | ((uint16_t) (lsb)));
113 temperature = 0x03FF & (temperature >> 6);
117 pressure = (uint16_t) (msb << 8);
118 pressure &= (0xFF00 | ((uint16_t) (lsb)));
119 pressure = 0x03FF & (pressure >> 6);
123 tmp1_val = (int32_t) coefficients[MPL115A_C11].value;
124 tmp2_val = (int32_t) pressure;
126 tmp3_val = tmp1_val * tmp2_val;
128 tmp1_val = (int32_t) (coefficients[MPL115A_B1].value << 14);
129 tmp2_val = (int32_t) tmp3_val;
130 tmp3_val = tmp1_val + tmp2_val;
132 tmp_help = (int32_t) (tmp3_val >> 14);
134 tmp1_val = (int32_t) coefficients[MPL115A_C12].value;
135 tmp2_val = (int32_t) temperature;
137 tmp3_val = tmp1_val * tmp2_val;
139 tmp1_val = (int32_t) (tmp_help << 11);
140 tmp2_val = (int32_t) tmp3_val;
141 tmp3_val = tmp1_val + tmp2_val;
143 tmp_help = (int32_t) (tmp3_val >> 11);
145 tmp1_val = (int32_t) coefficients[MPL115A_C22].value;
146 tmp2_val = (int32_t) temperature;
148 tmp3_val = tmp1_val * tmp2_val;
150 tmp1_val = (int32_t) (coefficients[MPL115A_B2].value << 15);
151 tmp2_val = (int32_t) (tmp3_val >> 1);
152 tmp3_val = tmp1_val + tmp2_val;
154 tmp1_val = (int32_t) tmp_help;
156 tmp_help = (int32_t) (tmp3_val >> 16);
157 tmp2_val = (int32_t) pressure;
159 tmp3_val = tmp1_val * tmp2_val;
161 tmp1_val = (int32_t) (coefficients[MPL115A_A0].value << 10);
162 tmp2_val = (int32_t) tmp3_val;
163 tmp3_val = tmp1_val + tmp2_val;
165 tmp1_val = (int32_t) tmp_help;
167 tmp_help = (int32_t) (tmp3_val >> 10);
168 tmp2_val = (int32_t) temperature;
170 tmp3_val = tmp1_val * tmp2_val;
172 tmp1_val = (int32_t) (tmp_help << 10);
173 tmp2_val = (int32_t) tmp3_val;
174 tmp3_val = tmp1_val + tmp2_val;
176 return (int16_t) (tmp3_val >> 13);