AnsweredAssumed Answered

I2C initialisation problem STM32F0308 - Discovery

Question asked by viglione.roberto on Feb 23, 2016
Latest reply on Feb 23, 2016 by viglione.roberto
Hello all,

I'm trying to get both I2C peripherals to work on my STM32F0308 - Discovery board. I am using OpenSTM32 toolchain with Eclipse Mars.

I downloaded the MxCube example projects for the F0 and loaded the I2C example with interrupts. To initialize both I2C peripherals, I tried to modify the HAL_I2C_MspInit() function in the following manner:

void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c)
{
    if (hi2c->Instance == I2C1)
    {
        // Do stuff for I2C1
    }
    else
    {
        // Do stuff for I2C2      
    }
}

So here is my problem. In my initilisation, I have the following line;
GPIO_InitStruct.Pin = I2Cx_SCL_PIN;

When I go to the declaration of I2Cx_SCL_PIN, it points to the main.h file. So I changed the I2Cx portion to I2C1, and dupliacted all the #define to have I2C2 instances aswell. However, when I go back to my code and change the line to:

GPIO_InitStruct.Pin = I2C1_SCL_PIN;

Eclipse complains and says that I2C1_SCL_PIN isn't declared. When I change it back to I2Cx_SCL_PIN and go to the declaration, it goes to and highlights I2C1_SCL_PIN. Also, if I delete the #define altogether, it still points to something inside my main.h file, even though the #define no longer exists.

Has anyone encountered similar problems and figured out why this is happening?

Outcomes