• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ I2C_ClearFlag函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: MPU6050_Read

/* @brief Reads bytes from MPU6050
 *
 * @param SlaveAddr - Slave I2C address
 * @param RegAddr - register address
 * @param pBuffer - buffer to write to
 * @ param NumByteToRead - number of bytes to read
 *
 * @retval @MPU6050_errorstatus
 */
MPU6050_errorstatus MPU6050_Read(uint8_t SlaveAddr, uint8_t RegAddr, uint8_t* pBuffer, uint16_t NumByteToRead)
{

   /* Test if SDA line busy */
   MPU6050_Timeout = MPU6050_LONG_TIMEOUT;
   while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_BUSY) != RESET)
   {
      if((MPU6050_Timeout--) == 0) return MPU6050_I2C_ERROR;
   }

   I2C_TransferHandling(MPU6050_I2C, SlaveAddr, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);

   MPU6050_Timeout = MPU6050_LONG_TIMEOUT;
   while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_TXIS) == RESET)
   {
      if((MPU6050_Timeout--) == 0) return MPU6050_I2C_ERROR;
   }

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

   I2C_SendData(MPU6050_I2C, (uint8_t)RegAddr);

   MPU6050_Timeout = MPU6050_LONG_TIMEOUT;
   while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_TC) == RESET)
   {
      if((MPU6050_Timeout--) == 0) return MPU6050_I2C_TX_ERROR;
   }

    I2C_TransferHandling(MPU6050_I2C, SlaveAddr, NumByteToRead, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);

    while (NumByteToRead)
    {
      MPU6050_Timeout = MPU6050_LONG_TIMEOUT;
      while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_RXNE) == RESET)
      {
         if((MPU6050_Timeout--) == 0) return MPU6050_I2C_RX_ERROR;
      }

      *pBuffer = I2C_ReceiveData(MPU6050_I2C);
      pBuffer++;

      NumByteToRead--;
    }

    MPU6050_Timeout = MPU6050_LONG_TIMEOUT;
    while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_STOPF) == RESET)
    {
      if((MPU6050_Timeout--) == 0) return MPU6050_I2C_ERROR;
    }

    I2C_ClearFlag(MPU6050_I2C, I2C_FLAG_STOPF);

    return MPU6050_NO_ERROR;
}
开发者ID:synergia,项目名称:BalanSyner,代码行数:64,代码来源:_LibMPU6050.c


示例17: LSM303DLHC_Write

/**
 * @brief  Writes one byte to the LSM303DLHC.
 * @param  DeviceAddr : specifies the slave address to be programmed.
 * @param  RegAddr : specifies the LSM303DLHC register to be written.
 * @param  pBuffer : pointer to the buffer  containing the data to be written to the LSM303DLH.
 * @retval LSM303DLHC Status
 */
uint16_t LSM303DLHC_Write(uint8_t DeviceAddr, uint8_t RegAddr, uint8_t* pBuffer) {
	/* Test on BUSY Flag */
	LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
	while (I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_BUSY ) != RESET) {
		if ((LSM303DLHC_Timeout--) == 0)
			return LSM303DLHC_TIMEOUT_UserCallback();
	}

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

	/* Wait until TXIS flag is set */
	LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
	while (I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS ) == RESET) {
		if ((LSM303DLHC_Timeout--) == 0)
			return LSM303DLHC_TIMEOUT_UserCallback();
	}

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

	/* Wait until TCR flag is set */
	LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
	while (I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TCR ) == RESET) {
		if ((LSM303DLHC_Timeout--) == 0)
			return LSM303DLHC_TIMEOUT_UserCallback();
	}

	/* Configure slave address, nbytes, reload, end mode and start or stop generation */
	I2C_TransferHandling(LSM303DLHC_I2C, DeviceAddr, 1, I2C_AutoEnd_Mode,
			I2C_No_StartStop);

	/* Wait until TXIS flag is set */
	LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
	while (I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_TXIS ) == RESET) {
		if ((LSM303DLHC_Timeout--) == 0)
			return LSM303DLHC_TIMEOUT_UserCallback();
	}

	/* Write data to TXDR */
	I2C_SendData(LSM303DLHC_I2C, *pBuffer);

	/* Wait until STOPF flag is set */
	LSM303DLHC_Timeout = LSM303DLHC_LONG_TIMEOUT;
	while (I2C_GetFlagStatus(LSM303DLHC_I2C, I2C_ISR_STOPF ) == RESET) {
		if ((LSM303DLHC_Timeout--) == 0)
			return LSM303DLHC_TIMEOUT_UserCallback();
	}

	/* Clear STOPF flag */
	I2C_ClearFlag(LSM303DLHC_I2C, I2C_ICR_STOPCF );

	return LSM303DLHC_OK ;
}
开发者ID:tbraunP,项目名称:FreeRTOS_STM32F3_Demo,代码行数:62,代码来源:stm32f3_discovery_lsm303dlhc.c


示例18: I2C1_ER_IRQHandler

/*************************************************************************
 * Function Name: I2C1_ErrIntrHandler
 * Parameters: none
 *
 * Return: none
 *
 * Description: I2C1 error interrupt handler
 *
 *************************************************************************/
void I2C1_ER_IRQHandler(void)
{
  if(I2C_EVENT_SLAVE_ACK_FAILURE & I2C_GetLastEvent(I2C1))
  {
    // Generate Stop condition (return back to slave mode)
    I2C_GenerateSTOP(I2C1,ENABLE);
    I2C_ClearFlag(I2C1,I2C_FLAG_AF);
  }
  s_Done = TRUE;
  s_Error = TRUE;
}
开发者ID:ADTL,项目名称:ARMWork,代码行数:20,代码来源:i2c1_drv.c


示例19: AT24Cxx_ack_polling

static void AT24Cxx_ack_polling(struct AT24Cxx_init_struct* init)
{
	/* Until ack fails (I2C_FLAG_AF) continue with the polling */
	do {
		I2C_GenerateSTART(init->I2C_peripheral, ENABLE);
		I2C_Send7bitAddress(init->I2C_peripheral, init->I2C_address, I2C_Direction_Transmitter);
	} while((I2C_GetLastEvent(init->I2C_peripheral) & I2C_FLAG_AF));

	I2C_ClearFlag(init->I2C_peripheral, I2C_FLAG_AF);
	I2C_GenerateSTOP(init->I2C_peripheral, ENABLE);
}
开发者ID:smanni,项目名称:stm32,代码行数:11,代码来源:at24cxx.c


示例20: i2c_write

void i2c_write(uint8_t* pBuffer, uint8_t num) {
	uint8_t i = 0;
	I2C_ITConfig(I2C2, I2C_IT_RXI | I2C_IT_TXI | I2C_IT_ADDRI | I2C_IT_STOPI, DISABLE);
	while(I2C_GetFlagStatus(I2C2, I2C_ISR_BUSY) != RESET);
	I2C_TransferHandling(I2C2, I2C_SLAVE, num, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
	for(; i < num; i++) {
		while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET);
		I2C_SendData(I2C2, (uint8_t) I2C_SLAVE);
	}
	while(I2C_GetFlagStatus(I2C2, I2C_ISR_STOPF) == RESET); 
	I2C_ClearFlag(I2C2, I2C_ICR_STOPCF);
}
开发者ID:korrav,项目名称:analog_stm32f3,代码行数:12,代码来源:main.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ I2C_Cmd函数代码示例发布时间:2022-05-30
下一篇:
C++ I2C_CheckEvent函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap