AnsweredAssumed Answered

STM32F4xx - cannot start the pheriperie I2C

Question asked by muller.markus on Jun 6, 2012
Latest reply on Oct 15, 2012 by Fred

Always, when I set on the clock in I2C1 or I2C2, in the status register SR2 is the BUSY bit set.

Here the code:
int main(void) 
  I2C1_DBG = (I2C_TypeDef *)  I2C1_BASE; // for debugging 
  RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;  // Active the clockwhile(1); 
This code is start directly without other startup-code.

Why is the BUSY bit set?

I test it with the STM32F4-Discovery Board. This pins are with 4K7 PullUp Resistor.
Then, when I activate the GIPO (Configuration, AF, Clock), then the SCL/SDA goes low.

I have checked my start code with CPAL code, but I have not find out what can be wrong.

Can every body write me how I must start the initialization vom I2C?
I have change all order from initializations but always the same, it do not work.

Please help me, I have now spend a lot of time for that and it do not work.

Regards, Markus.

Edit: Here the complete code from my initialization, who does not work:
  I2C1->CR1 &= ~I2C_CR1_PE; // Pheriperie Disable 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, DISABLE); 
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); 
  GPIO_PinAFConfig(GPIOB, GPIO_Pin_6, GPIO_AF_I2C1); 
  GPIO_PinAFConfig(GPIOB, GPIO_Pin_9, GPIO_AF_I2C1); 
  GPIOB->BSRR = GPIO_Pin_6 | GPIO_Pin_9; 
  GPIO_InitSt.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_9; // SCL / SDA 
  GPIO_InitSt.GPIO_Mode = GPIO_Mode_AF; 
  GPIO_InitSt.GPIO_OType = GPIO_OType_OD; 
  GPIO_InitSt.GPIO_Speed = GPIO_Speed_50MHz; 
  GPIO_Init(GPIOB, &GPIO_InitSt); 
  I2C1->CR1 |= I2C_CR1_PE; // Pheriperie Enable 
  I2C_InitSt.I2C_Mode = I2C_Mode_I2C; 
  I2C_InitSt.I2C_DutyCycle = I2C_DutyCycle_2; 
  I2C_InitSt.I2C_OwnAddress1 = 0;//0x10; 
  I2C_InitSt.I2C_Ack = I2C_Ack_Enable; 
  I2C_InitSt.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; 
  I2C_Init(I2C1, &I2C_InitSt); // disable & enable