コード例 #1
0
/**
  * @brief  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
  {
    // [ILG]
    #if defined ( __GNUC__ )
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wconversion"
    #endif
    /* Reset the address bit0 for write */
    Address &= OAR1_ADD0_Reset;
    // [ILG]
    #if defined ( __GNUC__ )
    #pragma GCC diagnostic pop
    #endif
  }
  /* Send the address */
  I2Cx->DR = Address;
}
コード例 #2
0
ファイル: MDR32F9Qx_i2c.c プロジェクト: bora14/armdiv
/**
  * @brief  Transmits the address byte to select the Slave device.
  * @param  Address: specifies the Slave address which will be transmitted.
  *         The Address[0] bit value is ignored. So only Address[7..1] bits
  *         are the seven-bit Slave address.
  * @param  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(uint8_t Address, uint32_t Direction)
{
  MDR_I2C_TypeDef *I2Cx;

  assert_param(IS_I2C_DIRECTION(Direction));

  I2Cx = MDR_I2C;

  I2Cx->TXD = (Address & ~I2C_Direction_Msk) | Direction;
  I2Cx->CMD = I2C_CMD_START | I2C_CMD_WR;
}
コード例 #3
0
/**
  * @brief  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;
}