i2c driver for STM32F051

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

lex
Posts: 6
Joined: Fri Mar 21, 2014 3:12 am

i2c driver for STM32F051

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: i2c driver for STM32F051

Post 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
lex
Posts: 6
Joined: Fri Mar 21, 2014 3:12 am

Re: i2c driver for STM32F051

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: i2c driver for STM32F051

Post by Giovanni »

It is something related to the compiler, probably you have to add the math lib to the makefile.

Giovanni
lex
Posts: 6
Joined: Fri Mar 21, 2014 3:12 am

Re: i2c driver for STM32F051

Post 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
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: i2c driver for STM32F051

Post by Giovanni »

Wrong place, there is a line for user libraries in the Makefile of your project.

Giovanni
lex
Posts: 6
Joined: Fri Mar 21, 2014 3:12 am

Re: i2c driver for STM32F051

Post by lex »

Sorry, but I'm a beginner. But after adding the option error message disappeared and the compilation was successful.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: i2c driver for STM32F051

Post by Giovanni »

The option is right :) but rules.mk is a shared file, you have to put that same option in Makefile.

Giovanni
lex
Posts: 6
Joined: Fri Mar 21, 2014 3:12 am

Re: i2c driver for STM32F051

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: i2c driver for STM32F051

Post by Giovanni »

It is correct.

Giovanni
Post Reply