Question
I2C Questions on STM32F427
Posted on November 25, 2016 at 09:35
2.The return data=0xFF is failure when the address doesn't shift left 1bit#define OV5642_DEVICE_WRITE_ADDRESS 0x78<<1
Subroutinevoid 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;}
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:0x3008register default value:0x021.The return data=0x00 is success when the address doesn't shift left 1bit#define OV5642_DEVICE_WRITE_ADDRESS 0x78
2.The return data=0xFF is failure when the address doesn't shift left 1bit#define OV5642_DEVICE_WRITE_ADDRESS 0x78<<1
Subroutinevoid 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;}