cancel
Showing results for 
Search instead for 
Did you mean: 

I2C not work in stm32f103c8t6

SoHaeng.Lee
Associate II
Posted on October 05, 2017 at 07:58

0690X00000608RKQAY.png

I am under test for I2C.

Setting of CubeMX does not allow the pullup/down setting.

0690X00000608RLQAY.png

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

0690X00000608UcQAI.png

--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);

.

.

#i2c #stm32f103c8t6 #htu-21d
0 REPLIES 0