2013-09-01 09:26 AM
Hello,
I am trying to get the I2C bus to run with the MMA8452 accelerometer, but it just wont. I can generate a start condition but nothing else. I'm watching the bus lines with a scope/logic analyzer and I can see that it doesn't generate anything after the start condition on SCL/SDA. In debug mode I also noticed that after writing to the I2C data register the ''AF - acknowledge failure'' bit is set in SR1 The code:RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2); GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); I2C_InitTypeDef I2C_InitStruct; I2C_InitStruct.I2C_Ack = I2C_Ack_Enable; I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; I2C_InitStruct.I2C_ClockSpeed = 100000; I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; I2C_InitStruct.I2C_OwnAddress1 = 0; I2C_Init(I2C2, &I2C_InitStruct); I2C_Cmd(I2C2, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); while(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0)); GPIO_SetBits(GPIOA, GPIO_Pin_5); //Trigger for analyzer I2C_GenerateSTART(I2C2, ENABLE); I2C_Send7bitAddress(I2C2, 0x3A, I2C_Direction_Transmitter); while(1); Any suggestions?2013-09-01 10:00 AM
You don't fill the pin initialization structure completely/properly. Make sure to configure the output in Open Drain mode, and use pull-up resistors.
If address 0x3A doesn't work, try 0x382013-09-01 10:20 AM
Ok, thanks, I changed it but it doesn't seem to have any affect, still no transmission after start condition!
2013-09-02 02:27 AM