cancel
Showing results for 
Search instead for 
Did you mean: 

I am doing I2C project with [MPU6050][1] using [STM32F4DISCOVERY][2] board. The ADDR bit in SR1 register is clearing in one instruction execution without reading SR2 register. Because of clearing ADDR bit, I can't do acknowledge disable is made during EV6

Npedi.455
Associate

The datasheet states:

>ADDR: Address sent (master mode)/matched (slave mode) This bit is cleared by software reading SR1 register followed reading SR2.

In case a single byte has to be received, the Acknowledge disable is made during EV6 (before ADDR flag is cleared) and the STOP condition generation is made after EV6.

If I write any instruction (or declaration) between `I2C->DR=address|0` and `while(!(I2C2->SR1 & (1<<1)))` in below code, then ADDR flag is cleared without reading the SR2 register (`I2C2->SR2`).

if(direction==i2c_transmitter_mode)

{

I2C2->DR = address ;//SEND ADDRESS WITH ZERO LAST BIT

while(!(I2C2->SR1 & (1<<1)))

{

if(--i2c1_timeout==00)

{

return 1;

}

}

I2C2->SR2;

return 0;

}

I am sending WHO_AM_I register address and getting 0x68h.so,ADDR and TXE bits are set.but ADDR flag is being cleared immediately.

How can I fix this problem?

1 REPLY 1

>>How can I fix this problem?

perhaps you could use the libraries using the memory addressing API function?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..