cancel
Showing results for 
Search instead for 
Did you mean: 

When I should set the GPIO to open drain mode or push-pull mode?

viprobin
Associate
Posted on January 12, 2012 at 13:30

There is a part of codes in the stm324xg_eval_audio_codec.c.

/* CODEC_I2C SCL and SDA pins configuration -------------------------------------*/

  /* If the I2C peripheral is already enabled, don't reconfigure it */

  if ((CODEC_I2C->CR1 & I2C_CR1_PE) != 0)

  {

    GPIO_InitStructure.GPIO_Pin = CODEC_I2C_SCL_PIN | CODEC_I2C_SDA_PIN;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_OType =

GPIO_OType_OD

;

    GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;

    GPIO_Init(CODEC_I2C_GPIO, &GPIO_InitStructure);     

    /* Connect pins to Periph */

    GPIO_PinAFConfig(CODEC_I2C_GPIO,

CODEC_I2S_SCL_PINSRC

, CODEC_I2C_GPIO_AF);  

    GPIO_PinAFConfig(CODEC_I2C_GPIO,

CODEC_I2S_SDA_PINSRC

, CODEC_I2C_GPIO_AF);  

  }

  /* CODEC_I2S pins configuration: WS, SCK and SD pins -----------------------------*/

  GPIO_InitStructure.GPIO_Pin = CODEC_I2S_WS_PIN | CODEC_I2S_SCK_PIN | CODEC_I2S_SD_PIN;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_OType =

GPIO_OType_PP

;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

  GPIO_Init(CODEC_I2S_GPIO, &GPIO_InitStructure);     

  /* Connect pins to I2S peripheral  */

  GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_WS_PINSRC, CODEC_I2S_GPIO_AF);  

  GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SCK_PINSRC, CODEC_I2S_GPIO_AF);

  GPIO_PinAFConfig(CODEC_I2S_GPIO, CODEC_I2S_SD_PINSRC, CODEC_I2S_GPIO_AF);

I want to know why I2C and I2S use different modes. By the way, I think

CODEC_I2S_SCL_PINSRC

shoud be corrected to 

CODEC_

I2C

_SCL_PINSRC.

#basic-electronics
2 REPLIES 2
Posted on January 12, 2012 at 13:45

I2C has always been a bidirectional interface using open collector/drain, slave devices recognize when they are addressed and need to signal back to the master. Push-pull would cause drivers to fight/contend with each other.

I2S is a single slave, point-to-point interface, as I recall.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 14, 2012 at 18:08

''When I should set the GPIO to open drain mode or push-pull mode?''

You set whatever the application requires!

''Open-Drain'', ''Open-Collector'' and ''Push-Pull'' are basic electronic terms - nothing specifically to do with the STM32. If you're not familiar with the terms, a basic electronics text book should help...

http://en.wikipedia.org/wiki/Push%E2%80%93pull_output

http://en.wikipedia.org/wiki/Open_collector

http://en.wikipedia.org/wiki/Open_drain

http://www.opamp-electronics.com/tutorials/digital_theory_ch_003.htm