AnsweredAssumed Answered

STM32 I2C init failed

Question asked by ivanov.vladimir on Apr 13, 2012
Latest reply on Apr 18, 2012 by dsouza.hansen.001
ATTENTION! The following code do not work for STM32 I2C while looking good:

void I2C_Ini(void){ I2C_InitTypeDef I2C_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; // I2C RCC RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); // I2C GPIO RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE);// SCL=B8,SDA=B9 PININI(SCL,GPIO_Mode_AF_OD,GPIO_Speed_50MHz);PINLOCK(SCL); //macros w/o errors PININI(SDA,GPIO_Mode_AF_OD,GPIO_Speed_50MHz);PINLOCK(SDA);// macros w/o errors // I2C config I2C_InitStructure.I2C_ClockSpeed = 100000; I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = 0xAA; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_Init(I2C1,&I2C_InitStructure); I2C_Cmd(I2C1,ENABLE); // I2C NVIC NVIC_InitStructure.NVIC_IRQChannel = I2C1_EV_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure.NVIC_IRQChannel = I2C1_ER_IRQn; NVIC_Init(&NVIC_InitStructure); I2C_ITConfig(I2C1,I2C_IT_EVT,ENABLE); // enable event IRQ I2C_ITConfig(I2C1,I2C_IT_ERR,ENABLE); // enable error IRQ I2C_ITConfig(I2C1,I2C_IT_BUF,ENABLE); // enable buffer IRQ }
As a result of this init the BUSY bit is set and I2C can't work! The ref manual don't provide any info about this.

Outcomes