I am trying to establish I2C communication between STM32F030K6T6 mikrokontroller and HH10D humidity sensor. The problem is, that after I call I2C_TransferHandling() the I2C_ISR_TXIS flag won't be set, and the program stucks in the loop waiting for it.

Here is my code, I made it based on the example code in the std periph library.

void initI2C()
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);

    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    I2C_InitTypeDef  I2C_InitStructure;
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
    I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
    I2C_InitStructure.I2C_DigitalFilter = 0x00;
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
    I2C_InitStructure.I2C_OwnAddress1 = 0x00; 
    I2C_InitStructure.I2C_Timing = 0x00201D2B;

    I2C_Init(I2C1, &I2C_InitStructure);

    I2C_Cmd(I2C1, ENABLE);

uint8_t I2C_Read(uint8_t address, uint8_t reg){

    uint8_t ReadByte;

    I2C_TransferHandling(I2C1,address, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET); //the program stucks here

    I2C_SendData(I2C1, (uint8_t)reg);
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_TC) == RESET);

    I2C_TransferHandling(I2C1,address, 1, I2C_AutoEnd_Mode,I2C_Generate_Start_Read);

    ReadByte = I2C_ReceiveData(I2C1);
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_RXNE) == RESET);

    while(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF));
    I2C_ClearFlag(I2C2, I2C_ICR_STOPCF);

    return ReadByte;

And the calling of the read function:

    uint16_t readSensitivity()
//The sensor address is 0x01, the register adresses are 0x0A and 0x0B
        return (I2C_Read(0x01, 0x0A) << 8) + I2C_Read(0x01, 0x0B);

The relevant part of my schematic is following: enter image description here enter image description here

What can be the problem?


1 Answer 1


The I²C Address of a 24C02 EEPROM cannot be 0x01. The HH10D datasheet is misleading in this, the real I²C address should be something like A2, see M24C02.

  • \$\begingroup\$ You are right, the HH10D was misleading. \$\endgroup\$
    – Milan Tenk
    Oct 17, 2015 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.