Skip to main content
j239955_stm1_st
Visitor II
June 28, 2016
Question

STM32F0 I2C Read Problem

  • June 28, 2016
  • 1 reply
  • 594 views
Posted on June 28, 2016 at 17:14

Hallo,

Leider komme ich noch nicht so ganz mit dem lesen von I2C Slaves klar. Das schreiben klappt.

Hat jemand eine funktionierende Routine womit ich das lesen mal testen könnte?

Im Internet finde ich zwar vieles, nichts funktioniert so wirklich :'(

Hiermit schreibe ich Daten:

uint8_t I2C_WrReg(I2C_TypeDef *I2Cx, uint8_t Addr, uint8_t Reg, uint8_t Val)

{

    uint32_t tme_out = 0;

    while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY) == SET)

    {

        if(tme_out++ > 800000)

        {

            tme_out = 0;

            return ERROR;

        }

    }

    I2C_TransferHandling(I2Cx, Addr, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);

    while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_TXIS) == RESET)

    {

        if(tme_out++ > 800000)

        {

            tme_out = 0;

            return ERROR;

        }

    }

    I2C_SendData(I2Cx, Reg);

    while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_TCR) == RESET)

    {

        if(tme_out++ > 800000)

        {

            tme_out = 0;

            return ERROR;

        }

    }

    I2C_TransferHandling(I2Cx, Addr, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);

    while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_TXIS) == RESET)

    {

        if(tme_out++ > 800000)

        {

            tme_out = 0;

            return ERROR;

        }

    }

    I2C_SendData(I2Cx, Val);

    while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_STOPF) == RESET)

    {

        if(tme_out++ > 800000)

        {

            tme_out = 0;

            return ERROR;

        }

    }

    I2C_ClearFlag(I2Cx, I2C_FLAG_STOPF);

    return SUCCESS;

}
    This topic has been closed for replies.

    1 reply

    Nesrine M_O
    Associate
    June 29, 2016
    Posted on June 29, 2016 at 12:35

    Hi homann.jan,

    Please use English (to be more understandable) in your post.

    Have a look to these examples under the

    http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32-standard-peripheral-libraries/stsw-stm32048.html

    it may be helpful. 

    stm32f0_stdperiph_lib\STM32F0xx_StdPeriph_Lib_V1.5.0\Projects\STM32F0xx_StdPeriph_Examples\I2C

    -Syrine-