- while (NumByteToRead)
- {
-
- if (NumByteToRead != 3) /* Receive bytes from first byte until byte N-3 */
- {
- while ((I2C_GetLastEvent(I2C1) & 0x00004) != 0x000004); /* Poll on BTF */
- /* Read data */
- *pBuffer = I2C_ReceiveData(I2C1);
- pBuffer++;
- /* Decrement the read bytes counter */
- NumByteToRead--;
- }
-
- if (NumByteToRead == 3) /* it remains to read three data: data N-2, data N-1, Data N */
- {
-
- /* Data N-2 in DR and data N -1 in shift register */
- while ((I2C_GetLastEvent(I2C1) & 0x000004) != 0x0000004); /* Poll on BTF */
- /* Clear ACK */
- I2C_AcknowledgeConfig(I2C1, DISABLE);
- __disable_irq();
- /* Read Data N-2 */
- *pBuffer = I2C_ReceiveData(I2C1);
- pBuffer++;
- /* Program the STOP */
- I2C_GenerateSTOP(I2C1, ENABLE);
- /* Read DataN-1 */
- *pBuffer = I2C_ReceiveData(I2C1);
- __enable_irq();
- pBuffer++;
- while ((I2C_GetLastEvent(I2C1) & 0x00000040) != 0x0000040); /* Poll on RxNE */
- /* Read DataN */
- *pBuffer = I2C1->DR;
- /* Reset the number of bytes to be read by master */
- NumByteToRead = 0;
-
- }
- }
请教下,为什么在禁能了ack后,要先关闭中断,再去读data N-2数据和data N-1数据呢,如果不管中断会造成什么后果,请指教?
|