hello. I want to write byte to the sensör with I2C so write this code :
void MPU6050_I2C_Init() { // RCC Configuration RCC_HCLKConfig(RCC_SYSCLK_Div2); RCC_PCLK1Config(RCC_HCLK_Div1); RCC_PCLK2Config(RCC_HCLK_Div1); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); // GPIO Configuration GPIO_Config_Anahtari.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_Config_Anahtari.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Config_Anahtari.GPIO_Speed = GPIO_Speed_2MHz; GPIO_Init(GPIOB,&GPIO_Config_Anahtari); GPIO_PinRemapConfig(GPIO_Remap_I2C1,ENABLE); // I2C Configuration I2C_Config_Anahtari.I2C_Mode = I2C_Mode_I2C; I2C_Config_Anahtari.I2C_ClockSpeed = 400000; I2C_Config_Anahtari.I2C_DutyCycle = I2C_DutyCycle_2; I2C_Config_Anahtari.I2C_Ack = ENABLE; I2C_Config_Anahtari.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_Config_Anahtari.I2C_OwnAddress1 = 0x10; I2C_Init(I2C1,&I2C_Config_Anahtari); I2C_Cmd(I2C1,ENABLE); } void I2C_MonitorAndClear_ADDR() { while(I2C_GetFlagStatus(I2C1,I2C_FLAG_ADDR)==RESET); I2C_ReadRegister(I2C1,I2C_Register_SR1); I2C_ReadRegister(I2C1,I2C_Register_SR2); } void I2C_Clear_SB_Monitor_MSL() { I2C_ReadRegister(I2C1,I2C_Register_SR1); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_MSL)==RESET); } void MPU6050_SingleByte_Write(uint8_t register_address,uint8_t data) { while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)==SET); I2C_GenerateSTART(I2C1,ENABLE); I2C_Clear_SB_Monitor_MSL(); I2C_Send7bitAddress(I2C1,MPU6050_Default_Address,I2C_Direction_Transmitter); I2C_MonitorAndClear_ADDR(); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_TRA)==RESET); I2C_SendData(I2C1,register_address); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_TXE)==RESET); I2C_SendData(I2C1,data); while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BTF)==RESET); I2C_GenerateSTOP(I2C1,ENABLE); }
here is my functions . In RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); line , BUSY flag is set and never reset. So code hangs in here. When I reset the I2C1 periph clock with RCC_APB2PeriphResetCmd command , busy flag is reset but I can't configure the I2C interface after reset cmd. So what is the problem ?
thanks for your answer.