2013-11-22 08:10 AM
Hi,
here my code for I2C setup on STM32F051R8 (STM32 discovery board practically)void set_I2C(void){
GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure;RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);/* Configure the I2C clock source. The clock is derived from the HSI */
RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1);//Configure pins: SCL and SDA ------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; GPIO_Init(GPIOB, &GPIO_InitStructure);I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable;
I2C_InitStructure.I2C_DigitalFilter = 0x00; I2C_InitStructure.I2C_OwnAddress1 = 0x00; // MPU6050 7-bit adress = 0x68, 8-bit adress = 0xD0; I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; //I2C_InitStructure.I2C_Timing = 0xA0120227; I2C_InitStructure.I2C_Timing = 0x20310A0D; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;I2C_Init(I2C1, &I2C_InitStructure);
I2C_Cmd(I2C1, ENABLE);
}
but when in the main I try to send one data: I2C_SendData(I2C1, 0xAA); I don't see any signal on the Pb6 PB7. Please, can you tell me what's wrong? Thanks a lot in advance. #stm32 #i2c #stm32f02013-11-28 11:11 PM
Hi Clive,
today I tried this instruction:I2C_GenerateSTART(I2C1,
ENABLE
); and I see with the scope che clock and one data... so it seems the I2C is correctly set up... but how can I send my desiderd data on the bus? I hope you can help me... I have no othe ideas.. :(2014-11-04 08:48 AM
Hi there,
Did you solve this problem? I've been having the same issue lately in where I can't even get garbage data outputting on the I2C bus.