Question
stm32 accelerometer
Posted on April 30, 2014 at 11:54
hi, I have a problem. I2C busy flag always set.
I am using I2C1 peripherel. this peripherel conected EEPROM, IO expander and Lis302dlI think, problem is attaching EEPROM or IO expander. how can I disconnect EEPROM and IO expander using software. If this is not the problem, what is problem ?my configuration codes: GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; //GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7; GPIO_Init(GPIOB,&GPIO_InitStructure); I2C_Cmd(I2C1, ENABLE); I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = 0x00; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = 100000; I2C_Init(I2C1, &I2C_InitStructure);codes for reading process: unsigned char uc; I2C_GenerateSTART(I2C1, ENABLE); while (!(I2C_sr() & 0x0001)); // start condition generate edilene kkadar bekliyoz. I2C_Send7bitAddress(I2C1, address, I2C_Direction_Transmitter); while (!(I2C_sr() & 0x0002)); //Addr sent olana kadan bekle I2C_SendData(I2C1,cmd); while (!(I2C_sr() & 0x00000004)); /* Wait until BTF bit set */ I2C_GenerateSTART(I2C1, ENABLE); while (!(I2C_sr() & 0x0001)); // start condition generate edilene kkadar bekliyoz. I2C_Send7bitAddress(I2C1, address,I2C_Direction_Receiver); while (!(I2C_sr() & 0x0002)); //Addr sent olana kadan bekle uc = I2C_ReceiveData(I2C1); while (!(I2C_sr() & 0x00000040)); /* Wait until RxNE bit set */ I2C_GenerateSTOP(I2C1, ENABLE); while (I2C_sr() & 0x00020000); /* Wait until BUSY bit reset */ return( uc );