您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ I2C_ReceiveData函数代码示例

51自学网 2021-06-01 21:26:57
  C++
这篇教程C++ I2C_ReceiveData函数代码示例写得很实用,希望能帮到您。

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

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

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


示例2: I2CRXByte

unsigned char I2CRXByte(I2C_TypeDef *I2Cx){	unsigned short temp;#ifdef I2C_INT_MODE		I2C_ITConfig(I2Cx, I2C_IT_RX_FULL, ENABLE);		while(1)	{		if(rx_flag)		{			rx_flag = 0;			break;		}	}	#else	I2CRXFullCheck(I2Cx);#endif		temp = I2C_ReceiveData(I2Cx);	return (unsigned char)temp;}
开发者ID:CherishFan,项目名称:MT02_MCO,代码行数:24,


示例3: crI2c

//.........这里部分代码省略.........						if ( idc->elapsed++ > idc->timeout )                        {						    idc->status = I2C_ERROR_BTF;                            I2C_GenerateSTOP( idc->i2c, ENABLE );						    goto i2c_end;					    }						crDELAY( xHandle, 1 );					    idc = i2c( uxIndex );					}				}				// Receiving data if necessary.				if ( idc->receiveCnt )				{				    I2C_AcknowledgeConfig( idc->i2c, ENABLE );					// Generate START condition if there was at least one byte written.					I2C_GenerateSTART( idc->i2c, ENABLE );					idc->status = I2C_MMS_R;					// 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_R;                            I2C_GenerateSTOP( idc->i2c, ENABLE );							goto i2c_end;						}						crDELAY( xHandle, 1 );						idc = i2c( uxIndex );					}					I2C_Send7bitAddress( idc->i2c, idc->address, I2C_Direction_Receiver );					// Test on ADDR Flag					idc->status = I2C_RMS;					idc->elapsed = 0;					while ( !I2C_CheckEvent( idc->i2c, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ) )					{						if ( idc->elapsed++ > idc->timeout )						{							idc->status = I2C_ERROR_RMS;                            I2C_GenerateSTOP( idc->i2c, ENABLE );							goto i2c_end;						}						crDELAY( xHandle, 1 );						idc = i2c( uxIndex );					}					// Receiving a number of bytes from slave.					for ( i=0; i<idc->receiveCnt; i++ )					{						// Turn acknowledge off when reading the last byte.						if ( i == (idc->receiveCnt-1) )							I2C_AcknowledgeConfig( idc->i2c, DISABLE );						// Wait for data available.						idc->status = I2C_MBR;						idc->elapsed = 0;						while ( !I2C_CheckEvent( idc->i2c, I2C_EVENT_MASTER_BYTE_RECEIVED ) )						{							if ( idc->elapsed++ > idc->timeout )                            {							    idc->status = I2C_ERROR_MBR;	                            I2C_GenerateSTOP( idc->i2c, ENABLE ); 						        goto i2c_end;						    }							crDELAY( xHandle, 1 );							idc = i2c( uxIndex );						}						// Read the data.						uint8_t data = I2C_ReceiveData( idc->i2c );						idc->receiveQueue[i] = data;						idc->bytesRead = i+1;					}				}				// Generating STOP.				I2C_GenerateSTOP( idc->i2c, ENABLE );                // Idle status when finished in regular way.                idc->status = I2C_IDLE;			}		}		else // master.		{			// slave mode IO.			//...... implementation.....            // Idle status when finished in regular way.            //idc->status = I2C_IDLE;			crDELAY( xHandle, 1 );		}i2c_end:		// To prevent cyclic writes of zero data.		idc->sendCnt = 0;		idc->receiveCnt = 0;		// Give other coroutines time for running.		crDELAY( xHandle, 1 );    }    crEND();}
开发者ID:glockwork,项目名称:dfu,代码行数:101,


示例4: BH1750_Read

uint32_t BH1750_Read(void){        uint16_t BH_H;        uint16_t BH_L;        uint32_t value;                int iTimeout = DEF_TIMEOUT_I2C;        I2C_AcknowledgeConfig(BH1750_I2C,ENABLE); // Enable I2C acknowledge	I2C_GenerateSTART(BH1750_I2C,ENABLE); // Send START condition        iTimeout = DEF_TIMEOUT_I2C;	while (!I2C_CheckEvent(BH1750_I2C,I2C_EVENT_MASTER_MODE_SELECT)) { // Wait for EV5                      iTimeout--;           if(!(iTimeout))   {              return 0;           }        }        iTimeout = DEF_TIMEOUT_I2C;	while (!I2C_CheckEvent(BH1750_I2C, I2C_EVENT_MASTER_MODE_SELECT)) { // Wait for EV5                      iTimeout--;           if(!(iTimeout))   {              return 0;           }        }	I2C_Send7bitAddress(BH1750_I2C, BH1750_ADDRESS, I2C_Direction_Receiver); // Send slave address for READ        iTimeout = DEF_TIMEOUT_I2C;	while (!I2C_CheckEvent(BH1750_I2C,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) { // Wait for EV6                      iTimeout--;           if(!(iTimeout))   {              return 0;           }        }	iTimeout = DEF_TIMEOUT_I2C;	while (!I2C_CheckEvent(BH1750_I2C,I2C_EVENT_MASTER_BYTE_RECEIVED)) { // Wait for EV7 (Byte received from slave)                      iTimeout--;           if(!(iTimeout))   {              return 0;           }        }	BH_H = (uint16_t)I2C_ReceiveData(BH1750_I2C); // Receive MSB	iTimeout = DEF_TIMEOUT_I2C;	while (!I2C_CheckEvent(BH1750_I2C,I2C_EVENT_MASTER_BYTE_RECEIVED)) { // Wait for EV7 (Byte received from slave)                      iTimeout--;           if(!(iTimeout))   {              return 0;           }        }	BH_L = (uint32_t)I2C_ReceiveData(BH1750_I2C); // Receive LSB	I2C_AcknowledgeConfig(BH1750_I2C,DISABLE); // Disable I2C acknowledgment	I2C_GenerateSTOP(BH1750_I2C,ENABLE); // Send STOP condition                value = BH_H*256 + BH_L;        value = value*10/12;                return value;}
开发者ID:IvanOrfanidi,项目名称:STM32-Tests-Project,代码行数:61,


示例5: I2C_BufferRead

void I2C_BufferRead(I2C_TypeDef* I2Cx,u8* pBuffer,u8 devAddr, u8 ReadAddr, u16 NumByteToRead){#if 0		  /* Send START condition */  I2C_GenerateSTART(I2Cx, ENABLE);  /* Test on EV5 and clear it */  while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));  /* Send EEPROM address for write */  I2C_Send7bitAddress(I2Cx, devAddr, I2C_Direction_Transmitter);  /* Test on EV6 and clear it */  while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));  /* Clear EV6 by setting again the PE bit */  I2C_Cmd(I2Cx, ENABLE);  /* Send the EEPROM's internal address to write to */  I2C_SendData(I2Cx, ReadAddr);  /* Test on EV8 and clear it */  while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));  /* Send STRAT condition a second time */  I2C_GenerateSTART(I2Cx, ENABLE);  /* Test on EV5 and clear it */  while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));  /* Send EEPROM address for read */  I2C_Send7bitAddress(I2Cx, devAddr, I2C_Direction_Receiver);  /* Test on EV6 and clear it */  while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));  /* While there is data to be read */  while(NumByteToRead)  {    if(NumByteToRead == 1)    {      /* Disable Acknowledgement */      I2C_AcknowledgeConfig(I2Cx, DISABLE);      /* Send STOP Condition */      I2C_GenerateSTOP(I2Cx, ENABLE);    }    /* Test on EV7 and clear it */    if(I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED))    {      /* Read a byte from the EEPROM */      *pBuffer = I2C_ReceiveData(I2Cx);      /* 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(I2Cx, ENABLE);#endif  }
开发者ID:Simonliang0928,项目名称:Contiki-BORDER,代码行数:66,


示例6: LM75_ShutDown

/**  * @brief  Enables or disables the LM75.  * @param  NewState: specifies the LM75 new status. This parameter can be ENABLE  *         or DISABLE.    * @retval None  */uint8_t LM75_ShutDown(FunctionalState NewState){     uint8_t LM75_BufferRX[2] ={0,0};  uint8_t LM75_BufferTX = 0;  __IO uint8_t RegValue = 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);    /* Get received data */  RegValue = (uint8_t)LM75_BufferRX[0];    /*---------------------------- Transmission Phase ---------------------------*/    /* Enable or disable SD bit */  if (NewState != DISABLE)  {    /* Enable LM75 */    LM75_BufferTX = RegValue & LM75_SD_RESET;  }  else  {    /* Disable LM75 */    LM75_BufferTX = RegValue | LM75_SD_SET;  }      /* 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 *///.........这里部分代码省略.........
开发者ID:Azizou,项目名称:stm32f0_devel,代码行数:101,


示例7: LSM303DLH_I2C_BufferRead

void LSM303DLH_I2C_BufferRead(u8 slAddr, u8* pBuffer, u8 ReadAddr, u16 NumByteToRead){  iNEMO_ENTER_CRITICAL();  /* While the bus is busy */  while(I2C_GetFlagStatus(LSM_I2C, I2C_FLAG_BUSY));  /* Send START condition */  I2C_GenerateSTART(LSM_I2C, ENABLE);  /* Test on EV5 and clear it */  while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_MODE_SELECT));  /* Send LSM303DLH_Magn address for write */  I2C_Send7bitAddress(LSM_I2C, slAddr, I2C_Direction_Transmitter);  /* Test on EV6 and clear it */  while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));  /* Clear EV6 by setting again the PE bit */  I2C_Cmd(LSM_I2C, ENABLE);  /* Send the LSM303DLH_Magn's internal address to write to */  I2C_SendData(LSM_I2C, ReadAddr);  /* Test on EV8 and clear it */  while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));  /* Send STRAT condition a second time */  I2C_GenerateSTART(LSM_I2C, ENABLE);  /* Test on EV5 and clear it */  while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_MODE_SELECT));  /* Send LSM303DLH address for read */  I2C_Send7bitAddress(LSM_I2C, slAddr, I2C_Direction_Receiver);  /* Test on EV6 and clear it */  while(!I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));  /* While there is data to be read */  while(NumByteToRead)  {    if(NumByteToRead == 1)    {      /* Disable Acknowledgement */      I2C_AcknowledgeConfig(LSM_I2C, DISABLE);      /* Send STOP Condition */      I2C_GenerateSTOP(LSM_I2C, ENABLE);    }    /* Test on EV7 and clear it */    if(I2C_CheckEvent(LSM_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))    {      /* Read a byte from the LSM303DLH */      *pBuffer = I2C_ReceiveData(LSM_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(LSM_I2C, ENABLE);  iNEMO_EXIT_CRITICAL();}
开发者ID:dessel,项目名称:stf12,代码行数:69,


示例8: AJS_TargetIO_I2cRead

uint8_t AJS_TargetIO_I2cRead(void* ctx){    I2C_Pin* i2c = (I2C_Pin*)ctx;    return I2C_ReceiveData(i2c->I2Cx);}
开发者ID:anthony-ngu,项目名称:core-alljoyn-js,代码行数:5,


示例9: main

/******************************************************************************** Function Name  : main* Description    : Main program* Input          : None* Output         : None* Return         : None*******************************************************************************/int main(void){#ifdef DEBUG  debug();#endif  /* System clocks configuration ---------------------------------------------*/  RCC_Configuration();  /* NVIC configuration ------------------------------------------------------*/  NVIC_Configuration();  /* GPIO configuration ------------------------------------------------------*/  GPIO_Configuration();  /* Enable I2C1 and I2C2 ----------------------------------------------------*/  I2C_Cmd(I2C1, ENABLE);  I2C_Cmd(I2C2, ENABLE);  /* I2C1 configuration ------------------------------------------------------*/  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;  I2C_InitStructure.I2C_ClockSpeed = ClockSpeed;  I2C_Init(I2C1, &I2C_InitStructure);  /* I2C2 configuration ------------------------------------------------------*/  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_10bit;  I2C_InitStructure.I2C_OwnAddress1 = I2C2_SLAVE_ADDRESS10;  I2C_Init(I2C2, &I2C_InitStructure);       /*----- Transmission Phase -----*/  /* Send I2C1 START condition */  I2C_GenerateSTART(I2C1, ENABLE);  /* Test on I2C1 EV5 and clear it */  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));    /* Send Header to I2C2 for write */  I2C_SendData(I2C1, HeaderAddressWrite);  /* Test on I2C1 EV9 and clear it */  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_ADDRESS10));   /* Send I2C2 slave Address for write */  I2C_Send7bitAddress(I2C1, I2C2_SLAVE_ADDRESS7, I2C_Direction_Transmitter);  /* Test on I2C2 EV1 and clear it */  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED));    /* Test on I2C1 EV6 and clear it */  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));    /* Send data */  while (RxIdx < BufferSize)  {    /* Send I2C1 data */    I2C_SendData(I2C1, I2C1_Buffer_Tx[TxIdx++]);   /* Test on I2C2 EV2 and clear it */    while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_BYTE_RECEIVED));      /* Store received data on I2C2 */    I2C2_Buffer_Rx[RxIdx++] = I2C_ReceiveData(I2C2);    /* Test on I2C1 EV8 and clear it */    while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));   }  /* Send I2C1 STOP Condition */  I2C_GenerateSTOP(I2C1, ENABLE);  /* Test on I2C2 EV4 and clear it */  while(!I2C_CheckEvent(I2C2, I2C_EVENT_SLAVE_STOP_DETECTED));   /* Clear I2C2 STOPF flag: read operation to I2C_SR1 followed by a   write operation to I2C_CR1 */  (void)(I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF));  I2C_Cmd(I2C2, ENABLE);   /* Check the corectness of written data */  TransferStatus = Buffercmp(I2C1_Buffer_Tx, I2C2_Buffer_Rx, BufferSize);  /* TransferStatus = PASSED, if the transmitted and received data     are equal */  /* TransferStatus = FAILED, if the transmitted and received data      are different */  while (1)  {  }}
开发者ID:zaurus04,项目名称:cortexm3,代码行数:88,


示例10: MPU9250_I2C_ByteRead

char MPU9250_I2C_ByteRead(u8 slaveAddr, u8 readAddr){	char tmp = 0;    // ENTR_CRT_SECTION();    /* While the bus is busy */    while (I2C_GetFlagStatus(MPU9250_I2C, I2C_FLAG_BUSY));    /* Send START condition */    I2C_GenerateSTART(MPU9250_I2C, ENABLE);    /* Test on EV5 and clear it */    while (!I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_MODE_SELECT));    /* Send MPU9250 address for write */    I2C_Send7bitAddress(MPU9250_I2C, slaveAddr, I2C_Direction_Transmitter);    /* Test on EV6 and clear it */    while (!I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));    /* Clear EV6 by setting again the PE bit */    I2C_Cmd(MPU9250_I2C, ENABLE);    /* Send the MPU9250's internal address to write to */    I2C_SendData(MPU9250_I2C, readAddr);    /* Test on EV8 and clear it */    while (!I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));    /* Send STRAT condition a second time */    I2C_GenerateSTART(MPU9250_I2C, ENABLE);    /* Test on EV5 and clear it */    while (!I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_MODE_SELECT));    /* Send MPU9250 address for read */    I2C_Send7bitAddress(MPU9250_I2C, slaveAddr, I2C_Direction_Receiver);    /* Test on EV6 and clear it */    while (!I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));    /* While there is data to be read */	for (;;) {		/* Disable Acknowledgement */		I2C_AcknowledgeConfig(MPU9250_I2C, DISABLE);		/* Send STOP Condition */		I2C_GenerateSTOP(MPU9250_I2C, ENABLE);		/* Test on EV7 and clear it */		if (I2C_CheckEvent(MPU9250_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)) {			/* Read a byte from the MPU9250 */			tmp = I2C_ReceiveData(MPU9250_I2C);			break;		}	}    /* Enable Acknowledgement to be ready for another reception */    I2C_AcknowledgeConfig(MPU9250_I2C, ENABLE);    // EXT_CRT_SECTION();    return tmp;}
开发者ID:blanboom,项目名称:QuickRotor,代码行数:66,


示例11: TWI_MasterWriteRead

//.........这里部分代码省略.........		  /*!< Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */		  sEETimeout = sEE_FLAG_TIMEOUT;		  while(!I2C_CheckEvent(sEE_I2C[TwiStruct->TwiNr], I2C_EVENT_MASTER_MODE_SELECT))		  {				if((sEETimeout--) == 0) {					return false;				}		  }		  /*!< Send EEPROM address for read */		  I2C_Send7bitAddress(sEE_I2C[TwiStruct->TwiNr], TwiStruct->MasterSlaveAddr << 1, 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 (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[TwiStruct->TwiNr], I2C_FLAG_ADDR) == RESET)			{				if((sEETimeout--) == 0) {					return false;				}			}			(void)sEE_I2C[TwiStruct->TwiNr]->SR2;			  cnt = 0;			  for(; cnt < ReceiveBytes; cnt++)			  {				if(cnt == ReceiveBytes - 1)				{					/*!< Disable Acknowledgement */					I2C_AcknowledgeConfig(sEE_I2C[TwiStruct->TwiNr], DISABLE);					/* Call User callback for critical section start (should typically disable interrupts) */					sEE_EnterCriticalSection_UserCallback();					/* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */					(void)sEE_I2C[TwiStruct->TwiNr]->SR2;					/*!< Send STOP Condition */					I2C_GenerateSTOP(sEE_I2C[TwiStruct->TwiNr], ENABLE);					/* Call User callback for critical section end (should typically re-enable interrupts) */					sEE_ExitCriticalSection_UserCallback();				}				/* Wait for the byte to be received */				sEETimeout = sEE_FLAG_TIMEOUT;				while(I2C_GetFlagStatus(sEE_I2C[TwiStruct->TwiNr], I2C_FLAG_RXNE) == RESET)				{					if((sEETimeout--) == 0) {						return false;					}				}				/*!< Read the byte received from the EEPROM */				TwiStruct->RxBuff[cnt] = I2C_ReceiveData(sEE_I2C[TwiStruct->TwiNr]);			  }			/* Wait to make sure that STOP control bit has been cleared */			sEETimeout = sEE_FLAG_TIMEOUT;			while(sEE_I2C[TwiStruct->TwiNr]->CR1 & I2C_CR1_STOP)			{				if((sEETimeout--) == 0) {					return false;				}			}			/*!< Re-Enable Acknowledgement to be ready for another reception */			I2C_AcknowledgeConfig(sEE_I2C[TwiStruct->TwiNr], ENABLE);	  }  }  else {		/* Call User callback for critical section start (should typically disable interrupts) */		sEE_EnterCriticalSection_UserCallback();		/* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */		(void)sEE_I2C[TwiStruct->TwiNr]->SR2;		/*!< Send STOP Condition */		I2C_GenerateSTOP(sEE_I2C[TwiStruct->TwiNr], ENABLE);		/* Call User callback for critical section end (should typically re-enable interrupts) */		sEE_ExitCriticalSection_UserCallback();		/* Wait for the byte to be received */		sEETimeout = sEE_FLAG_TIMEOUT;		while(I2C_GetFlagStatus(sEE_I2C[TwiStruct->TwiNr], I2C_FLAG_RXNE) == RESET)		{			if((sEETimeout--) == 0) {				return true;			}		}  }  /* If all operations OK, return sEE_OK (0) */  return true;}
开发者ID:KonstantinVoip,项目名称:mSdk,代码行数:101,


示例12: HAL_I2C_EV_InterruptHandler

static void HAL_I2C_EV_InterruptHandler(HAL_I2C_Interface i2c){    /* Process Last I2C Event */    switch (I2C_GetLastEvent(i2cMap[i2c]->I2C_Peripheral))    {    /********** Slave Transmitter Events ************/    /* Check on EV1 */    case I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED:        i2cMap[i2c]->transmitting = 1;        i2cMap[i2c]->txBufferIndex = 0;        i2cMap[i2c]->txBufferLength = 0;        if(NULL != i2cMap[i2c]->callback_onRequest)        {            // alert user program            i2cMap[i2c]->callback_onRequest();        }        i2cMap[i2c]->txBufferIndex = 0;        break;    /* Check on EV3 */    case I2C_EVENT_SLAVE_BYTE_TRANSMITTING:    case I2C_EVENT_SLAVE_BYTE_TRANSMITTED:        if (i2cMap[i2c]->txBufferIndex < i2cMap[i2c]->txBufferLength)        {            I2C_SendData(i2cMap[i2c]->I2C_Peripheral, i2cMap[i2c]->txBuffer[i2cMap[i2c]->txBufferIndex++]);        }        break;    /*********** Slave Receiver Events *************/    /* check on EV1*/    case I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED:        i2cMap[i2c]->rxBufferIndex = 0;        i2cMap[i2c]->rxBufferLength = 0;        break;    /* Check on EV2*/    case I2C_EVENT_SLAVE_BYTE_RECEIVED:    case (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_SR1_BTF):        i2cMap[i2c]->rxBuffer[i2cMap[i2c]->rxBufferIndex++] = I2C_ReceiveData(i2cMap[i2c]->I2C_Peripheral);        break;    /* Check on EV4 */    case I2C_EVENT_SLAVE_STOP_DETECTED:        /* software sequence to clear STOPF */        I2C_GetFlagStatus(i2cMap[i2c]->I2C_Peripheral, I2C_FLAG_STOPF);        I2C_Cmd(i2cMap[i2c]->I2C_Peripheral, ENABLE);        i2cMap[i2c]->rxBufferLength = i2cMap[i2c]->rxBufferIndex;        i2cMap[i2c]->rxBufferIndex = 0;        if(NULL != i2cMap[i2c]->callback_onReceive)        {            // alert user program            i2cMap[i2c]->callback_onReceive(i2cMap[i2c]->rxBufferLength);        }        break;    default:        break;    }}
开发者ID:RobertNewkirk,项目名称:particle,代码行数:65,


示例13: HAL_I2C_Request_Data

uint32_t HAL_I2C_Request_Data(HAL_I2C_Interface i2c, uint8_t address, uint8_t quantity, uint8_t stop, void* reserved){    uint32_t _millis;    uint8_t bytesRead = 0;    // clamp to buffer length    if(quantity > BUFFER_LENGTH)    {        quantity = BUFFER_LENGTH;    }    /* Send START condition */    I2C_GenerateSTART(i2cMap[i2c]->I2C_Peripheral, ENABLE);    _millis = HAL_Timer_Get_Milli_Seconds();    while(!I2C_CheckEvent(i2cMap[i2c]->I2C_Peripheral, I2C_EVENT_MASTER_MODE_SELECT))    {        if(EVENT_TIMEOUT < (HAL_Timer_Get_Milli_Seconds() - _millis))        {            /* SW Reset the I2C Peripheral */            HAL_I2C_SoftwareReset(i2c);            return 0;        }    }    /* Initialized variables here to minimize delays     * between sending of slave addr and read loop     */    uint8_t *pBuffer = i2cMap[i2c]->rxBuffer;    uint8_t numByteToRead = quantity;    /* Ensure ackFailure flag is cleared */    i2cMap[i2c]->ackFailure = false;    /* Set ACK/NACK prior to I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED check     * to minimize delays between sending of slave addr and read loop.     * I2C_CheckEvent() will clear ADDR bit and allow SCL clocks to run, so we don't     * have much time to check/set this correctly while I2C is in operation.     */    if (quantity == 1)        /* Disable Acknowledgement */        I2C_AcknowledgeConfig(i2cMap[i2c]->I2C_Peripheral, DISABLE);    else        I2C_AcknowledgeConfig(i2cMap[i2c]->I2C_Peripheral, ENABLE);    /* Send Slave address for read */    I2C_Send7bitAddress(i2cMap[i2c]->I2C_Peripheral, address << 1, I2C_Direction_Receiver);    _millis = HAL_Timer_Get_Milli_Seconds();    while(!I2C_CheckEvent(i2cMap[i2c]->I2C_Peripheral, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))    {        /* STOP/RESET immediately if ACK failure detected */        if(EVENT_TIMEOUT < (HAL_Timer_Get_Milli_Seconds() - _millis) || i2cMap[i2c]->ackFailure)        {            /* Send STOP Condition */            I2C_GenerateSTOP(i2cMap[i2c]->I2C_Peripheral, ENABLE);            /* Wait to make sure that STOP control bit has been cleared */            _millis = HAL_Timer_Get_Milli_Seconds();            while(i2cMap[i2c]->I2C_Peripheral->CR1 & I2C_CR1_STOP)            {                if(EVENT_TIMEOUT < (HAL_Timer_Get_Milli_Seconds() - _millis))                {                    break;                }            }            /* SW Reset the I2C Peripheral */            HAL_I2C_SoftwareReset(i2c);            /* Ensure ackFailure flag is cleared */            i2cMap[i2c]->ackFailure = false;            return 0;        }    }    /* DATA on SDA --> Shift Register (SR) [8 clocks by SCL] --> Data Register (DR) --> ACK/NACK (9th clock)     *     * SINGLE BYTE READ     *  - SCL will run immediately after ADDR bit is cleared by reading SR2 (any I2C_CheckEvent)     *  - DR will be empty     *  - 1st byte from slave will be transferred to DR after 8th SCL clock     *  - ACK/NACK will be sent immediately (SCL will run 9th clock)     *     * 2 BYTES LEFT TO READ     *  - DR is not yet empty (2nd last byte is in DR; it was ACKed on its xfer to DR)     *  - Last byte is being assembled in SR     *  - SCL will be stretched after 8th clock (SR full) until DR is empty     *  - Reading DR for 2nd last byte will then move last byte to DR and send ACK/NACK     *     * While there is data to be read, perform blocking read into buffer     */    while(numByteToRead)    {        /* Wait for DR to be full. As soon as DR is full, the byte that was xfer'd from SR         * to DR will be ACK/NACK'd. So it is important to enable/disable ACK bit ahead of this event         */        _millis = HAL_Timer_Get_Milli_Seconds();//.........这里部分代码省略.........
开发者ID:RobertNewkirk,项目名称:particle,代码行数:101,


示例14: i2c1_read

int i2c1_read(uint8_t u8addr, uint8_t *u8data,uint8_t u8qty){  volatile uint32_t u32timeout;  uint8_t recived = 0;  /* While the bus is busy */  //u32timeout = I2C_WAIT_TIMEOUT;  //while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY)&& --u32timeout);  //if (!u32timeout) return 1;  /* Send START condition */  I2C_GenerateSTART(I2C1, ENABLE);  /* Test on EV5 and clear it */  u32timeout = I2C_WAIT_TIMEOUT;  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)&& --u32timeout);  if (!u32timeout) return fail;  /* Send paj7620 address for write */  I2C_Send7bitAddress(I2C1, APDS9960_I2C_ADDR << 1, I2C_Direction_Transmitter);  /* Test on EV6 and clear it */  u32timeout = I2C_WAIT_TIMEOUT;  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)&& --u32timeout);  if (!u32timeout) return fail;  /* Clear EV6 by setting again the PE bit */  I2C_Cmd(I2C1, ENABLE);  /* Send the paj7620's internal address to write to */  I2C_SendData(I2C1, u8addr);  /* Test on EV8 and clear it */  u32timeout = I2C_WAIT_TIMEOUT;  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)&& --u32timeout);  if (!u32timeout) return fail;  /* Send STRAT condition a second time */  I2C_GenerateSTART(I2C1, ENABLE);  /* Test on EV5 and clear it */  u32timeout = I2C_WAIT_TIMEOUT;  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)&& --u32timeout);  if (!u32timeout) return fail;  /* Send paj7620 address for read */  I2C_Send7bitAddress(I2C1, APDS9960_I2C_ADDR << 1, I2C_Direction_Receiver);  /* Test on EV6 and clear it */  u32timeout = I2C_WAIT_TIMEOUT;  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)&& --u32timeout);  if (!u32timeout) return fail;  /* While there is data to be read */  while(u8qty)  {    if(u8qty == 1)    {      /* Disable Acknowledgement */      I2C_AcknowledgeConfig(I2C1, DISABLE);      /* Send STOP Condition */      I2C_GenerateSTOP(I2C1, ENABLE);    }    /* Test on EV7 and clear it */    if(I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))    {      /* Read a byte from the paj7620 */      //*u8data = I2C_ReceiveData(I2C1);      u8data[recived] = I2C_ReceiveData(I2C1);      /* Point to the next location where the byte read will be saved */      //u8data++;      recived++;      /* Decrement the read bytes counter */      u8qty--;    }  }  /* Enable Acknowledgement to be ready for another reception */  I2C_AcknowledgeConfig(I2C1, ENABLE);  return recived;}/* End of this function */
开发者ID:elektronikaembedded,项目名称:IR_Gesture_APDS9960,代码行数:74,


示例15: sEE_ReadBuffer

uint32_t sEE_ReadBuffer(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead){  /* While the bus is busy */  sEETimeout = sEE_LONG_TIMEOUT;  while(I2C_GetFlagStatus( I2C_FLAG_BUSBUSY))  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  }  /* Send START condition */  I2C_GenerateSTART(ENABLE);  /* Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */  sEETimeout = sEE_FLAG_TIMEOUT;  while(!I2C_CheckEvent( I2C_EVENT_MASTER_MODE_SELECT))  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  }  /* Send EEPROM address for write */  I2C_Send7bitAddress( (uint8_t)sEEAddress, I2C_DIRECTION_TX);  /* Test on EV6 and clear it */  sEETimeout = sEE_FLAG_TIMEOUT;  while(!I2C_CheckEvent( I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  } #ifdef sEE_M24C64_32  /* Send the EEPROM's internal address to read from: MSB of the address first */  I2C_SendData( (uint8_t)((ReadAddr & 0xFF00) >> 8));      /* Test on EV8 and clear it */  sEETimeout = sEE_FLAG_TIMEOUT;  while(!I2C_CheckEvent( I2C_EVENT_MASTER_BYTE_TRANSMITTED))  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  }#endif /* sEE_M24C64_32 */  /* Send the EEPROM's internal address to read from: LSB of the address */  I2C_SendData( (uint8_t)(ReadAddr & 0x00FF));      /* Test on EV8 and clear it */  sEETimeout = sEE_FLAG_TIMEOUT;  while(I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET)  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  }    /* Send START condition a second time */    I2C_GenerateSTART( ENABLE);    /* Test on EV5 and clear it (cleared by reading SR1 then writing to DR) */  sEETimeout = sEE_FLAG_TIMEOUT;  while(!I2C_CheckEvent( I2C_EVENT_MASTER_MODE_SELECT))  {    if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();  }     /* Send EEPROM address for read */  I2C_Send7bitAddress((uint8_t)sEEAddress, I2C_DIRECTION_RX);  if ((uint16_t)(NumByteToRead)> 2)  {    sEETimeout = sEE_FLAG_TIMEOUT;    while(!I2C_GetFlagStatus( I2C_FLAG_ADDRESSSENTMATCHED))    {      if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();    }     I2C->SR3;    /* Read data from first byte until byte N-3 */    while ((uint16_t)(NumByteToRead)> 3)       {                        /* Poll on BTF */        sEETimeout = sEE_FLAG_TIMEOUT;        while (I2C_GetFlagStatus( I2C_FLAG_TRANSFERFINISHED) == RESET)        {          if((sEETimeout--) == 0) return sEE_TIMEOUT_UserCallback();        }           /* Read a byte from the EEPROM */        *pBuffer = I2C_ReceiveData();          /* Point to the next location where the byte read will be saved */        pBuffer++;          /* Decrement the read bytes counter */        (uint16_t)(NumByteToRead)--;      }  //}  /*  Remains three data for read: data N-2, data N-1, Data N */  /* Three Bytes Master Reception procedure (POLLING) ------------------------*/ // if ((uint16_t)(*NumByteToRead) == 3)    //{//.........这里部分代码省略.........
开发者ID:faithsws,项目名称:Kit,代码行数:101,


示例16: 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();            /* a = */ 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	    /*a = */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++] = I2C_ReceiveData(I2Cx);    //read data N-2                I2C_GenerateSTOP(I2Cx, ENABLE); //program the Stop                final_stop = 1; //reuired to fix hardware                read_p[index++] = I2C_ReceiveData(I2Cx);    //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++] = I2C_ReceiveData(I2Cx);    //read data N-1                read_p[index++] = I2C_ReceiveData(I2Cx);    //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            }        }        //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++] = I2C_ReceiveData(I2Cx);        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            I2C_SendData(I2Cx, 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++;            I2C_SendData(I2Cx, 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        //Completion Tasks go here        //End of completion tasks        subaddress_sent = 0;    //reset this here        // I2Cx->CR1 &= ~0x0800;   //reset the POS bit so NACK applied to the current byte        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:kh4,项目名称:openLRSngRX32_test,代码行数:101,


示例17: i2c_byte_read

int i2c_byte_read(i2c_t *obj, int last){    I2cHandle = (I2C_TypeDef *)(obj->i2c);    return I2C_ReceiveData(I2cHandle, last);}
开发者ID:jsunderland,项目名称:mbed,代码行数:6,


示例18: receive_i2c

ErrorStatus receive_i2c(I2C_TypeDef * I2Cx, uint8_t * RxBuffer, uint8_t slave_address, uint8_t package_size){	static uint32_t Timeout;	uint8_t TxCounter = 0;	uint16_t i2c_error = 0;	__disable_irq();	/* While the bus is busy */	Timeout = 0xFFF;	/* While the bus is busy */	while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))	{        if (Timeout-- == 0)        {        	i2c_error_code = BUSY;			i2c_error = 1;			break;        }	}	if(i2c_error == 0)	{		/* Send I2Cx START condition */		I2C_GenerateSTART(I2Cx, ENABLE);		Timeout = 0xFFF;		/* Test on I2Cx EV5 and clear it */		while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))		{			if (Timeout-- == 0)			{	        	i2c_error_code = NOT_MASTER;				i2c_error = 1;				break;			}		}	}	if(i2c_error == 0)	{		/* Send slave Address for write */		I2C_Send7bitAddress(I2Cx, slave_address, I2C_Direction_Receiver);		Timeout = 0xFF;		/* wait for acknowledge bit */		while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))		{	        if (Timeout-- == 0)	        {	        	i2c_error_code = NO_ACKNOWLEDGEMENT;				i2c_error = 1;				break;	        }		}	}	if(i2c_error == 0)	{		while(TxCounter!=package_size-1)		{				Timeout = 0xFFFF;				while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED ))				{					if (Timeout-- == 0)					{						i2c_error_code = DATA_NOT_RECEIVED;						i2c_error = 1;						break;					}				}				/* Receive some data */				RxBuffer[TxCounter++] = I2C_ReceiveData(I2Cx);		}	}	I2C_AcknowledgeConfig(I2Cx, DISABLE);	if(i2c_error == 0)	{		/* Send I2Cx STOP Condition */		I2C_GenerateSTOP(I2Cx, ENABLE);		Timeout = 0xFFFF;		while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED ))		{			if (Timeout-- == 0)			{	        	i2c_error_code = DATA_NOT_RECEIVED;				i2c_error = 1;			}		}		/* Receive some data */		RxBuffer[TxCounter++] = I2C_ReceiveData(I2Cx);	}//.........这里部分代码省略.........
开发者ID:alecjacobson,项目名称:puppet,代码行数:101,


示例19: main

//.........这里部分代码省略.........  /* Test on EV6 and clear it */  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));  /* Repeated Start */  I2C_GenerateSTART(ENABLE);  /* Test on EV5 and clear it */  while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));  /* Send Header to Slave for Read */  I2C_SendData(HEADER_ADDRESS_Read);  /* Test on EV6 and clear it */  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));#else  /* Send slave Address for write */  I2C_Send7bitAddress(SLAVE_ADDRESS, I2C_DIRECTION_RX);  /* Test on EV6 and clear it */  while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));#endif /* TEN_BITS_ADDRESS */  /* While there is data to be read */  while (NumByteToRead)  {#ifdef SAFE_PROCEDURE    if (NumByteToRead != 3) /* Receive bytes from first byte until byte N-3 */    {      while ((I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET)); /* Poll on BTF */      /* Read a byte from the Slave */      RxBuffer[Rx_Idx] = I2C_ReceiveData();      /* Point to the next location where the byte read will be saved */      Rx_Idx++;      /* Decrement the read bytes counter */      NumByteToRead--;    }    if (NumByteToRead == 3)  /* it remains to read three data: data N-2, data N-1, Data N */    {      /* Data N-2 in DR and data N -1 in shift register */      while ((I2C_GetFlagStatus(I2C_FLAG_TRANSFERFINISHED) == RESET)); /* Poll on BTF */      /* Clear ACK */      I2C_AcknowledgeConfig(I2C_ACK_NONE);      /* Disable general interrupts */      disableInterrupts();      /* Read Data N-2 */      RxBuffer[Rx_Idx] = I2C_ReceiveData();      /* Point to the next location where the byte read will be saved */      Rx_Idx++;      /* Program the STOP */      I2C_GenerateSTOP(ENABLE);      /* Read DataN-1 */      RxBuffer[Rx_Idx] = I2C_ReceiveData();      /* Enable General interrupts */
开发者ID:MbedTinkerer,项目名称:STM8teach,代码行数:67,


示例20: UB_I2C3_ReadByte

//--------------------------------------------------------------// Auslesen einer Adresse per I2C von einem Slave// slave_adr => I2C-Basis-Adresse vom Slave// adr       => Register Adresse die gelesen wird//// Return_wert ://  0...255 , Bytewert der gelesen wurde//  < 0     , Error//--------------------------------------------------------------int16_t UB_I2C3_ReadByte(uint8_t slave_adr, uint8_t adr){  int16_t ret_wert=0;  uint32_t timeout=I2C3_TIMEOUT;  // Start-Sequenz  I2C_GenerateSTART(I2C3, ENABLE);    timeout=I2C3_TIMEOUT;  while (!I2C_GetFlagStatus(I2C3, I2C_FLAG_SB)) {    if(timeout!=0) timeout--; else return(P_I2C3_timeout(-1));  }  // ACK disable  I2C_AcknowledgeConfig(I2C3, DISABLE);  // Slave-Adresse senden (write)  I2C_Send7bitAddress(I2C3, slave_adr, I2C_Direction_Transmitter);   timeout=I2C3_TIMEOUT;  while (!I2C_GetFlagStatus(I2C3, I2C_FLAG_ADDR)) {    if(timeout!=0) timeout--; else return(P_I2C3_timeout(-2));  }    // ADDR-Flag l
C++ I2C_Send7bitAddress函数代码示例
C++ I2C_Read函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。