cancel
Showing results for 
Search instead for 
Did you mean: 

I2C GPIO config

davidfussell9
Associate II
Posted on July 02, 2008 at 13:54

I2C GPIO config

1 REPLY 1
davidfussell9
Associate II
Posted on May 17, 2011 at 09:54

Hi,

I'm after some clarification on the correct configuration of GPIO pins when used for I2C.

I see from the doc'n that each I2C pin (Clock & Data) has both an IN and an OUT (via alternative input/output settings). Does this mean, for example, that for a Master the CLK pin remains as an output, but the Data pin needs to be re-configured to be an input during a read cycle- or will the following work?

// Configure I2C1 as Master on port 2

vl_GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput;

vl_GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;

vl_GPIO_InitStructure.GPIO_Type = GPIO_Type_OpenCollector ;

vl_GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable;

vl_GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt2;

GPIO_Init (GPIO2, &vl_GPIO_InitStructure);

Presumably, the required GPIO configuration for Master and Slave I2C ports are different...?

Thanks

Dave