Skip to main content
Associate II
May 4, 2025
Question

Nucleo-U385RG-Q with LPS22HH using I2C times out

  • May 4, 2025
  • 2 replies
  • 476 views

Hi, I am using STM32CubeMX to configure STM32CubeIDE project. I have Nucleo-U385RG-Q with MEMS X-Nucleo-IKS01A3. I am trying to read pressure sensor LPS22HH. According the X-Nucleo documentation the I2C default addresses for LPS22HH are: BA and B8. But the C code for the sensor defines BA and B8.

Using the STM32CubeIDE project generated by STM32CubeMX I am not able to read sensor ID. The following code gives me an error. 

In the code I first define:

	stmdev_ctx_t dev_ctx;
	dev_ctx.write_reg = platform_write;
	dev_ctx.read_reg = platform_read;
	dev_ctx.mdelay = platform_delay;
	dev_ctx.handle = &SENSOR_BUS;

Then use it:

	whoamI = 0;
	lps22hh_device_id_get(&dev_ctx, &whoamI);

In STM32CubeMX i configured PINs PB6 and PB7 for I2C1. The sensor files "lps22hh_reg.*" I got from GitHub.

Can someone please point me to the right direction. Thank you in advance.

2 replies

TDK
Super User
May 4, 2025

> The sensor files "lps22hh_reg.*" I got from GitHub.

I'm more likely to believe the issues lies somewhere in here, or your implementation of it.

See if HAL_I2C_IsDeviceReady returns HAL_OK for the slave address in question. If not, the connection is likely not there, or pullups are missing/insufficient, or the device isn't powered, etc.

"If you feel a post has answered your question, please click ""Accept as Solution""."
suiunbekAuthor
Associate II
May 5, 2025

@TDK thank you for your reply. I am using STMicroelectronics' code from:

https://github.com/STMicroelectronics/STMems_Standard_C_drivers/tree/master/lps22hh_STdC

I haven't modified any code. I use it as is. The function call for HAL_I2C_IsDeviceReady returns HAL_ERROR. I can't find in STM32CubeMX any place to configure master/slave modes. I think Nucleo board is by default master.

The code defines addresses as

/** I2C Device Address 8 bit format if SA0=0 -> B9 if SA0=1 -> BB **/
#define LPS22HH_I2C_ADD_H 0xBBU
#define LPS22HH_I2C_ADD_L 0xB9U

/** Device Identification (Who am I) **/
#define LPS22HH_ID 0xB3U

Therefore, for reading I am using LPS22HH_I2C_ADD_H. The X-Nucleo-IKS01A3 defines addresses differently:

LPS22HH BAh
LPS22HH B8h

So it is confusing.

For both pins PB6 and PB7 of the Nucleo board I am setting GPIO Pull-up/Pull-down to Pull-up. And the Maximum output speed to Very High. I also enabled I2C1 Event interrupts. For the rest of the settings I use default.

Is there anything else I can do to test the connection?

 


@suiunbek wrote:

Hi, I am using STM32CubeMX to configure STM32CubeIDE project. I have Nucleo-U385RG-Q with MEMS X-Nucleo-IKS01A3. I am trying to read pressure sensor LPS22HH. According the X-Nucleo documentation the I2C default addresses for LPS22HH are: BA and B8. But the C code for the sensor defines BA and B8.

Using the STM32CubeIDE project generated by STM32CubeMX I am not able to read sensor ID. The following code gives me an error. 

In the code I first define:

	stmdev_ctx_t dev_ctx;
	dev_ctx.write_reg = platform_write;
	dev_ctx.read_reg = platform_read;
	dev_ctx.mdelay = platform_delay;
	dev_ctx.handle = &SENSOR_BUS;

Then use it:

	whoamI = 0;
	lps22hh_device_id_get(&dev_ctx, &whoamI);

In STM32CubeMX i configured PINs PB6 and PB7 for I2C1. The sensor files "lps22hh_reg.*" I got from GitHub.

Can someone please point me to the right direction. Thank you in advance.