AnsweredAssumed Answered

I2C not work in stm32f103c8t6

Question asked by sohaeng.lee on Oct 5, 2017

stm32f103c8t6,htu-21d

 

I am under test for I2C.
Setting of CubeMX does not allow the pullup/down setting.

 

 

The I2C device used is htu-21d (Humidity and Humidity Sensor).

 

 

 

 

--source code--

.

.

i2cTxData = (uint8_t)0xe3;    // temp

while(HAL_I2C_Master_Transmit(&hi2c1,(uint16_t)HTDU21D_ADDRESS,(uint8_t *)&i2cTxData,1,1000)!=HAL_OK);    <—— Stop this line

HAL_Delay(50);

while(HAL_I2C_Master_Receive (&hi2c1,(uint16_t)HTDU21D_ADDRESS,(uint8_t *)i2cRxData,6,1000)!=HAL_OK);

double temp = -46.85 + 0.002681 * ((i2cRxData[0]<<8)|i2cRxData[1]);

 

i2cTxData = (uint8_t)0xe5;   // humi

while(HAL_I2C_Master_Transmit(&hi2c1,(uint16_t)HTDU21D_ADDRESS,(uint8_t *)&i2cTxData,1,1000)!=HAL_OK);

HAL_Delay(16);

while(HAL_I2C_Master_Receive (&hi2c1,(uint16_t)HTDU21D_ADDRESS,(uint8_t *)i2cRxData,3,1000)!=HAL_OK);

 

double humi = -6.0 + 0.001907 * (((i2cRxData[0]<<8)|i2cRxData[1])^0x02);

sprintf(str,"%10.5lf:%10.5lf\r\n",temp,humi);

HAL_UART_Transmit(&huart2,(uint8_t *)str,strlen(str),1000);

.

.

Outcomes