请教stm32 i2c轮询为什么要在此处关闭中断

[复制链接]
3160|0
 楼主| haov000 发表于 2011-9-24 10:57 | 显示全部楼层 |阅读模式
  1. while (NumByteToRead)   
  2.     {   
  3.    
  4.         if (NumByteToRead != 3) /* Receive bytes from first byte until byte N-3 */   
  5.         {   
  6.             while ((I2C_GetLastEvent(I2C1) & 0x00004) != 0x000004); /* Poll on BTF */   
  7.             /* Read data */   
  8.             *pBuffer = I2C_ReceiveData(I2C1);   
  9.             pBuffer++;   
  10.             /* Decrement the read bytes counter */   
  11.             NumByteToRead--;   
  12.         }   
  13.    
  14.         if (NumByteToRead == 3)  /* it remains to read three data: data N-2, data N-1, Data N */   
  15.         {   
  16.    
  17.             /* Data N-2 in DR and data N -1 in shift register */   
  18.             while ((I2C_GetLastEvent(I2C1) & 0x000004) != 0x0000004); /* Poll on BTF */   
  19.             /* Clear ACK */   
  20.             I2C_AcknowledgeConfig(I2C1, DISABLE);   
  21.             __disable_irq();   
  22.             /* Read Data N-2 */   
  23.             *pBuffer = I2C_ReceiveData(I2C1);   
  24.             pBuffer++;   
  25.             /* Program the STOP */   
  26.             I2C_GenerateSTOP(I2C1, ENABLE);   
  27.             /* Read DataN-1 */   
  28.             *pBuffer = I2C_ReceiveData(I2C1);   
  29.              __enable_irq();   
  30.             pBuffer++;   
  31.             while ((I2C_GetLastEvent(I2C1) & 0x00000040) != 0x0000040); /* Poll on RxNE */   
  32.             /* Read DataN */   
  33.             *pBuffer = I2C1->DR;   
  34.             /* Reset the number of bytes to be read by master */   
  35.             NumByteToRead = 0;   
  36.    
  37.         }   
  38.     }   
请教下,为什么在禁能了ack后,要先关闭中断,再去读data N-2数据和data N-1数据呢,如果不管中断会造成什么后果,请指教?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

6

主题

132

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部