AnsweredAssumed Answered

I2C Questions on STM32F427

Question asked by Chen.Pohua on Nov 25, 2016
Latest reply on Nov 28, 2016 by Chen.Pohua
I have a slave device which is address 0x78 for write and address 0x79 for read.
I want to confirm that why the below I2C transaction is difference?

I want to reset the slave device and the mapping register information as the below shown.
Reset register (R/W)
register address:0x3008
register default value:0x02

1.The return data=0x00 is success when the address doesn't shift left 1bit
#define OV5642_DEVICE_WRITE_ADDRESS 0x78
address%20non%20shift.png

2.The return data=0xFF is failure when the address doesn't shift left 1bit
#define OV5642_DEVICE_WRITE_ADDRESS 0x78<<1
shift.png

Subroutine
void OV5642_Reset(void)
{
  OV5642_WriteReg(SC_SYS_0, 0x80);
}


uint8_t OV5642_WriteReg(uint16_t Addr, uint8_t Data)
{
  uint32_t timeout = DCMI_TIMEOUT_MAX;
  
  /* Generate the Start Condition */
  I2C_GenerateSTART(I2C1, ENABLE);


  /* Test on I2C1 EV5 and clear it */
  timeout = DCMI_TIMEOUT_MAX; /* Initialize timeout value */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT))
  {
    /* If the timeout delay is exceeded, exit with error code */
    if ((timeout--) == 0) return 0xFF;
  }
   
  /* Send DCMI selected device slave Address for write */
  I2C_Send7bitAddress(I2C1, OV5642_DEVICE_WRITE_ADDRESS, I2C_Direction_Transmitter);
 
  /* Test on I2C1 EV6 and clear it */
  timeout = DCMI_TIMEOUT_MAX; /* Initialize timeout value */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
  {
    /* If the timeout delay is exceeded, exit with error code */
    if ((timeout--) == 0) return 0xFF;
  }
 
  /* Send I2C1 location address LSB */
  I2C_SendData(I2C1, (uint8_t)(Addr>>8));
     I2C_SendData(I2C1, (uint8_t)(Addr));




  /* Test on I2C1 EV8 and clear it */
  timeout = DCMI_TIMEOUT_MAX; /* Initialize timeout value */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
  {
    /* If the timeout delay is exceeded, exit with error code */
    if ((timeout--) == 0) return 0xFF;
  }
  
  /* Send Data */
  I2C_SendData(I2C1, Data);


  /* Test on I2C1 EV8 and clear it */
  timeout = DCMI_TIMEOUT_MAX; /* Initialize timeout value */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
  {
    /* If the timeout delay is exceeded, exit with error code */
    if ((timeout--) == 0) return 0xFF;
  }  
 
  /* Send I2C1 STOP Condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
  
  /* If operation is OK, return 0 */
  return 0;
}

Outcomes