hamidkavianathar
Member level 5
hi guys
I want to read data from mpu 9250. I've written this code. but it's hanging at line 24.
could you please tell me, what should I do?
thanks.
I want to read data from mpu 9250. I've written this code. but it's hanging at line 24.
Code:
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
thanks.
Code:
[LIST=1]
[*] /* While the bus is busy */
[*] while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
[*]
[*] /* Send START condition */
[*] I2C_GenerateSTART(I2C1, ENABLE);
[*]
[*] /* Test on EV5 and clear it */
[*] while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
[*]
[*] /* Send 9250 address for write */
[*] I2C_Send7bitAddress(I2C1, MPU9250_ADDRESS , I2C_Direction_Transmitter);
[*]
[*] /* Test on EV6 and clear it */
[*] while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
[*]
[*] /* Clear EV6 by setting again the PE bit */
[*] //I2C_Cmd(I2C1, ENABLE);
[*]
[*] /* Send the 9250's internal address to write to */
[*] I2C_SendData(I2C1, ReadAddr);
[*]
[*] /* Test on EV8 and clear it */
[*] while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
[*]
[*] /* Send STRAT condition a second time */
[*] I2C_GenerateSTART(I2C1, ENABLE);
[*]
[*] /* Test on EV5 and clear it */
[*] while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
[*]
[*] /* Send 9250 address for read */
[*] I2C_Send7bitAddress(I2C1, MPU9250_ADDRESS , I2C_Direction_Receiver);
[*]
[*] /* Test on EV6 and clear it */
[*] while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
[*]
[*] /* While there is data to be read */
[*] while(NumByteToRead)
[*] {
[*] if(NumByteToRead == 1)
[*] {
[*] /* Disable Acknowledgement */
[*] I2C_AcknowledgeConfig(I2C1, DISABLE);
[*]
[*] /* Send STOP Condition */
[*] I2C_GenerateSTOP(I2C1, ENABLE);
[*] }
[*]
[*] /* Test on EV7 and clear it */
[*] if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))
[*] {
[*] /* Read a byte from the 9250 */
[*] *pBuffer = I2C_ReceiveData(I2C1);
[*]
[*] /* Point to the next location where the byte read will be saved */
[*] pBuffer++;
[*]
[*] /* Decrement the read bytes counter */
[*] NumByteToRead--;
[*] }
[*] }
[*]
[*] /* Enable Acknowledgement to be ready for another reception */
[*] I2C_AcknowledgeConfig(I2C1, ENABLE);
[*]}
[*]
[/LIST]