cancel
Showing results for 
Search instead for 
Did you mean: 

i2c start doesn't do anything on the bus

saccrue
Associate II
Posted on October 28, 2012 at 17:18

I am trying to write an i2c driver for my stm32f100 discovery board. To verify that it is setup right, I want to send a start condition and check to see that the SDA line goes low while SCL stays high. I have the following code (borrowed from the web)...

void I2C_Setup(void) 
{ 
GPIO_InitTypeDef GPIO_InitStructure; 
I2C_InitTypeDef I2C_InitStructure; 
/* I2C1 clock enable */ 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); 
/*enable I2C*/ 
I2C_Cmd(I2C1,ENABLE); 
/* I2C1 SDA and SCL configuration */ 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; 
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; // Alternate function Open Drain 
GPIO_Init(GPIOB, &GPIO_InitStructure); 
/*SCL is pin06 and SDA is pin 07 for I2C1*/ 
/* I2C1 configuration */ 
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; 
I2C_InitStructure.I2C_OwnAddress1 = 0x04; 
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; 
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; 
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED ; 
I2C_Init(I2C1, &I2C_InitStructure); 
} 

I call this function first and then try to send the start condition...

/* initiate start sequence */ 
I2C_GenerateSTART(I2C1, ENABLE); 
/* check start bit flag */ 
while(!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB));

I have an o-scope connected to both SDA and SCL but I don't see SDA go low as I would expect. I just put in the own address as 0x4 for now. There is no slave on the bus, I just have the two gpio lines going to a breadboard fed by 3.3 from the discovery board and those pins are pulled high with 4.7K pullups. I was expecting to see SDA go low. Is my understanding of the protocol incorrect or is the web sample missing something?
2 REPLIES 2
Posted on October 28, 2012 at 21:13

Have you enabled the GPIOB clock?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
saccrue
Associate II
Posted on October 28, 2012 at 22:34

No, I didn't enable the GPIOB clock. That was it. It was left out of the sample I took from the web.

thanks clive1!