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


C++ I2C_TransferHandling函数代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: I2C_Write

uint16_t I2C_Write(uint8_t deviceAddressess, uint8_t registerAddress, uint8_t* dataPointer)
{
	I2C_Timeout = I2C_LONG_TIMEOUT;
	while(I2C_GetFlagStatus(I2C, I2C_ISR_BUSY) != RESET)
	{
		if((I2C_Timeout--) == 0) return I2C_TIMEOUT_UserCallback();
	}

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

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

	/* Send Register address */
	I2C_SendData(I2C, (uint8_t) registerAddress);

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

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

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

	/* Write data to TXDR */
	I2C_SendData(I2C, *dataPointer);

	/* Wait until STOPF flag is set */
	I2C_Timeout = I2C_LONG_TIMEOUT;
	while(I2C_GetFlagStatus(I2C, I2C_ISR_STOPF) == RESET)
	{
		if((I2C_Timeout--) == 0) return I2C_TIMEOUT_UserCallback();
	}   

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

	return I2C_OK;
}
开发者ID:scottlawsonbc,项目名称:FilamentDiameterSensor,代码行数:53,代码来源:i2c.c

示例9: I2C_WriteRegister

void I2C_WriteRegister(uint8_t addr, uint8_t reg, uint8_t val)
{
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY) == SET);
    I2C_TransferHandling(I2C2, addr, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_TXIS) == RESET);
    I2C_SendData(I2C2, reg);
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_TCR) == RESET);
    I2C_TransferHandling(I2C2, addr, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_TXIS) == RESET);
    I2C_SendData(I2C2, val);
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF) == RESET);
    I2C_ClearFlag(I2C2, I2C_FLAG_STOPF);
}
开发者ID:carpman,项目名称:OSHWatch,代码行数:13,代码来源:hal.c

示例10: EEP_WriteData

/* Private functions ---------------------------------------------------------*/
int EEP_WriteData(uint8_t DevAddr, uint16_t RegAddr, uint8_t* DataBuf, uint16_t DataLen)
{
	EEP_Timeout = EEP_LONG_TIMEOUT;
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_BUSY))
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_TransferHandling(I2C2,DevAddr,2,I2C_Reload_Mode,I2C_Generate_Start_Write);
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_TXIS) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_SendData(I2C2,RegAddr>>8);
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_TXIS) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}		
	
	I2C_SendData(I2C2,RegAddr&0xFF);
	while(I2C_GetFlagStatus(I2C2,I2C_ISR_TCR) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_TransferHandling(I2C2,DevAddr,DataLen,I2C_AutoEnd_Mode,I2C_No_StartStop);
	while(DataLen--)
	{
		while(I2C_GetFlagStatus(I2C2,I2C_FLAG_TXIS) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
		I2C_SendData(I2C2, *DataBuf);
		DataBuf++;
	}
	
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_STOPF) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	I2C_ClearFlag(I2C2, I2C_ICR_STOPCF);
	return SUCCESS;
}
开发者ID:nightseas,项目名称:tiny_arms,代码行数:51,代码来源:at24c128.c

示例11: millis

//
//	Originally, 'endTransmission' was an f(void) function.
//	It has been modified to take one parameter indicating
//	whether or not a STOP should be performed on the bus.
//	Calling endTransmission(false) allows a sketch to
//	perform a repeated start.
//
//	WARNING: Nothing in the library keeps track of whether
//	the bus tenure has been properly ended with a STOP. It
//	is very possible to leave the bus in a hung state if
//	no call to endTransmission(true) is made. Some I2C
//	devices will behave oddly if they do not see a STOP.
//
uint8_t TwoWire::endTransmission(uint8_t sendStop) {
	uint32_t _millis;
	
	_millis = millis();
	while(I2C_GetFlagStatus(twi, I2C_FLAG_BUSY) != RESET)
	{
		if(EVENT_TIMEOUT < (millis() - _millis)) return 0;
	}
	if (sendStop == true)
	{
		I2C_TransferHandling(twi, txAddress, txBufferLength, I2C_AutoEnd_Mode, I2C_Generate_Start_Write);
	} 
	else 
	{
		I2C_TransferHandling(twi, txAddress, txBufferLength, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
	}	
	uint8_t *pBuffer = txBuffer;
	uint8_t NumByteToWrite = txBufferLength;
	/* While there is data to be read */
	while(NumByteToWrite--)
	{
		_millis = millis();
		while(I2C_GetFlagStatus(twi, I2C_FLAG_TXIS) == RESET)
		{
			if(EVENT_TIMEOUT < (millis() - _millis)) return 0;
		}
		/* Send the current byte to slave */
		I2C_SendData(twi, *pBuffer++);	
	}
	_millis = millis();
	if (sendStop == true)
	{
		while(I2C_GetFlagStatus(twi, I2C_FLAG_STOPF) == RESET)
		{
			if(EVENT_TIMEOUT < (millis() - _millis)) return 0;
		}
	}
	else
	{
		while(I2C_GetFlagStatus(twi, I2C_FLAG_STOPF) == RESET)
		{
			if(EVENT_TIMEOUT < (millis() - _millis)) return 0;
		}	
	}
	// reset tx buffer iterator vars
	txBufferLength = 0;

	status = MASTER_IDLE;
	return 0;
}
开发者ID:BestU,项目名称:STM32_for_Arduino_BSP,代码行数:63,代码来源:Wire.cpp

示例12: EEP_ReadData

int EEP_ReadData(uint8_t DevAddr, uint16_t RegAddr, uint8_t* DataBuf, uint16_t DataLen)
{ 
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_BUSY))
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_TransferHandling(I2C2,DevAddr,2,I2C_SoftEnd_Mode,I2C_Generate_Start_Write);
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_TXIS) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_SendData(I2C2,RegAddr>>8);
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_TXIS) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_SendData(I2C2,RegAddr&0xFF);
	while(I2C_GetFlagStatus(I2C2,I2C_ISR_TC) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}	
	
	I2C_TransferHandling(I2C2,DevAddr,DataLen,I2C_AutoEnd_Mode,I2C_Generate_Start_Read);
	while(DataLen)
	{
		while(I2C_GetFlagStatus(I2C2,I2C_FLAG_RXNE) == RESET)
		{
			if(EEP_Timeout-- == 0)
				return ERROR;
		}	
		*DataBuf = I2C_ReceiveData(I2C2);
		DataBuf++;
		DataLen--;
	}
	while(I2C_GetFlagStatus(I2C2,I2C_FLAG_STOPF) == RESET)
	{
		if(EEP_Timeout-- == 0)
			return ERROR;
	}
	return SUCCESS;
}
开发者ID:nightseas,项目名称:tiny_arms,代码行数:48,代码来源:at24c128.c

示例13: I2C_RdReg

//We're really fortunate with the HMC5883L as it automatically
//increments the internal register counter with every read
//so we need to set the internal register pointer to the first data
//register (the X value register) and just read the next 6 pieces
//of data, X1, X2, Z1, Z2 Y1, Y2 and
//voila! We have the compass values!
uint8_t I2C_RdReg(int8_t Reg, int8_t *Data, uint8_t DCnt){
	int8_t Cnt, SingleData = 0;

	//As per, ensure the I2C peripheral isn't busy!
	while(I2C_GetFlagStatus(HMC_I2C, I2C_FLAG_BUSY) == SET);

	//Again, start another tranfer using the "transfer handling"
	//function, the end bit being set in software this time
	//round, generate a start condition and indicate you will
	//be writing data to the HMC device.
	I2C_TransferHandling(HMC_I2C, HMCAddr, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);

	//Wait until the transmit interrupt status is set
	while(I2C_GetFlagStatus(HMC_I2C, I2C_FLAG_TXIS) == RESET);

	//Send the address of the register you wish to read
	I2C_SendData(HMC_I2C, (uint8_t)Reg);

	//Wait until transfer is complete!
	while(I2C_GetFlagStatus(HMC_I2C, I2C_FLAG_TC) == RESET);

	//As per, start another transfer, we want to read DCnt
	//amount of bytes. Generate a start condition and
	//indicate that we want to read.
	I2C_TransferHandling(HMC_I2C, HMCAddr, DCnt, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);

	//Read in DCnt pieces of data
	for(Cnt = 0; Cnt<DCnt; Cnt++){
		//Wait until the RX register is full of luscious data!
		while(I2C_GetFlagStatus(HMC_I2C, I2C_FLAG_RXNE) == RESET);

		//If we're only reading one byte, place that data direct into the
		//SingleData variable. If we're reading more than 1 piece of data
		//store in the array "Data" (a pointer from main)
		if(DCnt > 1) Data[Cnt] = I2C_ReceiveData(HMC_I2C);
		else SingleData = I2C_ReceiveData(HMC_I2C);
	}

	//Wait for the stop condition to be sent
	while(I2C_GetFlagStatus(HMC_I2C, I2C_FLAG_STOPF) == RESET);

	//Clear the stop flag for next transfers
	I2C_ClearFlag(HMC_I2C, I2C_FLAG_STOPF);

	//Return a single piece of data if DCnt was
	//less than 1, otherwise 0 will be returned.
	return SingleData;
}
开发者ID:pyrohaz,项目名称:STM32F0-HMC5883_Barebones,代码行数:54,代码来源:main.c

示例14: 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

示例15: i2c_write

int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
    I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
    int timeout;
    int count;

    if (length == 0) return 0;

    // Configure slave address, nbytes, reload, end mode and start generation
    I2C_TransferHandling(i2c, address, length, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);

    // Write all bytes
    for (count = 0; count < length; count++) {
        i2c_byte_write(obj, data[count]);
    }

    timeout = FLAG_TIMEOUT;
    while(!I2C_GetFlagStatus(i2c, I2C_FLAG_TC)) {
        timeout--;
        if (timeout == 0) return 0;
    }
        
    if(stop) i2c_stop(obj);

    return count;
}
开发者ID:goconnor,项目名称:mbed,代码行数:25,代码来源:i2c_api.c


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