IKS01A3驱动移植,STM32G474RE的LPS22HH气压温度检测
<div class='showpostmsg'><p>测量LPS22HH气压和温湿度通过串口打印</p><p><br />
</p>
<p> </p>
<pre>
<code class="language-cpp">/* 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;
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 *)&reg, 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 :%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 :%6.2f\r\n", temperature_degC );
tx_com( tx_buffer, strlen( (char const*)tx_buffer ) );
}
}
}</code></pre>
<p>工程文件:<br />
<br />
<b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">littleshrimp</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b></p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>这不算驱动移植吧</p>
dcexpert 发表于 2019-8-29 21:45
这不算驱动移植吧
应该叫什么? <p>感觉是在STM32G474RE上使用传感器,而没有涉及到传感器的驱动移植<span style="display:none"> </span><span style="display:none"> </span></p>
dcexpert 发表于 2019-8-29 22:57
感觉是在STM32G474RE上使用传感器,而没有涉及到传感器的驱动移植
<p>这个工程里的LPS22HH的驱动是是官方提供的</p>
<p>驱动提供一个读取数据通过串口发送的DEMO</p>
<p>是应用在NUCLEO_STM32F411RE开发板上的</p>
<p>没有提供项目文件</p>
<p>改这个东西是为了方便网友(拿用主义)在G474平台上使用这款传感器</p>
<p>因为ST将驱动都已经封装好</p>
<p>应用在G474或者其它单片机只需要配置好对应单片机的I2C和UART</p>
<p>再对代码做简单修改就可以在对应的单片机上使用</p>
<p>方便了很多</p>
您好,请问有没有评估过这款传感器测量下限在哪里,低于260hpa时是否还有输出 A212 发表于 2024-5-16 11:29
您好,请问有没有评估过这款传感器测量下限在哪里,低于260hpa时是否还有输出
<p>没测试过</p><br/>
页:
[1]