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


C++ I2C_GenerateSTOP函数代码示例

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


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

示例1: I2C_EE_PageWrite

/*******************************************************************************
* Function Name  : I2C_EE_PageWrite
* Description    : Writes more than one byte to the EEPROM with a single WRITE
*                  cycle. The number of byte can't exceed the EEPROM page size.
* Input          : - pBuffer : pointer to the buffer containing the data to be 
*                    written to the EEPROM.
*                  - WriteAddr : EEPROM's internal address to write to.
*                  - NumByteToWrite : number of bytes to write to the EEPROM.
* Output         : None
* Return         : None
*******************************************************************************/
void I2C_EE_PageWrite(u8* pBuffer, u8 WriteAddr, u8 NumByteToWrite)
{
  /* Send START condition */
  I2C_GenerateSTART(I2C1, ENABLE);
  
  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 
  
  /* Send EEPROM address for write */
  I2C_Send7bitAddress(I2C1, EEPROM_ADDRESS, I2C_Direction_Transmitter);

  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));  

  /* Send the EEPROM's internal address to write to */    
  I2C_SendData(I2C1, WriteAddr);  

  /* Test on EV8 and clear it */
  while(! I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

  /* While there is data to be written */
  while(NumByteToWrite--)  
  {
    /* Send the current byte */
    I2C_SendData(I2C1, *pBuffer); 

    /* Point to the next byte to be written */
    pBuffer++; 
  
    /* Test on EV8 and clear it */
    while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
  }

  /* Send STOP condition */
  I2C_GenerateSTOP(I2C1, ENABLE);
}
开发者ID:Paolo-Maffei,项目名称:lxyppc-tetrix,代码行数:47,代码来源:i2c_ee.c

示例2: SdkEvalPmDigipotRead

/**
 * @brief  Returns the RDAC register. The potentiometer value in ohm is
 *         given by the formula (cDValue/256*Rab + Rw), where Rab = xxxx and Rw = 60 ohm.
 * @param  xDigipot specifies what digipot has to be set.
 *         This parameter can be DIGIPOT1 or DIGIPOT2.
 * @param  pcDValue pointer to the variable in which the D value has to be stored.
 *         This parameter is an uint8_t*.
 * @retval uint8_t Notifies if an I2C error has occured or if the communication has been correctly done.
 *         This parameter can be I2C_DIGIPOT_OK or I2C_DIGIPOT_ERROR.
 */
uint8_t SdkEvalPmDigipotRead(SdkEvalDigipot xDigipot, uint8_t* pcDValue)
{
  /* Test on BUSY flag */
  while (I2C_GetFlagStatus(DIGIPOT_I2C,I2C_FLAG_BUSY)) I2C_WAIT_TIMER();

  /* Sends START condition */
  I2C_GenerateSTART(DIGIPOT_I2C, ENABLE);

  /* Test on EV5 and clear it */
  while(!I2C_CheckEvent(DIGIPOT_I2C, I2C_EVENT_MASTER_MODE_SELECT)) I2C_WAIT_TIMER();

  /* Sends address for read */
  I2C_Send7bitAddress(DIGIPOT_I2C, s_vectxDigipotAddress[xDigipot], I2C_Direction_Receiver);

  /* Test on EV6 and clear it */
  while(!I2C_CheckEvent(DIGIPOT_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) I2C_WAIT_TIMER();

  /* Disables acknowledgement */
  I2C_AcknowledgeConfig(DIGIPOT_I2C, DISABLE);

  /* Test on EV7 and clear it */
  while(!I2C_CheckEvent(DIGIPOT_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)) I2C_WAIT_TIMER();

  /* Read a byte from DIGIPOT */
  *pcDValue = I2C_ReceiveData(DIGIPOT_I2C);

  /* Sends STOP Condition */
  I2C_GenerateSTOP(DIGIPOT_I2C, ENABLE);

  /* Enables acknowledgement to be ready for a new I2C operation */
  I2C_AcknowledgeConfig(DIGIPOT_I2C,ENABLE);

  /* Returns I2C operation OK value */
  return I2C_DIGIPOT_OK;

}
开发者ID:bzdegluk,项目名称:ACQ,代码行数:46,代码来源:SDK_EVAL_PM.c

示例3: SSD1306_WRITEMULTI

static void SSD1306_WRITEMULTI(uint8_t* data, uint16_t count) 
{
 __disable_irq(); 
 //Wait until I2C isn't busy
while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY) == SET);
  
I2C_TransferHandling(I2C2, SSD1306_I2C_ADDR, count + 1, I2C_AutoEnd_Mode, I2C_CR2_START); // Configure slave address, nbytes, reload, end mode and start or stop generation
   
 while(I2C_GetFlagStatus(I2C2, I2C_ISR_TXIS) == RESET){};  // Wait until TXIS flag is set, waiting ACK
   
 I2C_SendData(I2C2, 0x40);// Send Register address

 while(I2C_GetFlagStatus(I2C2, I2C_FLAG_TXE) == RESET);
 
 
 for (uint8_t i = 0; i < count; i++) 
  {
    
   
    I2C_SendData(I2C2, data[i]); // Send data  
    while(I2C_GetFlagStatus(I2C2, I2C_FLAG_TXE) == RESET);
    
    
  }
 

 I2C_GenerateSTOP(I2C2, ENABLE);
 
 while(I2C_GetFlagStatus(I2C2, I2C_ISR_STOPF) == RESET){};// Wait until STOPF flag is set
   
 I2C_ClearFlag(I2C2, I2C_ICR_STOPCF); // Clear STOPF flag
  
   __enable_irq(); 

 	
}
开发者ID:NjordCZ,项目名称:opentag-eval,代码行数:36,代码来源:i2c_ssd1306.c

示例4: ARead_ATP

char ARead_ATP(int slave_add)
{
  char rdata;

  I2C_Cmd(I2C1,ENABLE);

  I2C_GenerateSTART(I2C1,ENABLE);

  while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT));

  I2C_Send7bitAddress(I2C1,slave_add,I2C_Direction_Receiver);

  while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

  I2C_AcknowledgeConfig(I2C1,DISABLE);

  I2C_GenerateSTOP(I2C1, ENABLE);

  while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED));

  rdata = I2C_ReceiveData(I2C1);

  return rdata;
}
开发者ID:ArimotoHikaru,项目名称:stm32f4_project,代码行数:24,代码来源:i2c.c

示例5: LIS35_ReadRegister

void LIS35_ReadRegister(char addr,char *v)
{
  //Reads one register value

  I2C_GenerateSTART(LIS35_I2C,ENABLE);
  //Test on EV5 and clear it
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_MODE_SELECT));  
  //Send LIS35 address, set I2C master in transmiter mode
  I2C_Send7bitAddress(LIS35_I2C, LIS35_Addr, I2C_Direction_Transmitter);
  //Test on EV6 and clear it
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
  //Send LIS35 local register address, which will be read
  I2C_SendData(LIS35_I2C, addr);
  // Test on EV8 and clear it
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

  //Re-generate START, transmition from slave beginning
  I2C_GenerateSTART(LIS35_I2C,ENABLE);
  //Test on EV5 and clear it
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_MODE_SELECT)); 
  //Send LIS35 address, set I2C master in receiver mode
  I2C_Send7bitAddress(LIS35_I2C, LIS35_Addr, I2C_Direction_Receiver);
  //Only one byte will be received
  //NAck must be configured just before checking EV6 -> disable Acknowledge
  I2C_AcknowledgeConfig(LIS35_I2C, DISABLE);
  //Test on EV6 and clear it
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
  //Generate STOP Condition
  I2C_GenerateSTOP(LIS35_I2C,ENABLE);
  //Test on EV7 and clear it - Wait until DataN is in Shift register
  while(!I2C_CheckEvent(LIS35_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED));
  //Read DataN from DR register
  *v=I2C_ReceiveData(LIS35_I2C);
  //Enable Acknowledge for next transmission 
  I2C_AcknowledgeConfig(LIS35_I2C, ENABLE);
}
开发者ID:develorn,项目名称:ARM_function_kamami,代码行数:36,代码来源:mems2_i2c_lib.c

示例6: mpu6050_i2c_byte_write

void mpu6050_i2c_byte_write(u8 write_data, u8 reg_addr)
{
	while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_BUSY));
	//send start condition
	I2C_GenerateSTART( MPU6050_I2C, ENABLE);
	//test on ev5 and clear it 
	while(!I2C_CheckEvent( MPU6050_I2C, I2C_EVENT_MASTER_MODE_SELECT));
	//send address for write 
	I2C_Send7bitAddress( MPU6050_I2C,I2C1_MPU6050, I2C_Direction_Transmitter);
	//test on ev6 and clear it 
	while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
	//send internal address to write to 
	I2C_SendData( MPU6050_I2C, reg_addr);
	//test on ev8
	while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
	//send the byte to be written
	I2C_SendData(MPU6050_I2C,write_data);
	//test on ev8
	while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

	//send stop condition
	I2C_GenerateSTOP( MPU6050_I2C, ENABLE);
	//i2c_wait_stand();
}
开发者ID:cross-sky,项目名称:stm32,代码行数:24,代码来源:mpu6050.c

示例7: number

/**
@brief Write to I2C
@param[in]	devnum		I2C peripheral number (1 or 2)
@param[in]	adr			I2C address
@param[in]	buf			pointer to data
@param[in]	nbyte		number of bytes to write (nbyte <= sizeof(buf))
@return 0 on success, non-zero otherwise
*/
uint8_t i2c_wr(uint8_t devnum, uint8_t adr, const uint8_t* buf,  uint32_t nbyte)
{
	I2C_TypeDef* I2Cx = i2c_get_pdef(devnum)->i2c;
	//__IO uint32_t Timeout = 0;

	/* Enable Error IT (used in all modes: DMA, Polling and Interrupts */
	// I2Cx->CR2 |= I2C_IT_ERR;

	if (nbyte) {
		i2c_waitfor(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY), 1);

		// Intiate Start Sequence
		I2C_GenerateSTART(I2Cx, ENABLE);
		i2c_waitfor(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT), 2);

		// Send Address  EV5
		I2C_Send7bitAddress(I2Cx, adr, I2C_Direction_Transmitter);
		i2c_waitfor(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED), 3);

		// EV6
		// Write first byte EV8_1
		I2C_SendData(I2Cx, *buf++);

		while (--nbyte) {
			// wait on BTF
			i2c_waitfor(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF), 4);
			I2C_SendData(I2Cx, *buf++);
		}

		i2c_waitfor(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF), 5);
		I2C_GenerateSTOP(I2Cx, ENABLE);
		i2c_waitfor(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF), 6);
	}

	return 0;
}
开发者ID:matejx,项目名称:stm32f10x_lib,代码行数:44,代码来源:i2c.c

示例8: I2C_Read8

uint8_t I2C_Read8(uint8_t addr, uint8_t reg)
{
	uint8_t data = 0;

	I2C_AcknowledgeConfig(I2C1, ENABLE);
	while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));

	I2C_GenerateSTART(I2C1, ENABLE);
	while(!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB));
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

	I2C_Send7bitAddress(I2C1, addr<<1,I2C_Direction_Transmitter);
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

	I2C_SendData(I2C1, reg);
	while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

	I2C_GenerateSTART(I2C1, ENABLE);
	while(!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB));

	I2C_Send7bitAddress(I2C1, addr<<1, I2C_Direction_Receiver);
	while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

	I2C_NACKPositionConfig(I2C1, I2C_NACKPosition_Current);
	I2C_AcknowledgeConfig(I2C1, DISABLE);

	//need to add a wait here for new data, right now it goes to fast to get the new data.
	while(!I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE));
	data = I2C_ReceiveData(I2C1);
	//while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED));

	I2C_GenerateSTOP(I2C1, ENABLE);
	while(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF));

	return data;
}
开发者ID:fwjensen,项目名称:STM32_init,代码行数:36,代码来源:10-DOF_IUM.c

示例9: I2C_DMA_TX_IRQHandler

/**
 * @brief  This function handles the DMA Tx Channel interrupt Handler.
 * @param  None
 * @retval None
 */
void I2C_DMA_TX_IRQHandler(i2c_dev *dev)
{
    /* Check if the DMA transfer is complete */
    if (DMA_GetFlagStatus(dev->dma_tx_ftc) != RESET)
    {
        /* Disable the DMA Tx Stream and Clear TC flag */
        DMA_Cmd(dev->dma_tx_chan, DISABLE);
        DMA_ClearFlag(dev->dma_tx_ftc);

        /*!< Wait till all data have been physically transferred on the bus */
        I2CTimeout = I2C_LONG_TIMEOUT;
        while (!I2C_GetFlagStatus(dev->I2Cx, I2C_FLAG_BTF ))
        {
            if ((I2CTimeout--) == 0)
                return;
        }

        /*!< Send STOP condition */
        I2C_GenerateSTOP(dev->I2Cx, ENABLE);

        /* Reset the variable holding the number of data to be written */
        *I2CDataWritePointer = 0;
    }
}
开发者ID:136048599,项目名称:vrgimbal,代码行数:29,代码来源:i2c_old.c

示例10: sEE_ReadBuffer


//.........这里部分代码省略.........
  } 

  /*!< Send the EEPROM's internal address to read from: MSB of the address first */
  I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));    

  /*!< Test on EV8 and clear it */
  sEETimeout = sEE_FLAG_TIMEOUT;
  while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTING))
  {
    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
  }

  /*!< Send the EEPROM's internal address to read from: LSB of the address */
  I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF));    

  /*!< Test on EV8 and clear it */
  sEETimeout = sEE_FLAG_TIMEOUT;
  while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BTF) == RESET)
  {
    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
  }
  
  /*!< Send STRAT condition a second time */  
  I2C_GenerateSTART(sEE_I2C, ENABLE);
  
  /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */
  sEETimeout = sEE_FLAG_TIMEOUT;
  while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
  {
    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
  } 
  
  /*!< Send EEPROM address for read */
  I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver);  
  
  /* If number of data to be read is 1, then DMA couldn't be used */
  /* One Byte Master Reception procedure (POLLING) ---------------------------*/
  if ((uint16_t)(*NumByteToRead) < 2)
  {
    /* Wait on ADDR flag to be set (ADDR is still not cleared at this level */
    sEETimeout = sEE_FLAG_TIMEOUT;
    while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_ADDR) == RESET)
    {
      if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
    }     
    
    /*!< Disable Acknowledgement */
    I2C_AcknowledgeConfig(sEE_I2C, DISABLE);   
    
    /* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */
    (void)sEE_I2C->SR2;
    
    /*!< Send STOP Condition */
    I2C_GenerateSTOP(sEE_I2C, ENABLE);
    
    /* Wait for the byte to be received */
    sEETimeout = sEE_FLAG_TIMEOUT;
    while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_RXNE) == RESET)
    {
      if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
    }
    
    /*!< Read the byte received from the EEPROM */
    *pBuffer = I2C_ReceiveData(sEE_I2C);
    
    /*!< Decrement the read bytes counter */
    (uint16_t)(*NumByteToRead)--;        
    
    /* Wait to make sure that STOP control bit has been cleared */
    sEETimeout = sEE_FLAG_TIMEOUT;
    while(sEE_I2C->CR1 & I2C_CR1_STOP)
    {
      if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
    }  
    
    /*!< Re-Enable Acknowledgement to be ready for another reception */
    I2C_AcknowledgeConfig(sEE_I2C, ENABLE);    
  }
  else/* More than one Byte Master Reception procedure (DMA) -----------------*/
  {
    /*!< Test on EV6 and clear it */
    sEETimeout = sEE_FLAG_TIMEOUT;
    while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
    {
      if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();
    }  
    
    /* Configure the DMA Rx Channel with the buffer address and the buffer size */
    sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint16_t)(*NumByteToRead), sEE_DIRECTION_RX);
    
    /* Inform the DMA that the next End Of Transfer Signal will be the last one */
    I2C_DMALastTransferCmd(sEE_I2C, ENABLE); 
    
    /* Enable the DMA Rx Stream */
    DMA_Cmd(sEE_I2C_DMA_STREAM_RX, ENABLE);    
  }
  
  /* If all operations OK, return sEE_OK (0) */
  return sEE_OK;
}
开发者ID:CHPeter,项目名称:stm32f429-gps,代码行数:101,代码来源:stm32f429i_discovery_i2c_ee.c

示例11: crI2c

void crI2c( xCoRoutineHandle xHandle,
            unsigned portBASE_TYPE uxIndex )
{
    static uint8_t i;
    crSTART( xHandle );
    for ( ;; )
    {

        static uint8_t init = 0;
        if ( init == 0 )
        {
            i2cSetEn( 0, 1 );
            uint8_t data[1];
            data[0] = 77;
            i2cIo( 0, 0, 1, 1, data );
            i2cConfig( 0, 0, 123, 10000 );
            init = 1;
        }


        TI2C * idc = i2c( uxIndex );

		// Commands loop.
		if ( idc->master )
		{
			if ( ( idc->sendCnt ) || ( idc->receiveCnt ) )
			{
				idc->status = I2C_BUSY;
				// wait for BUSY bit to get cleared.
				idc->elapsed = 0;
				while ( I2C_GetFlagStatus( idc->i2c, I2C_FLAG_BUSY ) )
				{
					if ( idc->elapsed++ > idc->timeout )
				    {
					    idc->status = I2C_ERROR_BUSY;
					    goto i2c_end;
				    }
					crDELAY( xHandle, 1 );
					idc = i2c( uxIndex );
				}

		        if ( idc->sendCnt )
				{
					// Generate START condition on a bus.
					I2C_GenerateSTART( idc->i2c, ENABLE );

					idc->status = I2C_MMS;
					// Wait for SB to be set
					idc->elapsed = 0;
					while ( !I2C_CheckEvent( idc->i2c, I2C_EVENT_MASTER_MODE_SELECT ) )
					{
						if ( idc->elapsed++ > idc->timeout )
						{
							idc->status = I2C_ERROR_MMS;
                            I2C_GenerateSTOP( idc->i2c, ENABLE );
							goto i2c_end;
						}
						crDELAY( xHandle, 1 );
						idc = i2c( uxIndex );
					}

					// Transmit the slave address with write operation enabled.
					I2C_Send7bitAddress( idc->i2c, idc->address, I2C_Direction_Transmitter );

					idc->status = I2C_TMS;
					// Test on ADDR flag.
					idc->elapsed = 0;
					while (  !I2C_CheckEvent( idc->i2c, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED ) )
					{
						if ( idc->elapsed++ > idc->timeout )
					    {
						    idc->status = I2C_ERROR_TMS;
                            I2C_GenerateSTOP( idc->i2c, ENABLE );
						    goto i2c_end;
					    }
					    crDELAY( xHandle, 1 );
					    idc = i2c( uxIndex );
					}


                    // Read data from send queue.
					for ( i=0; i<idc->sendCnt; i++ )
					{
						idc = i2c( uxIndex );
						// Transmit data.
						uint8_t data = idc->sendQueue[ i ];
						I2C_SendData( idc->i2c, data );

						// Test for TXE flag (data sent).
						idc->status = I2C_MBT;
						idc->elapsed = 0;
						while (  !I2C_CheckEvent( idc->i2c, I2C_EVENT_MASTER_BYTE_TRANSMITTED ) )
						{
							if ( idc->elapsed++ > idc->timeout )
						    {
							    idc->status = I2C_ERROR_MBT;
                                I2C_GenerateSTOP( idc->i2c, ENABLE );
							    goto i2c_end;
							}
							crDELAY( xHandle, 1 );
//.........这里部分代码省略.........
开发者ID:glockwork,项目名称:dfu,代码行数:101,代码来源:cr_i2c.c

示例12: i2c_ev_handler

void i2c_ev_handler(void)
{
    static uint8_t subaddress_sent, final_stop;                         // flag to indicate if subaddess sent, flag to indicate final bus condition
    static int8_t index;                                                // index is signed -1 == send the subaddress
    uint8_t SReg_1 = I2Cx->SR1;                                         // read the status register here

    if (SReg_1 & 0x0001) {                                              // we just sent a start - EV5 in ref manual
        I2Cx->CR1 &= ~0x0800;                                           // reset the POS bit so ACK/NACK applied to the current byte
        I2C_AcknowledgeConfig(I2Cx, ENABLE);                            // make sure ACK is on
        index = 0;                                                      // reset the index
        if (reading && (subaddress_sent || 0xFF == reg)) {              // we have sent the subaddr
            subaddress_sent = 1;                                        // make sure this is set in case of no subaddress, so following code runs correctly
            if (bytes == 2)
                I2Cx->CR1 |= 0x0800;                                    // set the POS bit so NACK applied to the final byte in the two byte read
            I2C_Send7bitAddress(I2Cx, addr, I2C_Direction_Receiver);    // send the address and set hardware mode
        } else {                                                        // direction is Tx, or we havent sent the sub and rep start
            I2C_Send7bitAddress(I2Cx, addr, I2C_Direction_Transmitter); // send the address and set hardware mode
            if (reg != 0xFF)                                            // 0xFF as subaddress means it will be ignored, in Tx or Rx mode
                index = -1;                                             // send a subaddress
        }
    } else if (SReg_1 & 0x0002) {                                       // we just sent the address - EV6 in ref manual
        // Read SR1,2 to clear ADDR
        __DMB();                                                        // memory fence to control hardware
        if (bytes == 1 && reading && subaddress_sent) {                 // we are receiving 1 byte - EV6_3
            I2C_AcknowledgeConfig(I2Cx, DISABLE);                       // turn off ACK
            __DMB();
            (void)I2Cx->SR2;                                            // clear ADDR after ACK is turned off
            I2C_GenerateSTOP(I2Cx, ENABLE);                             // program the stop
            final_stop = 1;
            I2C_ITConfig(I2Cx, I2C_IT_BUF, ENABLE);                     // allow us to have an EV7
        } else {                                                        // EV6 and EV6_1
            (void)I2Cx->SR2;                                            // clear the ADDR here
            __DMB();
            if (bytes == 2 && reading && subaddress_sent) {             // rx 2 bytes - EV6_1
                I2C_AcknowledgeConfig(I2Cx, DISABLE);                   // turn off ACK
                I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                // disable TXE to allow the buffer to fill
            } else if (bytes == 3 && reading && subaddress_sent)        // rx 3 bytes
                I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                // make sure RXNE disabled so we get a BTF in two bytes time
            else                                                        // receiving greater than three bytes, sending subaddress, or transmitting
                I2C_ITConfig(I2Cx, I2C_IT_BUF, ENABLE);
        }
    } else if (SReg_1 & 0x004) {                                        // Byte transfer finished - EV7_2, EV7_3 or EV8_2
        final_stop = 1;
        if (reading && subaddress_sent) {                               // EV7_2, EV7_3
            if (bytes > 2) {                                            // EV7_2
                I2C_AcknowledgeConfig(I2Cx, DISABLE);                   // turn off ACK
                read_p[index++] = (uint8_t)I2Cx->DR;                    // read data N-2
                I2C_GenerateSTOP(I2Cx, ENABLE);                         // program the Stop
                final_stop = 1;                                         // required to fix hardware
                read_p[index++] = (uint8_t)I2Cx->DR;                    // read data N - 1
                I2C_ITConfig(I2Cx, I2C_IT_BUF, ENABLE);                 // enable TXE to allow the final EV7
            } else {                                                    // EV7_3
                if (final_stop)
                    I2C_GenerateSTOP(I2Cx, ENABLE);                     // program the Stop
                else
                    I2C_GenerateSTART(I2Cx, ENABLE);                    // program a rep start
                read_p[index++] = (uint8_t)I2Cx->DR;                    // read data N - 1
                read_p[index++] = (uint8_t)I2Cx->DR;                    // read data N
                index++;                                                // to show job completed
            }
        } else {                                                        // EV8_2, which may be due to a subaddress sent or a write completion
            if (subaddress_sent || (writing)) {
                if (final_stop)
                    I2C_GenerateSTOP(I2Cx, ENABLE);                     // program the Stop
                else
                    I2C_GenerateSTART(I2Cx, ENABLE);                    // program a rep start
                index++;                                                // to show that the job is complete
            } else {                                                    // We need to send a subaddress
                I2C_GenerateSTART(I2Cx, ENABLE);                        // program the repeated Start
                subaddress_sent = 1;                                    // this is set back to zero upon completion of the current task
            }
        }
        // TODO - busy waiting in ISR
        // we must wait for the start to clear, otherwise we get constant BTF
        while (I2Cx->CR1 & 0x0100) { ; }
    } else if (SReg_1 & 0x0040) {                                       // Byte received - EV7
        read_p[index++] = (uint8_t)I2Cx->DR;
        if (bytes == (index + 3))
            I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                    // disable TXE to allow the buffer to flush so we can get an EV7_2
        if (bytes == index)                                             // We have completed a final EV7
            index++;                                                    // to show job is complete
    } else if (SReg_1 & 0x0080) {                                       // Byte transmitted EV8 / EV8_1
        if (index != -1) {                                              // we dont have a subaddress to send
            I2Cx->DR = write_p[index++];
            if (bytes == index)                                         // we have sent all the data
                I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                // disable TXE to allow the buffer to flush
        } else {
            index++;
            I2Cx->DR = reg;                                             // send the subaddress
            if (reading || !bytes)                                      // if receiving or sending 0 bytes, flush now
                I2C_ITConfig(I2Cx, I2C_IT_BUF, DISABLE);                // disable TXE to allow the buffer to flush
        }
    }
    if (index == bytes + 1) {                                           // we have completed the current job
        subaddress_sent = 0;                                            // reset this here
        if (final_stop)                                                 // If there is a final stop and no more jobs, bus is inactive, disable interrupts to prevent BTF
            I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE);       // Disable EVT and ERR interrupts while bus inactive
        busy = 0;
    }
}
开发者ID:Andriiy,项目名称:cleanflight,代码行数:100,代码来源:bus_i2c_stm32f10x.c

示例13: MACEEP_Read

void MACEEP_Read(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead)
{
    /* While the bus is busy */
    while(I2C_GetFlagStatus(MACEPP_I2C, I2C_FLAG_BUSY));

    /* Send START condition */
    I2C_GenerateSTART(MACEPP_I2C, ENABLE);

    /* Test on EV5 and clear it */
    while(!I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_MODE_SELECT));

    /* Send EEPROM address for write */
    I2C_Send7bitAddress(MACEPP_I2C, MACEEP_Address, I2C_Direction_Transmitter);

    /* Test on EV6 and clear it */
    while(!I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));

    /* Send the EEPROM's internal address to read from: LSB of the address */
    I2C_SendData(MACEPP_I2C, (uint8_t)(ReadAddr & 0x00FF));

    /* Test on EV8 and clear it */
    while(!I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));

    /* Send STRAT condition a second time */
    I2C_GenerateSTART(MACEPP_I2C, ENABLE);

    /* Test on EV5 and clear it */
    while(!I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_MODE_SELECT));

    /* Send EEPROM address for read */
    I2C_Send7bitAddress(MACEPP_I2C, MACEEP_Address, I2C_Direction_Receiver);

    /* Test on EV6 and clear it */
    while(!I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));

    /* While there is data to be read */
    while(NumByteToRead)
    {
        if(NumByteToRead == 1)
        {
            /* Disable Acknowledgement */
            I2C_AcknowledgeConfig(MACEPP_I2C, DISABLE);

            /* Send STOP Condition */
            I2C_GenerateSTOP(MACEPP_I2C, ENABLE);
        }

    /* Test on EV7 and clear it */
        if(I2C_CheckEvent(MACEPP_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
        {
            /* Read a byte from the EEPROM */
            *pBuffer = I2C_ReceiveData(MACEPP_I2C);

            /* Point to the next location where the byte read will be saved */
            pBuffer++;

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

    /* Enable Acknowledgement to be ready for another reception */
    I2C_AcknowledgeConfig(MACEPP_I2C, ENABLE);
}
开发者ID:bangbh81,项目名称:MbedTLS-Test,代码行数:64,代码来源:IoTEVB.c

示例14: LM75_WriteConfReg

/**
  * @brief  Write to the configuration register of the LM75.
  * @param  RegValue: sepecifies 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 */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY)) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Configure DMA Peripheral */
  LM75_DMA_Config(LM75_DMA_TX, (uint8_t*)(&LM75_BufferTX), 1);
  
  /* Enable the I2C peripheral */
  I2C_GenerateSTART(LM75_I2C, ENABLE);
  
  /* Test on SB Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB) == RESET) 
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the slave address and enable writing operation */
  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
  
  /* Test on ADDR Flag */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Transmit the first address for r/w operations */
  I2C_SendData(LM75_I2C, LM75_REG_CONF);
  
  /* Test on TXE FLag (data sent) */
  LM75_Timeout = LM75_FLAG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Enable I2C DMA request */
  I2C_DMACmd(LM75_I2C,ENABLE);
  
  /* Enable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, ENABLE);
  
  /* Wait until DMA Transfer Complete */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while (!DMA_GetFlagStatus(LM75_DMA_TX_TCFLAG))
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }  
  
  /* Wait until BTF Flag is set before generating STOP */
  LM75_Timeout = LM75_LONG_TIMEOUT;
  while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))  
  {
    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
  }
  
  /* Send STOP Condition */
  I2C_GenerateSTOP(LM75_I2C, ENABLE);
  
  /* Disable DMA TX Channel */
  DMA_Cmd(LM75_DMA_TX_CHANNEL, DISABLE);
  
  /* Disable I2C DMA request */  
  I2C_DMACmd(LM75_I2C,DISABLE);
  
  /* Clear DMA TX Transfer Complete Flag */
  DMA_ClearFlag(LM75_DMA_TX_TCFLAG);  
  
  return LM75_OK;
  
}
开发者ID:0x00f,项目名称:STM32F1-workarea,代码行数:86,代码来源:stm32_eval_i2c_tsensor.c

示例15: I2C_stop

/* This funtion issues a stop condition and therefore
* releases the bus
*/
void I2C_stop(I2C_TypeDef* I2Cx){
	// Send I2C1 STOP Condition
	I2C_GenerateSTOP(I2Cx, ENABLE);

	//while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_STOPF)); //spoko to ja dopisalem
}
开发者ID:michalzykiert,项目名称:PUT_PTM13_IMU,代码行数:9,代码来源:main.c


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