cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C6T6A I2C interface not working

RShiv.1
Senior
 
16 REPLIES 16
RShiv.1
Senior

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
Senior

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

0693W00000WIE9lQAH.png

RShiv.1
Senior

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

QSHAO.1
ST Employee

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
Senior

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
Senior

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
Senior

Any update on this will be help us ..Thanks

RShiv.1
Senior

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
Senior

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