当前位置: 首页>>代码示例>>C++>>正文


C++ I2C_ClearFlag函数代码示例

本文整理汇总了C++中I2C_ClearFlag函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_ClearFlag函数的具体用法?C++ I2C_ClearFlag怎么用?C++ I2C_ClearFlag使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了I2C_ClearFlag函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: f3d_i2c1_read_nunchuk

// Make this so we can handle if the nunchuk is disconnected
void f3d_i2c1_read_nunchuk (uint8_t device, uint8_t* buffer, uint16_t numbytes) {

tryagain: ;

  int count = 100;

  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET){
  }
  I2C_TransferHandling(I2C1, 0xA4, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);          
  // This is where were screwing up
  while ((I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET) && count){
    asm("nop");
    count--;
  }
  
  if (count <= 0) {
    goto tryagain;
  }

  I2C_SendData(I2C1,0x00);                                                                  
  while(I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET){
  }
  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
  delay(1);
  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET) {
  }
  I2C_TransferHandling(I2C1, 0xA4, 6, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  while (numbytes--) {
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_RXNE) == RESET);
    *buffer++ = I2C_ReceiveData(I2C1);
  }
  while (I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET);                                  
  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
}
开发者ID:tzakian,项目名称:STM-32-asteroids,代码行数:35,代码来源:f3d_i2c.c

示例2: I2C_AcknowledgePolling

/*TODO: If your device need more time to initialize I2C bus or waiting memory write, you can use I2C_AcknowledgePolling avoid I2C bus lose.*/
Status I2C_AcknowledgePolling(I2C_TypeDef* I2Cx ,uint8_t Addr)
{
    uint32_t timeout = 0xFFFF, ret;
    uint16_t tmp;
	ret = rt_mutex_take(i2c_mux, RT_WAITING_FOREVER );
	
	if( ret == RT_EOK )
	{
	    do{
	        if( timeout-- <= 0 )
	        {
	            I2C_ClearFlag(I2Cx,I2C_FLAG_AF);
	            I2Cx->CR1 |= CR1_STOP_Set;
				rt_mutex_release(i2c_mux);
	            return Error;
	        }
	
	        I2Cx->CR1 |= CR1_START_Set;
	        tmp = I2Cx->SR1;//²M°£SB¦ì
	        I2Cx->DR = Addr;
	        
	    }while((I2Cx->SR1&0x0002) != 0x0002);
	  
	    I2C_ClearFlag(I2Cx,I2C_FLAG_AF);
	    I2Cx->CR1 |= CR1_STOP_Set;
	    while ((I2Cx->CR1&0x200) == 0x200);
		rt_kprintf( "AcknowledgePolling OK\n");
		rt_mutex_release(i2c_mux);
		return Success; 
	}
	else
		return Error;
} 
开发者ID:bright-pan,项目名称:smart-lock,代码行数:34,代码来源:i2c.c

示例3: I2C2_ER_IRQHandler

/**  
  * @brief  This function handles I2C2 Error interrupt request.  
  * @param  None  
  * @retval : None  
  */   
void I2C2_ER_IRQHandler(void)   
   
{   
   
    if (I2C_GetFlagStatus(I2C2, I2C_FLAG_AF))   
    {   
        I2C_ClearFlag(I2C2, I2C_FLAG_AF);   
    }   
   
    if (I2C_GetFlagStatus(I2C2, I2C_FLAG_BERR))   
    {   
        I2C_ClearFlag(I2C2, I2C_FLAG_BERR);   
   
    }   
    if (I2C_GetFlagStatus(I2C2, I2C_FLAG_OVR))   
    {   
        I2C_ClearFlag(I2C2, I2C_FLAG_OVR);   
   
    }   
   
    if (I2C_GetFlagStatus(I2C2, I2C_FLAG_ARLO))   
    {   
        I2C_ClearFlag(I2C2,I2C_FLAG_ARLO);   
   
    }   
   
   
   
   
}   
开发者ID:emmamuelo,项目名称:IPM,代码行数:35,代码来源:stm32f10x_it.c

示例4: I2C_CheckReceive

void I2C_CheckReceive()
{
	if (I2C_GetFlagStatus(I2C, I2C_FLAG_ADDR))
	{
		uprintf("\r\nAddress matched!\r\n");
		I2C_ClearFlag(I2C, I2C_FLAG_ADDR);
	}

	/* Receive byte */
	if (I2C_GetFlagStatus(I2C, I2C_FLAG_RXNE))
	{
		uprintf("Packet received!\r\n");

		I2C_RX_Packets[I2C_RX_Index] = I2C_ReceiveData(I2C);
		if (I2C_RX_Index < I2C_RX_PACKET_BUFFER_LENGTH-1) 
		{
			I2C_RX_Index++;
		}
		I2C_ClearFlag(I2C, I2C_FLAG_RXNE);
	}

	/* Process command */
	if (I2C_GetFlagStatus(I2C, I2C_FLAG_STOPF))
	{
		uprintf("Stop! received!\r\n");
		I2C_ClearFlag(I2C, I2C_FLAG_STOPF);
		I2C_ProcessCommand(I2C_RX_Packets, I2C_RX_Index+1);
		I2C_RX_Index = 0;
	}
}
开发者ID:scottlawsonbc,项目名称:FilamentDiameterSensor,代码行数:30,代码来源:i2c.c

示例5: LM75_GetStatus

/**
  * @brief  Checks the LM75 status.
  * @param  None
  * @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
  */
ErrorStatus LM75_GetStatus(void)
{
  uint32_t I2C_TimeOut = I2C_TIMEOUT;
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 0, I2C_AutoEnd_Mode, I2C_No_StartStop);
  
  /* Clear NACKF and STOPF */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
  
  /* Generate start */
  I2C_GenerateSTART(LM75_I2C, ENABLE);  
  
  /* Wait until timeout elapsed */
  while ((I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET) && (I2C_TimeOut-- != 0)); 
  
  /* Check if Temp sensor is ready for use */
  if ((I2C_GetFlagStatus(LM75_I2C, I2C_ISR_NACKF) != RESET) || (I2C_TimeOut == 0))
  {      
    /* Clear NACKF and STOPF */
    I2C_ClearFlag(LM75_I2C, I2C_ICR_NACKCF | I2C_ICR_STOPCF);
    
    return ERROR;
  }
  else
  {
    /* Clear STOPF */
    I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
    
    return SUCCESS;
  }    
}
开发者ID:Azizou,项目名称:stm32f0_devel,代码行数:37,代码来源:stm320518_eval_i2c_tsensor.c

示例6: sEE_WaitEepromStandbyState

/**
  * @brief  Wait for EEPROM Standby state
  * @param  None
  * @retval None
  */
void sEE_WaitEepromStandbyState(void)
{
    __IO uint8_t tempreg = 0;
    __IO uint32_t timeout = 0xFFFF;

    do
    {
        /*!< Send START condition */
        I2C_GenerateSTART(sEE_I2C, ENABLE);

        /* Test on EEPROM_I2C EV5 and clear it */
        while (!I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_SB))  /* EV5 */
        {
        }

        /*!< Send EEPROM address for write */
        I2C_Send7bitAddress(sEE_I2C, (uint8_t)sEEAddress, I2C_Direction_Transmitter);

        /*!< Wait for address aknowledgement */
        for (; timeout > 0; timeout--);

        /*!< Read sEE SR1 register to clear pending flags */
        tempreg = I2C_ReadRegister(sEE_I2C, I2C_Register_SR1);

    }
    while (!(tempreg & 0x02));

    /*!< Clear AF flag */
    I2C_ClearFlag(sEE_I2C, I2C_FLAG_AF);

    /*!< STOP condition */
    I2C_GenerateSTOP(sEE_I2C, ENABLE);
}
开发者ID:glockwork,项目名称:ev-stm8l151k6-emotor,代码行数:38,代码来源:stm8_eval_i2c_ee.c

示例7: I2C_Conf

/**
  * @brief  Configures a device connected to I2C
  * @param  Pointer to the config string, number of bytes to write
  * @retval I2C success/error code
  */
I2C_Returntype I2C_Conf(uint8_t* Confstr,uint8_t Bytes) {			//Sets up an i2c device
	uint8_t n;
	uint16_t Time=0;
	I2C_GenerateSTART( I2C1, ENABLE );
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) {
		Time++;
		if(Time>I2C_TIMEOUT) return I2C_START_TIMEOUT;
	}
	Time=0;
	I2C_Send7bitAddress( I2C1, Confstr[0], I2C_Direction_Transmitter );	//Address write
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) {
		Time++;
		if(Time>I2C_TIMEOUT) return I2C_SACK_TIMEOUT;
		if(SET==I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)) {
			I2C_ClearFlag(I2C1, I2C_FLAG_AF);
			I2C_GenerateSTOP( I2C1, ENABLE );			//Enable the STOP here - so hardware is ready again
			return I2C_SACK_FAILURE;				//Slave did not ack
		}
	}
	for(n=1;n<Bytes;n++) {
		Time=0;
		I2C_SendData( I2C1, Confstr[n] );				//Write rest of string (registers)
		while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) {
			Time++;
			if(Time>I2C_TIMEOUT) return I2C_TX_TIMEOUT;
		}
	}
	I2C_GenerateSTOP( I2C1, ENABLE );					//Finally send the stop bit
	return I2C_SUCCESS;							//Completed ok
}
开发者ID:Laurenceb,项目名称:Dactyl,代码行数:35,代码来源:i2c.c

示例8: TW88Write

uint8_t TW88Write(uint8_t regAddr, uint8_t data)
{
		int8_t retries;
		retries=3;
	
		while(I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET) { if ((retries--)>0) Delay(1); else return 0;}
	
		//I2C_TransferHandling(I2C1, TW88_I2C_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
		/* Configure slave address, nbytes, reload, end mode and start or stop generation */
		I2C_TransferHandling(I2C1, TW88_I2C_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
		retries=3;
		while(I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET) {if ((retries--)>0) Delay(1); else return 0; }
		//send the register address	
		I2C_SendData(I2C1, (uint8_t) regAddr);
		
		retries=3;
		while(I2C_GetFlagStatus(I2C1, I2C_ISR_TCR) == RESET){if ((retries--)>0) Delay(1); else return 0;}

		
		/* Configure slave address, nbytes, reload, end mode and start or stop generation */
		I2C_TransferHandling(I2C1, TW88_I2C_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);		
		retries=3;
		while(I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET) {if ((retries--)>0) Delay(1); else return 0;}
		
		I2C_SendData(I2C1, data);
		
		retries=3;
		while(I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET) {if ((retries--)>0) Delay(1); else return 0;}
		
		I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);	
			
		
		return 1;
}
开发者ID:Si4463Project,项目名称:ControllerBoard,代码行数:34,代码来源:tw88.c

示例9: i2c_transmit

/*******************************************************************************
* Function Name  : i2c_transmit
* Description    : Transmit byte(s)
* Input          : - Addr: Slave address
*                : - Ptr: Pointer to the first byte to be transmitted
*                : - Size: Number of bytes to transmit
*                : - Stop: Indicate if a STOP condition is to be generated
* Output         : None
* Return         : -1 if an error occurred
*******************************************************************************/
int i2c_transmit(u8 Addr, const char *Ptr, u16 Size, u8 Stop)
{
  int ret = 0;

  I2C_GenerateSTART(I2C1, ENABLE);
  while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
  I2C_Send7bitAddress(I2C1,Addr, I2C_Direction_Transmitter);
  while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_ADDR) && !I2C_GetFlagStatus(I2C1, I2C_FLAG_AF));
  if (I2C_GetFlagStatus(I2C1, I2C_FLAG_AF))
  {
    I2C_ClearFlag(I2C1, I2C_FLAG_AF);
    ret = -1;
  }
  else if (Size)
  {
    while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
    while (Size--)
    {
      while (!I2C_GetFlagStatus(I2C1, I2C_FLAG_TXE));
      I2C_SendData(I2C1, *Ptr++);
    }
    while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  }
  if (Stop || (ret == -1))
  {
    I2C_GenerateSTOP(I2C1, ENABLE);
    while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
  }
  return(ret);
}
开发者ID:lepton-distribution,项目名称:lepton,代码行数:40,代码来源:i2c.c

示例10: u8g_i2c_stop

void u8g_i2c_stop(void)
{
   //Wait for the stop flag to be set indicating a stop condition has been sent
	while(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF) == RESET);

	//Clear the stop flag for the next potential transfer
	I2C_ClearFlag(I2C1, I2C_FLAG_STOPF); 
}
开发者ID:peterfillmore,项目名称:RuxconBadge2015,代码行数:8,代码来源:u8g_arm.c

示例11: LM75_WriteConfReg

/**
  * @brief  Write to the configuration register of the LM75.
  * @param  RegValue: specifies the value to be written to LM75 configuration 
  *         register.
  * @retval None
  */
uint8_t LM75_WriteConfReg(uint8_t RegValue)
{   
  uint8_t LM75_BufferTX = 0;  
  
  LM75_BufferTX = (uint8_t)(RegValue);
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET) 
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TCR flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TCR) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Write data to TXDR */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_BufferTX);
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }   
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
    
  return LM75_OK;  
}
开发者ID:Azizou,项目名称:stm32f0_devel,代码行数:64,代码来源:stm320518_eval_i2c_tsensor.c

示例12: LM75_ReadConfReg

/**
  * @brief  Read the configuration register from the LM75.
  * @param  None
  * @retval LM75 configuration register value.
  */
uint8_t LM75_ReadConfReg(void)
{   
  uint8_t LM75_BufferRX[2] ={0,0}; 
  
  /* Test on BUSY Flag */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_BUSY) != RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
  
  /* Wait until TXIS flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TXIS) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send Register address */
  I2C_SendData(LM75_I2C, (uint8_t)LM75_REG_CONF);
  
  /* Wait until TC flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_TC) == RESET)
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(LM75_I2C, LM75_ADDR, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  
  /* Wait until RXNE flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;  
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_RXNE) == RESET)  
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Read data from RXDR */
  LM75_BufferRX[0]= I2C_ReceiveData(LM75_I2C);  
  
  /* Wait until STOPF flag is set */
  LM75Timeout = LM75_LONG_TIMEOUT;
  while(I2C_GetFlagStatus(LM75_I2C, I2C_ISR_STOPF) == RESET) 
  {
    if((LM75Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Clear STOPF flag */
  I2C_ClearFlag(LM75_I2C, I2C_ICR_STOPCF);
  
  /* Return Register value */
  return (uint8_t)LM75_BufferRX[0];
}
开发者ID:Azizou,项目名称:stm32f0_devel,代码行数:62,代码来源:stm320518_eval_i2c_tsensor.c

示例13: f3d_i2c1_read_nunchuk

void f3d_i2c1_read_nunchuk (uint8_t device, uint8_t* buffer, uint16_t numbytes) {

  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET);
  I2C_TransferHandling(I2C1, 0xA4, 1, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
  while (I2C_GetFlagStatus(I2C1, I2C_ISR_TXIS) == RESET);
  I2C_SendData(I2C1,0x00);
  while(I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET);
  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
  delay(1);
  while (I2C_GetFlagStatus(I2C1, I2C_ISR_BUSY) != RESET);
  I2C_TransferHandling(I2C1, 0xA4, 6, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
  while (numbytes--) {
    while(I2C_GetFlagStatus(I2C1, I2C_ISR_RXNE) == RESET);
    *buffer++ = I2C_ReceiveData(I2C1);
  }
  while (I2C_GetFlagStatus(I2C1, I2C_ISR_STOPF) == RESET);
  I2C_ClearFlag(I2C1, I2C_ICR_STOPCF);
}
开发者ID:gaoyuu,项目名称:III_III_V_CS,代码行数:18,代码来源:f3d_i2c.c

示例14: i2c_hand

void i2c_hand(void) {
	if(I2C_GetITStatus(I2C2, I2C_IT_ADDR) == SET) {
		handl_i2c_message();
		I2C_ClearFlag(I2C2, I2C_FLAG_ADDR);
		stat.is_tran = I2C_GetTransferDirection(I2C2);
		stat.numr = 0;
	}
	if(I2C_GetITStatus(I2C2, I2C_IT_STOPF) == SET) {
		handl_i2c_message();
		cTran++;
		I2C_ClearFlag(I2C2, I2C_FLAG_STOPF);
		stat.numr = 0;
	}
	if(I2C_GetITStatus(I2C2, I2C_IT_RXNE) == SET) {
		if(stat.numr < I2C_BUF_SIZE)
			stat.bufr[stat.numr++] = I2C_ReceiveData(I2C2);
	}
	return;
}
开发者ID:korrav,项目名称:analog_stm32f3,代码行数:19,代码来源:main.c

示例15: ADXL345_Read

void ADXL345_Read(uint8_t DeviceAddr, uint8_t RegAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
{
  /* Test on BUSY Flag */
  while(I2C_GetFlagStatus(ADXL345_I2C, I2C_ISR_BUSY) != RESET)
  {
  }

  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(ADXL345_I2C, DeviceAddr, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);

  /* Wait until TXIS flag is set */
  while(I2C_GetFlagStatus(ADXL345_I2C, I2C_ISR_TXIS) == RESET)
  {
  }

  if(NumByteToRead>1)
      RegAddr |= 0x80;


  /* Send Register address */
  I2C_SendData(ADXL345_I2C, (uint8_t)RegAddr);

  /* Wait until TC flag is set */
  while(I2C_GetFlagStatus(ADXL345_I2C, I2C_ISR_TC) == RESET)
  {
  }

  /* Configure slave address, nbytes, reload, end mode and start or stop generation */
  I2C_TransferHandling(ADXL345_I2C, DeviceAddr, NumByteToRead, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);

  /* Wait until all data are received */
  while (NumByteToRead)
  {
    /* Wait until RXNE flag is set */
    while(I2C_GetFlagStatus(ADXL345_I2C, I2C_ISR_RXNE) == RESET)
    {
    }

    /* Read data from RXDR */
    *pBuffer = I2C_ReceiveData(ADXL345_I2C);
    /* Point to the next location where the byte read will be saved */
    pBuffer++;

    /* Decrement the read bytes counter */
    NumByteToRead--;
  }

  /* Wait until STOPF flag is set */
  while(I2C_GetFlagStatus(ADXL345_I2C, I2C_ISR_STOPF) == RESET)
  {
  }

  /* Clear STOPF flag */
  I2C_ClearFlag(ADXL345_I2C, I2C_ICR_STOPCF);
}
开发者ID:AndreasHFA,项目名称:fh-vertibot,代码行数:55,代码来源:ADXL345_Lib.c


注:本文中的I2C_ClearFlag函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。