2023-04-15 11:41 PM - edited 2023-11-20 08:01 AM
Im using STM32F302R8 and developing the driver for I2CMasterReceive data from Arduino.
Here is my problem:
After 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.
I do not know why this problem happen. Could anyone help me?
2023-04-17 03:23 AM
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.
2023-04-17 04:33 PM - edited 2023-11-20 08:02 AM
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: