4914|6

9805

帖子

24

TA的资源

版主

楼主
 

IKS01A3驱动移植,STM32G474RE的LPS22HH气压温度检测 [复制链接]

 

测量LPS22HH气压和温湿度通过串口打印


 

/* Includes ------------------------------------------------------------------*/
#include "lps22hh_reg.h"
#include "main.h"
#include <string.h>
#include <stdio.h>
//#define MKI109V2
#define NUCLEO_G474RE

#define TX_BUF_DIM          1000

/* Private variables ---------------------------------------------------------*/
static axis1bit32_t data_raw_pressure;
static axis1bit16_t data_raw_temperature;
static float pressure_hPa;
static float temperature_degC;
static uint8_t whoamI, rst;
static uint8_t tx_buffer[TX_BUF_DIM];
extern I2C_HandleTypeDef hi2c1;

extern UART_HandleTypeDef hlpuart1;
/* Extern variables ----------------------------------------------------------*/

/* Private functions ---------------------------------------------------------*/

/*
 *   Replace the functions "platform_write" and "platform_read" with your
 *   platform specific read and write function.
 *   This example use an STM32 evaluation board and CubeMX tool.
 *   In this case the "*handle" variable is usefull in order to select the
 *   correct interface but the usage uf "*handle" is not mandatory.
 */

static int32_t platform_write(void *handle, uint8_t Reg, uint8_t *Bufp,
                              uint16_t len)
{
  if (handle == &hi2c1)
  {
    HAL_I2C_Mem_Write(handle, LPS22HH_I2C_ADD_H, Reg,
                      I2C_MEMADD_SIZE_8BIT, Bufp, len, 1000);
  }
#ifdef MKI109V2  
  else if (handle == &hspi2)
  {
    HAL_GPIO_WritePin(CS_SPI2_GPIO_Port, CS_SPI2_Pin, GPIO_PIN_RESET);
    HAL_SPI_Transmit(handle, &Reg, 1, 1000);
    HAL_SPI_Transmit(handle, Bufp, len, 1000);
    HAL_GPIO_WritePin(CS_SPI2_GPIO_Port, CS_SPI2_Pin, GPIO_PIN_SET);
  }
  else if (handle == &hspi1)
  {
    HAL_GPIO_WritePin(CS_SPI1_GPIO_Port, CS_SPI1_Pin, GPIO_PIN_RESET);
    HAL_SPI_Transmit(handle, &Reg, 1, 1000);
    HAL_SPI_Transmit(handle, Bufp, len, 1000);
    HAL_GPIO_WritePin(CS_SPI1_GPIO_Port, CS_SPI1_Pin, GPIO_PIN_SET);
  }
#endif
  return 0;
}

static int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp,
                             uint16_t len)
{
  if (handle == &hi2c1)
  {
      HAL_I2C_Mem_Read(handle, LPS22HH_I2C_ADD_H, Reg,
                       I2C_MEMADD_SIZE_8BIT, Bufp, len, 1000);
  }
#ifdef MKI109V2   
  else if (handle == &hspi2)
  {
    Reg |= 0x80;
    HAL_GPIO_WritePin(CS_DEV_GPIO_Port, CS_DEV_Pin, GPIO_PIN_RESET);
    HAL_SPI_Transmit(handle, &Reg, 1, 1000);
    HAL_SPI_Receive(handle, Bufp, len, 1000);
    HAL_GPIO_WritePin(CS_DEV_GPIO_Port, CS_DEV_Pin, GPIO_PIN_SET);
  }
  else
  {
    Reg |= 0x80;
    HAL_GPIO_WritePin(CS_RF_GPIO_Port, CS_RF_Pin, GPIO_PIN_RESET);
    HAL_SPI_Transmit(handle, &Reg, 1, 1000);
    HAL_SPI_Receive(handle, Bufp, len, 1000);
    HAL_GPIO_WritePin(CS_RF_GPIO_Port, CS_RF_Pin, GPIO_PIN_SET);
  }
#endif  
  return 0;
}

/*
 *  Function to print messages
 */
void tx_com( uint8_t *tx_buffer, uint16_t len )
{
  #ifdef NUCLEO_G474RE  
  HAL_UART_Transmit( &hlpuart1, tx_buffer, len, 1000 );
  #endif
  #ifdef MKI109V2  
  CDC_Transmit_FS( tx_buffer, len );
  #endif
}

/* Main Example --------------------------------------------------------------*/

void example_main(void)
{
  /*
   *  Initialize mems driver interface
   */
  lps22hh_ctx_t dev_ctx;
  dev_ctx.write_reg = platform_write;
  dev_ctx.read_reg = platform_read;
  dev_ctx.handle = &hi2c1;  
  /*
   *  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);
  
  /*
   * Read samples in polling mode (no int)
   */
  while(1)
  {
    /*
     * Read output only if new value is available
     */
    lps22hh_reg_t reg;
    lps22hh_read_reg(&dev_ctx, LPS22HH_STATUS, (uint8_t *)®, 1);

    if (reg.status.p_da)
    {
      memset(data_raw_pressure.u8bit, 0x00, sizeof(int32_t));
      lps22hh_pressure_raw_get(&dev_ctx, data_raw_pressure.u8bit);
      pressure_hPa = lps22hh_from_lsb_to_hpa( data_raw_pressure.i32bit);
      
      sprintf((char*)tx_buffer, "pressure [hPa]:%6.2f\r\n", pressure_hPa);
      tx_com( tx_buffer, strlen( (char const*)tx_buffer ) );
    }

    if (reg.status.t_da)
    {
      memset(data_raw_temperature.u8bit, 0x00, sizeof(int16_t));
      lps22hh_temperature_raw_get(&dev_ctx, data_raw_temperature.u8bit);
      temperature_degC = lps22hh_from_lsb_to_celsius( data_raw_temperature.i16bit );
      
      sprintf((char*)tx_buffer, "temperature [degC]:%6.2f\r\n", temperature_degC );
      tx_com( tx_buffer, strlen( (char const*)tx_buffer ) );
    }
  }
}

工程文件:
stm32g474 lps22hh.rar (2.57 MB, 下载次数: 64)


此内容由EEWORLD论坛网友littleshrimp原创,如需转载或用于商业用途需征得作者同意并注明出处

最新回复

您好,请问有没有评估过这款传感器测量下限在哪里,低于260hpa时是否还有输出  详情 回复 发表于 2024-5-16 11:29
点赞 关注(1)
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

回复
举报

1万

帖子

24

TA的资源

版主

沙发
 

这不算驱动移植吧

点评

应该叫什么?  详情 回复 发表于 2019-8-29 22:01
 
 
 

回复

9805

帖子

24

TA的资源

版主

板凳
 
dcexpert 发表于 2019-8-29 21:45
这不算驱动移植吧

应该叫什么?
 
 
 

回复

1万

帖子

24

TA的资源

版主

4
 

感觉是在STM32G474RE上使用传感器,而没有涉及到传感器的驱动移植  

点评

这个工程里的LPS22HH的驱动是是官方提供的 驱动提供一个读取数据通过串口发送的DEMO 是应用在NUCLEO_STM32F411RE开发板上的 没有提供项目文件 改这个东西是为了方便网友(拿用主义)在G474平台上使用这  详情 回复 发表于 2019-8-30 21:56
 
 
 

回复

9805

帖子

24

TA的资源

版主

5
 
dcexpert 发表于 2019-8-29 22:57 感觉是在STM32G474RE上使用传感器,而没有涉及到传感器的驱动移植  

这个工程里的LPS22HH的驱动是是官方提供的

驱动提供一个读取数据通过串口发送的DEMO

是应用在NUCLEO_STM32F411RE开发板上的

没有提供项目文件

改这个东西是为了方便网友(拿用主义)在G474平台上使用这款传感器

因为ST将驱动都已经封装好

应用在G474或者其它单片机只需要配置好对应单片机的I2C和UART

再对代码做简单修改就可以在对应的单片机上使用

方便了很多

个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

回复

1

帖子

0

TA的资源

一粒金砂(初级)

6
 
您好,请问有没有评估过这款传感器测量下限在哪里,低于260hpa时是否还有输出

点评

没测试过  详情 回复 发表于 2024-5-16 13:07
 
 
 

回复

9805

帖子

24

TA的资源

版主

7
 
A212 发表于 2024-5-16 11:29 您好,请问有没有评估过这款传感器测量下限在哪里,低于260hpa时是否还有输出

没测试过


 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/9 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表