HTU21D程序I2C 访问过不去,有做过HTU21的大侠指点下

2019-08-13 21:32发布

调试HTU21D 温湿度传感器I2C总线是 复位HTU21D老是过不去 什么原因请问,我这个I2C总线上挂的时钟芯片已经调试成功
void HTU21_Reset(void)
{
   /*****************************  
e_Error error = NO_ERROR;                    //error variable
U16 i;
vHRD_I2C_Start();
error |= eHRD_I2C_WriteByte (I2C_ADR_W);     // I2C Adr
error |= eHRD_I2C_WriteByte (SOFT_RESET);    // Command
vHRD_I2C_Stop();
for(i=0;i<=12000;i++);
return error;
*****************************/
uint8_t *data;
    uint8_t *num;
*num=1;
data[0]= SOFT_RESET;
   
I2C_WriteBuffer( data, I2C_ADR_W,  SOFT_RESET,num);

    delay_ms(10);
 
}


uint32_t I2C_WriteBuffer(uint8_t *data, uint8_t I2CAddr, uint16_t WriteAddr, uint8_t *NumByteToWrite)
{   
uint32_t I2C_Timeout, data_num = 0;
I2C_Timeout = I2C_LONG_TIMEOUT;
while(I2C_GetFlagStatus(I2C2, I2C_ISR_BUSY) != RESET)
{
if((I2C_Timeout--) == 0) 
{
return I2C_FAIL;
}
}
/* Configure slave address, nbytes, reload and generate start */
I2C_TransferHandling(I2C2, I2CAddr, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);

/* Wait until TXIS flag is set */
I2C_Timeout = I2C_LONG_TIMEOUT;  
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET)
{
if((I2C_Timeout--) == 0) 
{
return I2C_FAIL;
}
}

/* Send memory address */
I2C_SendData(I2C2, (uint8_t)WriteAddr);

/* Wait until TCR flag is set */
I2C_Timeout = I2C_LONG_TIMEOUT;
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TCR) == RESET)
{
if((I2C_Timeout--) == 0) 
{
return I2C_FAIL;
}
}

I2C_TransferHandling(I2C2, I2CAddr, *NumByteToWrite, I2C_AutoEnd_Mode, I2C_No_StartStop);

while (data_num != (*NumByteToWrite))
{      
I2C_Timeout = I2C_LONG_TIMEOUT;  
while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET)
{
if((I2C_Timeout--) == 0) 
{
return I2C_FAIL;
}
}

/* Write data to TXDR */
I2C_SendData(I2C2, data[data_num]);

/* Update number of transmitted data */
data_num++;   
}  
/* Wait until TXIS flag is set */
I2C_Timeout = I2C_LONG_TIMEOUT;
while(I2C_GetFlagStatus(I2C2, I2C_ISR_STOPF) == RESET)
{
if((I2C_Timeout--) == 0) 
{
return I2C_FAIL;
}
}  

/* Clear STOPF flag */
I2C_ClearFlag(I2C2, I2C_ISR_STOPF);

/* If all operations OK, return sEE_OK (0) */
return I2C_OK;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。