cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F302R8 I2C1 Master Receiver. I2C_ISR_RXNE is not SET.

WM_IR
Senior

Im using STM32F302R8 and developing the driver for I2CMasterReceive data from Arduino.

Here is my problem:


_legacyfs_online_stmicro_images_0693W00000biAUCQA2.pngAfter I send a command code, from master 0x51, and generate the start condition, the RXNE is SET.

But, after it goes into the while loop, the RXNE suddenly RESET. I do not read yet the RXDR register.


_legacyfs_online_stmicro_images_0693W00000biAUMQA2.png 

I do not know why this problem happen. Could anyone help me?

2 REPLIES 2
Foued_KH
ST Employee

Hello @WM_IR​ ,

If only 1 BYTE needs to be Read, follow thus steps :

a) Write the slave Address, and wait for the ADDR bit (bit 1 in SR1) to be set. This indicates that the address has been transmitted

I2C1->DR = Address;  //  send the address
while (!(I2C1->SR1 & (1<<1)));  // wait for ADDR bit to set

b) the Acknowledge disable is made during EV6 (before ADDR flag is cleared) and the STOP condition generation is made after EV6

I2C1->CR1 &= ~(1<<10);  // clear the ACK bit 
uint8_t temp = I2C1->SR1 | I2C1->SR2;  // read SR1 and SR2 to clear the ADDR bit.

c) Wait for the RXNE (Receive Buffer not Empty) bit to set

while (!(I2C1->SR1 & (1<<6)));  // wait for RxNE to set

d) Read the data from the DR

buffer[1] = I2C1->DR;  // Read the data from the DATA REGISTER

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

After I try to understand, isn't your code is for the STM32 become slave? Actually, Im working on the STM32 as Master, but it received data from the slave. Which can refer here:


_legacyfs_online_stmicro_images_0693W00000biGbdQAE.png
_legacyfs_online_stmicro_images_0693W00000biGbiQAE.png
_legacyfs_online_stmicro_images_0693W00000biGbnQAE.png