打印

关于STM32 I2C的固件库

[复制链接]
2697|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chinaqiaobo|  楼主 | 2013-5-22 11:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/**
  * [url=home.php?mod=space&uid=247401]@brief[/url]  Transmits the address byte to select the slave device.
  * @param  I2Cx: where x can be 1 or 2 to select the I2C peripheral.
  * @param  Address: specifies the slave address which will be transmitted
  * @param  I2C_Direction: specifies whether the I2C device will be a
  *   Transmitter or a Receiver. This parameter can be one of the following values
  *     @arg I2C_Direction_Transmitter: Transmitter mode
  *     @arg I2C_Direction_Receiver: Receiver mode
  * @retval None.
  */
void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, uint8_t I2C_Direction)
{
  /* Check the parameters */
  assert_param(IS_I2C_ALL_PERIPH(I2Cx));
  assert_param(IS_I2C_DIRECTION(I2C_Direction));
  /* Test on the direction to set/reset the read/write bit */
  if (I2C_Direction != I2C_Direction_Transmitter)
  {
    /* Set the address bit0 for read */
    Address |= OAR1_ADD0_Set;
  }
  else
  {
    /* Reset the address bit0 for write */
    Address &= OAR1_ADD0_Reset;
  }
  /* Send the address */
  I2Cx->DR = Address;
}
以上是STM32 V3.5的固件库中关于I2C的一个函数
函数体前面的注释说:   
I2C_Direction: specifies whether the I2C device will be a
Transmitter or a Receiver. This parameter can be one of the following values

我想请问,这里所说的I2C device 是指stm32单片机,还是我要操作的24C02 (这里用stm32向24C02读写数据为例),  我个人理解应该是指24C02,但是如果这样的话,
假设24C02选择Transmitter(即函数的参数为 I2C_Direction_Transmitter ),意味着stm32应该是Receiver,按照stm32的参考手册,I2C主模式中,
●  在7位地址模式时,
─  要进入发送器模式,主设备发送从地址时置最低位为’0’。
─  要进入接收器模式,主设备发送从地址时置最低位为’1’。

就是说从地址的最低为应该为1,
但是这个库函数却设置成了0

请问是不是我对于I2C device的理解有误呢? 请各位指教! 谢谢!
沙发
chinaqiaobo|  楼主 | 2013-5-22 11:40 | 只看该作者
好吧,我想我自己想明白了
这里所说的I2C device应该是指STM32的I2C 外设
而24C02应该被称作 slave device
正如注释的第一行所说

使用特权

评论回复
板凳
mmuuss586| | 2013-5-22 11:55 | 只看该作者

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3

主题

10

帖子

0

粉丝