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

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

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

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

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

示例1: 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 */  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_RX, (uint8_t*)LM75_BufferRX, 2);      /* Enable DMA NACK automatic generation */  I2C_DMALastTransferCmd(LM75_I2C, ENABLE);    /* 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))   {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Send device address for write */  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();  }    /* Send the device's internal address to write to */  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();  }    /* Send START condition a second time */    I2C_GenerateSTART(LM75_I2C, ENABLE);    /* Test on SB Flag */  LM75_Timeout = LM75_FLAG_TIMEOUT;  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))   {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Send LM75 address for read */  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);    /* Test on ADDR Flag */  LM75_Timeout = LM75_FLAG_TIMEOUT;  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))     {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Enable I2C DMA request */  I2C_DMACmd(LM75_I2C,ENABLE);    /* Enable DMA RX Channel */  DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);    /* Wait until DMA Transfer Complete */  LM75_Timeout = LM75_LONG_TIMEOUT;  while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))  {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }            /* Send STOP Condition */  I2C_GenerateSTOP(LM75_I2C, ENABLE);    /* Disable DMA RX Channel */  DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);    /* Disable I2C DMA request */    I2C_DMACmd(LM75_I2C,DISABLE);    /* Clear DMA RX Transfer Complete Flag */  DMA_ClearFlag(LM75_DMA_RX_TCFLAG);  //.........这里部分代码省略.........
开发者ID:91thUb,项目名称:usb-miner,代码行数:101,


示例2: I2C_RandRead

int I2C_RandRead(uint8_t slave,uint16_t addr,uint8_t addrsize,void *pbuffer,uint16_t len){struct i2c_job_st i2c_jobs[2];uint8_t buf_offset[2];	xSemaphoreTake(xSemaphoreI2C_Mutex,portMAX_DELAY);	if (I2C_isBusy())	{		i2c_error_flags = I2C_SR1_SB;		xSemaphoreGive(xSemaphoreI2C_Mutex);		return FALSE;	}	i2c_cntr = 0;	i2c_oper = I2C_Direction_Transmitter;	job = i2c_jobs;	i2c_addr = slave << 1;	memset(i2c_jobs,0,sizeof(i2c_jobs));	if (addrsize == 1)		buf_offset[0] = (uint8_t)addr;	else	{		buf_offset[0] = (uint8_t)(addr >> 8);		buf_offset[1] = (uint8_t)(addr & 0xff);	}	i2c_jobs[0].buf = buf_offset;	i2c_jobs[0].len = addrsize;	i2c_jobs[0].dir = I2C_Direction_Transmitter;	i2c_jobs[1].buf = (uint8_t *)pbuffer;	i2c_jobs[1].len = len;	i2c_jobs[1].dir = I2C_Direction_Receiver;	i2c_jobs[1].last = TRUE;	i2c_error_flags = 0;	i2c_done = i2c_err = FALSE;	// clear the semaphore	while (xSemaphoreTake(xSemaphoreI2C_Work,0));	I2C_AcknowledgeConfig(I2Cx,ENABLE);	I2C_NACKPositionConfig(I2Cx,I2C_NACKPosition_Current);	I2C_ITConfig(I2Cx,I2C_IT_BUF | I2C_IT_ERR | I2C_IT_EVT,ENABLE);	/* Send START condition */	I2C_GenerateSTART(I2Cx, ENABLE);	while (!i2c_done && !i2c_err)	{		if (!xSemaphoreTake(xSemaphoreI2C_Work,SEMA_DELAY))		{			I2C_Open(0);			i2c_err = TRUE;			break;		}	}	I2C_ITConfig(I2Cx,I2C_IT_BUF | I2C_IT_ERR | I2C_IT_EVT,DISABLE);	xSemaphoreGive(xSemaphoreI2C_Mutex);	return !i2c_err;}
开发者ID:pandc,项目名称:unitek,代码行数:64,


示例3: LM75_ReadReg

/**  * @brief  Read the specified register from the LM75.  * @param  RegName: specifies the LM75 register to be read.  *              This member can be one of the following values:    *                  - LM75_REG_TEMP: temperature register  *                  - LM75_REG_TOS: Over-limit temperature register  *                  - LM75_REG_THYS: Hysteresis temperature register  * @retval LM75 register value.  */uint16_t LM75_ReadReg(uint8_t RegName){     uint8_t LM75_BufferRX[2] ={0,0};  uint16_t tmp = 0;         /* 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_RX, (uint8_t*)LM75_BufferRX, 2);      /* Enable DMA NACK automatic generation */  I2C_DMALastTransferCmd(LM75_I2C, ENABLE);    /* 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))   {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Send device address for write */  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();  }    /* Send the device's internal address to write to */  I2C_SendData(LM75_I2C, RegName);      /* 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();  }    /* Send START condition a second time */    I2C_GenerateSTART(LM75_I2C, ENABLE);    /* Test on SB Flag */  LM75_Timeout = LM75_FLAG_TIMEOUT;  while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))   {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Send LM75 address for read */  I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);    /* Test on ADDR Flag */  LM75_Timeout = LM75_FLAG_TIMEOUT;  while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))     {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }    /* Enable I2C DMA request */  I2C_DMACmd(LM75_I2C,ENABLE);    /* Enable DMA RX Channel */  DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);    /* Wait until DMA Transfer Complete */  LM75_Timeout = LM75_LONG_TIMEOUT;  while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))  {    if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();  }            /* Send STOP Condition */  I2C_GenerateSTOP(LM75_I2C, ENABLE);    /* Disable DMA RX Channel */  DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);    /* Disable I2C DMA request */    I2C_DMACmd(LM75_I2C,DISABLE);    /* Clear DMA RX Transfer Complete Flag *///.........这里部分代码省略.........
开发者ID:burakagca,项目名称:ARMWork,代码行数:101,


示例4: 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            }        }        // 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:363546178,项目名称:baseflight,代码行数:101,


示例5: I2C_ByteRead

ErrorStatus I2C_ByteRead(uint8_t I2C_Addrs,uint8_t ReadAddr,uint8_t Data_Buffer[],uint8_t Number_Bytes_to_Read){	uint8_t i=0;	ErrorStatus	status=ERROR;	while(i<=7)	{		switch(i)		{			case 0:			  	i++;		//Pass				I2C_Time_Out_Counter=I2C_Time_Out;#ifdef	I2C_By_Function_Base				while(I2C_GetFlagStatus(I2C_FLAG_BUSBUSY))	//Line busy#else				while(I2C->SR3 & 0x02)						//等待
C++ I2C_GenerateSTOP函数代码示例
C++ I2C_DeInit函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。