Page 1 of 2

i2c driver for STM32F051

Posted: Fri Mar 21, 2014 3:37 am
by lex
Hi,

i need configure i2c driver for STM32F051. I not find i2c example for this MCU. I'm using ChibiOS 2.6.3.

If I use this configuration:

Code: Select all

static const I2CConfig i2cfg1 = {
    OPMODE_I2C,
    400000,
    FAST_DUTY_CYCLE_2,
};

so when compiling I get this error:

Code: Select all

main.c:56:5: error: 'OPMODE_I2C' undeclared here (not in a function)
main.c:58:5: error: 'FAST_DUTY_CYCLE_2' undeclared here (not in a function)

I modified example project ARMCM0-STM32F051-DISCOVERY.
What is wrong?

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 9:08 am
by Giovanni
Hi,

Look at the I2C example for the STM32F37x, it uses the same I2Cv2 peripheral. The structure you used is for the driver of the old I2Cv1 peripheral.

./testhal/STM32F37x/I2C

Giovanni

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 12:18 pm
by lex
Thank you for quick reply, I'll try it. But now I have another problem: exists in chibios function pow()? If not, is there any replacement?

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 12:20 pm
by Giovanni
It is something related to the compiler, probably you have to add the math lib to the makefile.

Giovanni

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:25 pm
by lex
Adding the pow() function is solved:

need add line

Code: Select all

LDFLAGS  += -lm

before lines

Code: Select all

# Generate dependency information
CFLAGS   += -MD -MP -MF .dep/$(@F).d
CPPFLAGS += -MD -MP -MF .dep/$(@F).d

in a file rules.mk

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:27 pm
by Giovanni
Wrong place, there is a line for user libraries in the Makefile of your project.

Giovanni

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:44 pm
by lex
Sorry, but I'm a beginner. But after adding the option error message disappeared and the compilation was successful.

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:50 pm
by Giovanni
The option is right :) but rules.mk is a shared file, you have to put that same option in Makefile.

Giovanni

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:55 pm
by lex
in the Makefile I found this:

Code: Select all

DLIBS =

and i changes to the:

Code: Select all

DLIBS = -lm

is that correct? Apparently so, because the error message is not displayed.

Re: i2c driver for STM32F051

Posted: Fri Mar 21, 2014 1:56 pm
by Giovanni
It is correct.

Giovanni