![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
pachas
Dependencies: mbed QEI FastPWM
Diff: pressure_sensors.cpp
- Revision:
- 7:f4e248182d31
- Child:
- 8:208d965a3bd2
diff -r d38287621cca -r f4e248182d31 pressure_sensors.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pressure_sensors.cpp Mon Apr 20 21:58:36 2020 +0000 @@ -0,0 +1,43 @@ + +#include "mbed.h" +#include "stdint.h" +#include "project_defines.h" +#include "pressure_sensors.h" + + +/* Object definition */ +I2C pressure_sensor_01(PRESSURE_SENSOR_01_SDA_PIN, PRESSURE_SENSOR_01_SCL_PIN); +I2C pressure_sensor_02(PRESSURE_SENSOR_02_SDA_PIN, PRESSURE_SENSOR_02_SCL_PIN); + +/* Global variable definition */ +uint16_t pressure_01_bin, pressure_02_bin, diff_pressure_bin; +float pressure_01_psi, pressure_02_psi; +float diff_pressure_psi; + +char sensor_read_data_buffer[2]; + +/* Function definition */ + +void Pressure_Sensors_Initialize(void){ + pressure_sensor_01.frequency(PRESSURE_SENSOR_I2C_CLK_HZ ); + pressure_sensor_02.frequency(PRESSURE_SENSOR_I2C_CLK_HZ ); +} + + +void Pressure_Sensors_Read(void){ + + /* Read binary values */ + pressure_sensor_01.read(PRESSURE_SENSOR_01_SRA, sensor_read_data_buffer, 2); + pressure_01_bin = ((sensor_read_data_buffer[0] << 8) | sensor_read_data_buffer[1]) & 0x3FFF; + pressure_sensor_02.read(PRESSURE_SENSOR_02_SRA, sensor_read_data_buffer, 2); + pressure_02_bin = ((sensor_read_data_buffer[0] << 8) | sensor_read_data_buffer[1]) & 0x3FFF; + diff_pressure_bin = pressure_01_bin - pressure_02_bin; + + /* Calculate pressure values in PSI */ + pressure_01_psi = (5.0 * pressure_01_bin) / 16383; + pressure_02_psi = (5.0 * pressure_02_bin) / 16383; + diff_pressure_psi = (5.0 * diff_pressure_bin) / 16383; + +} + +