cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 WB55 Nucleo I2c3

TGUCL.1
Associate III

Hi

I`m trying to read temperature from a Sensirion STS3X sensor using I2C3 with PB13 and PB14 configured

My problem is , during tranmission I2C_WaitOnTXISFlagUntilTimeout returns HAL_ERROR and I can`t talk to sensor.

I have used Cube project to generate files

I2C Init

static void MX_I2C3_Init(void)
{
 
  /* USER CODE BEGIN I2C3_Init 0 */
 
  /* USER CODE END I2C3_Init 0 */
 
  /* USER CODE BEGIN I2C3_Init 1 */
 
  /* USER CODE END I2C3_Init 1 */
  hi2c3.Instance = I2C3;
  hi2c3.Init.Timing = 0x20502B38;
  hi2c3.Init.OwnAddress1 = 0;
  hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
  hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
  hi2c3.Init.OwnAddress2 = 0;
  hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
  hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
  hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
  if (HAL_I2C_Init(&hi2c3) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Analogue filter 
  */
  if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
  {
    Error_Handler();
  }
  /** Configure Digital filter 
  */
  if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN I2C3_Init 2 */
 
  /* USER CODE END I2C3_Init 2 */
 
}

main loop

  while (1)
  {
 
 
 
		int32_t temperature;
		float temperature_degree;
		sts3x_measure_blocking_read(&temperature);
		temperature_degree = temperature / 1000.0f;
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }

sensor readings

void sts3x_measure_blocking_read(int32_t *temperature) {
	sts3x_measure();
	HAL_Delay(50);
	sts3x_read(temperature);
	HAL_Delay(50);
 
}
 
 
void sts3x_measure()
{
	if(HAL_I2C_Master_Transmit(&hi2c3, STS3X_ADDRESS, sts3x_cmd_measure, 1, HAL_MAX_DELAY) != HAL_OK)
	{
		Error_Handler();
	}
}
 
void sts3x_read(int32_t *temperature) {
	uint16_t word;
	if(HAL_I2C_Master_Receive(&hi2c3, STS3X_ADDRESS, &word, 2, HAL_MAX_DELAY)!= HAL_OK)
	{
		Error_Handler();
	}
 
 
	*temperature = ((21875 * (int32_t) word) >> 13) - 45000;
 
}
/* USER CODE END 4 */

for some reason , I receive error while transmitting

  while (hi2c->XferCount > 0U)
    {
      /* Wait until TXIS flag is set */
      if (I2C_WaitOnTXISFlagUntilTimeout(hi2c, Timeout, tickstart) != HAL_OK)
      {
        return HAL_ERROR; //Everytime  I endup here
      }
      /* Write data to TXDR */

And on the line levels SCL and SDA does not change,. But if I set them as GPIO Outputs and set/reset them I can monitor the change.

Has anyone experienced this ? I`m not sure what Am I doing wrong

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
TGUCL.1
Associate III

Yes there are.

Datasheet says that sensor has the address of 0x4a.

ı just noticed

If I provide (0x4a<<1) ,transmit returns HAL_OK .

Given that 7bit addressing mode and lsb bit is r/w indication ,Should I provide the shifted addresses to HAL I2C transmit/receive interfaces ?

View solution in original post

4 REPLIES 4
TDK
Guru

Do you have pullup resistors on the SCL/SDA lines?

If you feel a post has answered your question, please click "Accept as Solution".
Uwe Bonnes
Principal III

Activation the GPIO internal Pullup can be a last resort, with loading is small.

TGUCL.1
Associate III

Yes there are.

Datasheet says that sensor has the address of 0x4a.

ı just noticed

If I provide (0x4a<<1) ,transmit returns HAL_OK .

Given that 7bit addressing mode and lsb bit is r/w indication ,Should I provide the shifted addresses to HAL I2C transmit/receive interfaces ?

Yes.
If you feel a post has answered your question, please click "Accept as Solution".