在启动 I²C 通信时,状态寄存器 SR1 立即复位

问题描述

用下面的代码来握手一个EEPROM

 STM_enableRCCAPB1PeriphClock( RCC_APB1Periph_I2C1,ENABLE );
 STM_resetRCCAPB1PeriphCmd( RCC_APB1Periph_I2C1,disABLE );
 I2C_Cmd( m_pEE_I2C_TYPE,ENABLE );
 I2C_ITConfig( m_pEE_I2C_TYPE,I2C_IT_ERR,ENABLE );
 I2C_InitStructure.I2C_Mode        = EE_I2C_MODE;
 I2C_InitStructure.I2C_DutyCycle      = EE_I2C_DUTY_CYCLE;
 I2C_InitStructure.I2C_OwnAddress1     = EE_I2C_OWN_ADDRESS;
 I2C_InitStructure.I2C_Ack         = EE_I2C_ACK;
 I2C_InitStructure.I2C_AckNowledgedAddress = EE_I2C_ACK_ADDR;
 I2C_InitStructure.I2C_ClockSpeed     = EE_I2C_CLOCK_SPEED;
 GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_6 BITOR GPIO_Pin_7;
 GPIO_InitStructure.GPIO_Speed  = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AF_OD;


  /* Generate the START condition */
  I2C1->CR1 |= I2C_CR1_START;

  /* wait until START condition is set */
  while ( NOT ( I2C1->SR1  BITAND  I2C_SR1_SB ) )
  {
  }

  /* send the address of the EEPROM with r/w-bit reset */
  address = EE_EXT_ADDRESS;
  address |= 1u; // read / receiver
  I2C1->DR = address;

  /* wait for either ADDR (ACK) oder AF (NACK) to be set */
  u16StatusRegister = 0x00u;
  while ( NOT ( ( u16StatusRegister  BITAND  I2C_SR1_ADDR )  BITOR  ( 
u16StatusRegister  BITAND  I2C_SR1_AF ) ) )
  {
    u16StatusRegister = I2C1->SR1;
  }

我在执行后在调试器的寄存器视图中看到 AF 或 ADDR 的上升 I2C1->DR = 地址,但是一旦我执行 u16StatusRegister = 0x00u,SR1 中的所有位都将复位。

有人能猜到为什么会这样吗?

我在 STM32f103 上使用 IAR Workbench 7.50 和 IAR I-jets 调试器,并且没有编码中断例程。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)