2012-06-06 02:30 AM
Hello,
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 clock
while
(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
I2C_DeInit(I2C1); 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_PuPd = GPIO_PuPd_NOPULL; 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
#stm32f4-i2c2012-06-07 09:58 PM
Did you enable the RCC of GPIO ?
Why not to start with standard peripheral example on I2C ?2012-10-12 06:30 AM
Hello,
I have the same problem. Do you solve it ?2012-10-15 01:33 AM
I've found the solution. I've forgotten to config cpal_i2c_hal_stm32f2xx.h file because this microntroller has several pins for the same I2C device. So the section 1 allows user to choose IO Pins for each device if possible (in accordance with used product: some products have only one possibility for the IO pins).