Skip to main content
RShiv.1
Associate III
November 14, 2022
Question

STM32F103C6T6A I2C interface not working

  • November 14, 2022
  • 14 replies
  • 4277 views

..

This topic has been closed for replies.

14 replies

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

attached is the code ..I am using STMcubeID to run the I2C..I am trying to access sensor data using STM32 along with sensiron chip...but I I2C is not working...Let me know if you have any idea

uint16_t DevAddress = 0x61 << 1;

uint16_t MemAddress = 0x0036;

uint8_t env_var[6] = "";

char print_msg[100] = "";

uint16_t ret ;

 if (HAL_OK == HAL_I2C_IsDeviceReady(&hi2c1, DevAddress, 200, 2000)) {

  strcpy(print_msg, "SUCCESS HAL_I2C_Device_Read \n");

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg,strlen(MSG),1000);

  if (HAL_OK == HAL_I2C_Mem_Read(&hi2c1, DevAddress, MemAddress,I2C_MEMADD_SIZE_8BIT, (uint8_t*) &env_var[0],

  0x0006, HAL_MAX_DELAY)) {

  strcpy(print_msg, "SUCCESS HAL_I2C_Mem_Read\r\n");

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg,

  strlen(print_msg), 1000);

  sprintf(print_msg, "%X %X %X %X %X %X\r\n", env_var[0],

  env_var[1], env_var[2], env_var[3], env_var[4],

  env_var[5]);

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg, strlen(MSG),1000);

  } else {

  strcpy(print_msg, "ERROR in HAL_I2C_Mem_Read()\r\n");

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg, strlen(MSG),1000);

  }

  } else {

  strcpy(print_msg, "\n ERROR in HAL_I2C_IsDeviceReady()\r\n");

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg, strlen(MSG),1000);

  }

regards

Ravi

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

ANy configuration needs to be done using STM cube Mx which is missing kinfly

0693W00000WIE9lQAH.png

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

SCD30 interface description document attached...0x61 is the I2C address ...

QSHAO.1
ST Employee
November 14, 2022

before review of SW code, would you confirm that I2C bus is well pulled up by resistors? and more detail information may be helpful instead of "not working". for example NO ACK from sensor or something else.

RShiv.1
RShiv.1Author
Associate III
November 15, 2022

Hi QSHA0,

If you can suggest us any better solution will be good ..kindly let me know

regards

Ravi

RShiv.1
RShiv.1Author
Associate III
November 16, 2022

Hi,

I am seeing a timeout error inside HAL_I2C_Master_Transmit()...

I have pull up 4.7K resistor...where could be the issue...kindly let me know...any idea kinfly suggest

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

yes I2C is well pulled up using 4.7 K resistors and on probing also the line is showing 3.3v...when oscilloscope is connected no activity is seen on the bus...

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

we would like to confirm whether we have missed anything on the I2C configuration on STMcubeMx ..

Any IDE issue seen here...let us know...thanks

RShiv.1
RShiv.1Author
Associate III
November 14, 2022

Any update on this will be help us ..Thanks

RShiv.1
RShiv.1Author
Associate III
November 15, 2022

Hi ,

Just wanted to know if there needs to be change in S/W ...so that we can communicate with the sensor.

Let me know.

Thanks

RShiv.1
RShiv.1Author
Associate III
November 15, 2022

Hi,

I even tried with below code..even then why is I2C not passing..

 uint16_t DevAddress = 0x61 << 1;

 uint16_t MemAddress = 0x0036;

 uint8_t env_var[6] = "";

 char print_msg[200] = "";

 uint16_t ret ;

 ret = HAL_I2C_Master_Transmit(&hi2c1, DevAddress, env_var, 2, HAL_MAX_DELAY);

 if ( ret != HAL_OK )

   {

  strcpy(print_msg, "\n\r ERROR in HAL_I2C_Master_Tx() \r\n");

  HAL_UART_Transmit(&huart1, (uint8_t*) print_msg, strlen(MSG),1000);

 } else {

   strcpy(print_msg, "success in HAL_I2C_Master_Tx() \r\n");

   HAL_UART_Transmit(&huart1, (uint8_t*) print_msg, strlen(MSG),1000);

 }

Kindly let me know.

regards

Ravi

RShiv.1
RShiv.1Author
Associate III
November 15, 2022

Hi,

Tried the above code with ST25R3911B disco board which has STM32L476RET..

here we are not seeing any ret value..but the sensor is responding with some LED indication..

some configuration issue is stopping the ret values to indicate whether the I2C is working or not..

kindly suggest any changes in the code if any..then same configurations can be applied for STM32F103C6...kindly help us out if you have any suggestion.

thanks and regards

Ravi