Skip to main content
paulcowper
Associate II
November 21, 2011
Question

Does anyone have a quick and dirty i2c example?

  • November 21, 2011
  • 14 replies
  • 2866 views
Posted on November 22, 2011 at 00:18

Hi all,

I am very new to the STM32, currently using the STM32L..

As I am new to developing on this platform (Never touched anything ARM before), I am overwhelmed by the amount of documentation although trying to dig out the bits that are useful is a little confusing to me right now. While there is lots of information about i2c, it is very application specific (EEPROM etc). Some times I think simple is best.

I am wondering if anyone would be able to take the time to help me? I am using the standard lib and using TrueStudio.

I would like to see if anyone could create or already has an example of the following:

Setting up i2c, Setting the micro as the master, checking the presense of the device at address 0x40 and verifying the ACK and sending data to it, and maybe as a brucie bonus being able to do the same for a second device on the same bus. The actual slave is an IO extender device that I am using to test i2c.

Now I could go and read through the documentation again lots of times and try and get the bits I need. I have tried and failed to break bits out of the ST help files.

Your efforts are most apreciated :)

Many Thanks

Paul
    This topic has been closed for replies.

    14 replies

    Tesla DeLorean
    Guru
    November 24, 2011
    Posted on November 24, 2011 at 15:47

        /*!< Configure I2C SCL pin */

     

        GPIO_InitStructure.GPIO_Pin = GPIO_PinSource6;

     

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

     

    ..   

     

         /*!< Configure I2C SDA pin */

     

        GPIO_InitStructure.GPIO_Pin = GPIO_PinSource7;

     

     

    These don't use GPIO_PinSourceX (an index), but GPIO_Pin_X (a bit field)

        /*!< Configure I2C SCL pin */

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    ..   

         /*!< Configure I2C SDA pin */

        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    paulcowper
    Associate II
    November 24, 2011
    Posted on November 24, 2011 at 16:00

    Hi Clive,

    Doh! It just shows how little I know about this platform at the moment, I shall change them over when I get home.

    Thank you very much all

    Paul

    paulcowper
    Associate II
    November 24, 2011
    Posted on November 24, 2011 at 19:45

    Excellent, i2c is now alive :) Well at least im getting past I2C_EVENT_MASTER_MODE_SELECT.

    I am now timing out on I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED. But I will take more of a look into that.

    Thanks all

    Cheers

    Paul

    bekir
    Associate
    July 21, 2012
    Posted on July 21, 2012 at 07:13

    Hi Paul,

    I am new at I2C at stm32, Can you send me your latest version of your code?

    does it contain IT ?