STM32 I2C 通讯 主模式 官方EVENTS 解释(译自英文注释)

I2C 主模式事件 (按通讯顺序分组 )

1.通讯开始

/** 
  * @brief  Communication start
  * 
  * After sending the START condition (I2C_GenerateSTART() function) the master 
  * has to wait for this event. It means that the Start condition has been correctly 
  * released on the I2C bus (the bus is free, no other devices is communicating).
  * 
  */
/* --EV5 */
#define  I2C_EVENT_MASTER_MODE_SELECT                      ((uint32_t)0x00030001)  /* BUSY, MSL and SB flag */

        发送 通讯启动条件(I2C_GenerateSTART() 函数)后,主设备必须等待此事件(EV5)。 此事件意味着 I2C 总线上的启动条件已正确释放(总线空闲,没有其他设备正在通信)。

2.地址确认

/** 
  * @brief  Address Acknowledge
  * 
  * After checking on EV5 (start condition correctly released on the bus), the 
  * master sends the address of the slave(s) with which it will communicate 
  * (I2C_Send7bitAddress() function, it also determines the direction of the communication: 
  * Master transmitter or Receiver). Then the master has to wait that a slave acknowledges 
  * his address. If an acknowledge is sent on the bus, one of the following events will 
  * be set:
  * 
  *  1) In case of Master Receiver (7-bit addressing): the I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED 
  *     event is set.
  *  
  *  2) In case of Master Transmitter (7-bit addressing): the I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED 
  *     is set
  *  
  *  3) In case of 10-Bit addressing mode, the master (just after generating the START 
  *  and checking on EV5) has to send the header of 10-bit addressing mode (I2C_SendData() 
  *  function). Then master should wait on EV9. It means that the 10-bit addressing 
  *  header has been correctly sent on the bus. Then master should send the second part of 
  *  the 10-bit address (LSB) using the function I2C_Send7bitAddress(). Then master 
  *  should wait for event EV6. 
  *     
  */

/* --EV6 */
#define  I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED        ((uint32_t)0x00070082)  /* BUSY, MSL, ADDR, TXE and TRA flags */
#define  I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED           ((uint32_t)0x00030002)  /* BUSY, MSL and ADDR flags */
/* --EV9 */
#define  I2C_EVENT_MASTER_MODE_ADDRESS10                   ((uint32_t)0x00030008)  /* BUSY, MSL and ADD10 flags */

        检查 EV5(总线上正确释放启动条件)后,主设备发送与其通信的从设备的地址(I2C_Send7bitAddress() 函数,同时确定通信方向:主设备为发送器或接收器 )。 然后主设备必须等待从设备确认他的地址。 如果在总线上发送确认,则将设置以下事件之一:

1) 若为主接收器(7 位寻址):设置 I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED 事件。

2) 若是主发送器(7 位寻址):设置 I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED


3) 在 10 位寻址模式下,主设备(在生成 START 并检查 EV5 后)必须发送 10 位寻址模式的Header(I2C_SendData() 函数), 然后主设备应该等待EV9。 这意味着10位寻址Header已正确发送到总线上。 然后主设备应使用函数 I2C_Send7bitAddress() 发送 10 位地址 (LSB) 的第二部分。 然后主设备应该等待事件EV6。

3.通讯事件

/** 
  * @brief Communication events
  * 
  * If a communication is established (START condition generated and slave address 
  * acknowledged) then the master has to check on one of the following events for 
  * communication procedures:
  *  
  * 1) Master Receiver mode: The master has to wait on the event EV7 then to read 
  *    the data received from the slave (I2C_ReceiveData() function).
  * 
  * 2) Master Transmitter mode: The master has to send data (I2C_SendData() 
  *    function) then to wait on event EV8 or EV8_2.
  *    These two events are similar: 
  *     - EV8 means that the data has been written in the data register and is 
  *       being shifted out.
  *     - EV8_2 means that the data has been physically shifted out and output 
  *       on the bus.
  *     In most cases, using EV8 is sufficient for the application.
  *     Using EV8_2 leads to a slower communication but ensure more reliable test.
  *     EV8_2 is also more suitable than EV8 for testing on the last data transmission 
  *     (before Stop condition generation).
  *     
  *  @note In case the  user software does not guarantee that this event EV7 is 
  *  managed before the current byte end of transfer, then user may check on EV7 
  *  and BTF flag at the same time (ie. (I2C_EVENT_MASTER_BYTE_RECEIVED | I2C_FLAG_BTF)).
  *  In this case the communication may be slower.
  * 
  */

/* Master RECEIVER mode -----------------------------*/ 
/* --EV7 */
#define  I2C_EVENT_MASTER_BYTE_RECEIVED                    ((uint32_t)0x00030040)  /* BUSY, MSL and RXNE flags */

/* Master TRANSMITTER mode --------------------------*/
/* --EV8 */
#define I2C_EVENT_MASTER_BYTE_TRANSMITTING                 ((uint32_t)0x00070080) /* TRA, BUSY, MSL, TXE flags */
/* --EV8_2 */
#define  I2C_EVENT_MASTER_BYTE_TRANSMITTED                 ((uint32_t)0x00070084)  /* TRA, BUSY, MSL, TXE and BTF flags */

       如果建立了通信(已生成起始条件并确认从机地址),则主机必须检查以下通信过程事件之一:
  1) 主接收器模式:主设备必须等待事件 EV7,然后读取从从设备接收到的数据(I2C_ReceiveData() 函数)
  2) 主发送器模式:主设备必须发送数据(I2C_SendData() 函数),然后等待事件 EV8 或 EV8_2。

这两个事件类似:
- EV8 表示数据已写入数据寄存器并正在移出。
- EV8_2 表示数据已移出并输出到总线上。
  在大多数情况下,使用 EV8 足以满足应用程序的需要。 使用 EV8_2 会导致通信速度变慢,但可确保测试更可靠。 EV8_2 也比 EV8 更适合测试最后一次数据传输(在停止条件生成之前)。

注意:如果用户软件不能保证处理(manage,不知道这么翻译对不对)此事件 EV7是在 ⌈当前字节传输结束之前⌋ ,则用户可以同时检查 EV7 和 BTF 标志(即(I2C_EVENT_MASTER_BYTE_RECEIVED | I2C_FLAG_BTF))。 在这种情况下,通信速度可能会变慢。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值