一:LPS22HH基本知识:
LPS22HH是一款超小型压阻式绝对压力传感器,它兼具数字输出气压计的功能。该设备包含一个传感元件以及一个集成电路接口,该接口可通过I2C、MIPI13CSM或SPI方式从传感元件与应用程序进行通信。
该传感元件用于检测绝对压力,由ST公司开发的专用工艺制造的悬吊膜构成
LPS22HH现已提供全模、带孔LGA封装(HLGA)版本。该产品保证可在从-40°C至+85°C的温度范围内稳定运行。该封装带有孔洞设计,以便外部压力能够触及传感元件。
二:软件代码如下所示:
void lps22hh_init( void )
{
/* Initialize mems driver interface */
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
// dev_ctx.mdelay = platform_delay;
dev_ctx.handle = &SENSOR_BUS;
/* Initialize platform specific hardware */
platform_init();
/* Wait sensor boot time */
platform_delay(BOOT_TIME);
/* Check device ID */
whoamI = 0;
lps22hh_device_id_get(&dev_ctx, &whoamI);
if ( whoamI != LPS22HH_ID )
while (1); /*manage here device not found */
/* Restore default configuration */
lps22hh_reset_set(&dev_ctx, PROPERTY_ENABLE);
do {
lps22hh_reset_get(&dev_ctx, &rst);
} while (rst);
/* Enable Block Data Update */
lps22hh_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
/* Set Output Data Rate */
lps22hh_data_rate_set(&dev_ctx, LPS22HH_10_Hz_LOW_NOISE);
}
2.2 读取函数,以及数据处理部分函数:
void lps22hh_read_data_polling(void)
{
/* Read samples in polling mode (no int) */
/* Read output only if new value is available */
lps22hh_read_reg(&dev_ctx, LPS22HH_STATUS, (uint8_t *)®.status, 10);
if (reg.status.p_da) {
memset(&data_raw_pressure, 0x00, sizeof(uint32_t));
lps22hh_pressure_raw_get(&dev_ctx, &data_raw_pressure);
pressure_hPa = lps22hh_from_lsb_to_hpa( data_raw_pressure);
sprintf((char *)tx_buffer, "ST-LPS22HH Pressure:%6.2f hpa\r\n", pressure_hPa);
tx_com( tx_buffer, strlen( (char const *)tx_buffer ) );
}
if (reg.status.t_da) {
memset(&data_raw_temperature, 0x00, sizeof(int16_t));
lps22hh_temperature_raw_get(&dev_ctx, &data_raw_temperature);
temperature_degC = lps22hh_from_lsb_to_celsius(
data_raw_temperature );
sprintf((char *)tx_buffer, "ST-LPS22HH Temperature :%6.2f ℃\r\n",
temperature_degC );
tx_com( tx_buffer, strlen( (char const *)tx_buffer ) );
}
}
三:串口数据读取部分:

|