cancel
Showing results for 
Search instead for 
Did you mean: 

StdPeriph_Driver I2C

dennisvantienhoven
Associate II
Posted on November 30, 2011 at 12:01

Hello all,

I want to use the StdPeriph_Driver as a guide for my own project.

Part: STM32F100RB value line discovery (test kit).

Trying to get the I2C to work.

I want to use the I2C files (.c+.h) for my own project.

So when I put these files in my own project

(included correctly I think: I put the files i2c.c and i2c.h in de src folder and included 

- stm32f10x.h and

- stm32f10x_conf.h

in the firmware folder and included in the i2c.h file like:

&sharpinclude ''../firmware/stm32f10x.h''

&sharpinclude ''../firmware/stm32f10x_conf.h''

Now I call the I2C_StructInit function in my main.c

But it gives the error: too few arguments to function 'I2C_StructInit'

I've absolutely no idea what to include in that function.

i2c.c

void I2C_StructInit(I2C_InitTypeDef* I2C_InitStruct){

...

}

I2C_InitTypeDef refers to:

typedef struct{

... declaring variables.

}I2C_InitTypeDef;

If a take a look at void I2C_Init(I2C_TypeDef* I2Cx, I2C_InitTypeDef* I2C_InitStruct){

...

}

Then I see that I2Cx need to be I2C2 (the I2C I use).

But what does I2C_InitStruct need to be?

your help

is very appreciated

!

If I do something wrong here, just mention it.

Greets,

Dennis.

#stm32l-discovery-i2c-problem #i2c
4 REPLIES 4
Posted on November 30, 2011 at 15:33

Show your code that is failing, everyone has the library.

You would normally point to the library/include code by telling the compiler where there directories are, or drop them in the project.

For most of the project templates it's a matter of uncommenting line is stm32f10x_conf.h to pull in the right peripherals.

{

  I2C_InitTypeDef  I2C_InitStructure;

  I2C_Cmd(I2C2, ENABLE);

  I2C_StructInit(&I2C_InitStructure);

  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;

  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;

  I2C_InitStructure.I2C_OwnAddress1 = SLAVE_ADDRESS7;

  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;

  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;

  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;

  I2C_Init(I2C2, &I2C_InitStructure);

  ..

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dennisvantienhoven
Associate II
Posted on November 30, 2011 at 16:20

Find my problem.

ST gives you the option to create your own memory location for the I2C_InitTypeDef struct.

I didn't knew what to do with it, but now I know.

In the i2c.c file I wrote:

static I2C_InitTypeDef    I2C_InitStruct;

For creating a memory location for the struct.

now I've done this, it works, I'm not getting errors from it anymore.

But I've absolutely no idea why they created a InitStruct to fill in the struct of the I2C registers.

I should only use the Init function to write to these registers.

Or am I wrong and is this usefull after all?

Greets,

Dennis.

Posted on November 30, 2011 at 17:07

It is a temporary structure feed to the library routines to configure the hardware. Once done it is never used again. I wouldn't make it a static/global structure.

It often makes sense to use the I2C_StructInit() to clear the structure to default settings, especially when allocated from the stack as a local variable. Remember the stack contains random junk when the local variables are not explicitly set/initialized.

You could program the I2C peripheral registers directly, but then you'd need to deal with a whole level of minutia that becomes very unportable across device families.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
samuel239955_st
Associate II
Posted on June 27, 2012 at 08:09

Hi All;

I am using STM32L Discovery board to do I2C write and read to M24C64 eeprom via I2C interrupt. When I continous writing the EEPROM (with about 10mS interval), I find it lost data. From the Scope, a bad packet is only a START, no ''7 bits of address'', no Slave address and no data pulse.

Attached is the source code and read me.txt file.

Any solution?

Regards

Samuel

________________

Attachments :

STM32_I2C_WR_Via_Int.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzoN&d=%2Fa%2F0X0000000bQY%2Fa1k9yF5tyCGm3.BJSfnsoi6mqyzeYGmrtWqttNxpxys&asPdf=false