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


C++ I2C_delay函数代码示例

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


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

示例1: lib_i2c_write

/*************************************************************************
 Send one byte to I2C device
 
 Input:    byte to be transfered
 Return:   0 write successful 
           1 write failed
*************************************************************************/
unsigned char lib_i2c_write(unsigned char data)
{
    int i = 8;
    // transmit byte
    while (i--) {
        SCL_L;
        I2C_delay();
        if (data & 0x80)
            SDA_H;
        else
            SDA_L;
        data <<= 1;
        I2C_delay();
        SCL_H;
        I2C_delay();
    }
    SCL_L;

    if (lib_i2c_waitack()) {
        lib_i2c_stop();
        return 1;
    }

    return 0;
}
开发者ID:Mattnez,项目名称:bradwii-X4,代码行数:32,代码来源:lib_i2c.c

示例2: I2C_gen_start

uint8_t I2C_gen_start(void) {
	// Release SCL
	I2C_PORT |= (1<<I2C_SCL);
	while(!(I2C_PORT & (1<<I2C_SCL))) ;
	#ifdef I2C_FAST_MODE
	I2C_delay(I2C_T2);
	#else
	I2C_delay(I2C_T1);
	#endif

	// Generate start condition
	I2C_PORT &= ~(1<<I2C_SDA);
	I2C_delay(I2C_T2);
	I2C_PORT &= ~(1<<I2C_SCL);
	I2C_PORT |=  (1<<I2C_SDA);

	#ifdef SIGNAL_VERIFY
	// Check that the start condition was detected
	if (!(USISR & (1<<USISIF))) {
		I2C_state.errorState = I2C_ERR_MISSING_START_CON;
		return FALSE;
	}
	#endif
	return TRUE;
}
开发者ID:Luden,项目名称:main,代码行数:25,代码来源:USI_I2C.c

示例3: I2C_Start

BUS_Status I2C_Start(void)
{

    //before: SCL=H SDA=H,means bus is free
	SDA_H;			//1
	SCL_H;			//2
    I2C_delay();	//3
	
	if(!(SDA_read))
	{
        ERROR_MACRO(IIC_DEV,I2C_Start_ERROR_BUS_BUSY);
		return BUS_BUSY;
	}

	SDA_L;			//4
	I2C_delay();	//5

//	SDA_L;			//6
//	I2C_delay();	//7
	
	if(SDA_read)
	{
        ERROR_MACRO(IIC_DEV,I2C_Start_ERROR_BUS_ERROR);
		return BUS_ERROR;
	}

    SCL_L;

    //After: SCL=L SDA=L
	
	return BUS_READY;
}
开发者ID:reynoldxu,项目名称:DWM,代码行数:32,代码来源:I2C_soft.c

示例4: I2C_Wr

//////////////////////////////////////////////////////////////////////
// Returns 0 for no errors = the ACK bit from the slave
unsigned short I2C_Wr(unsigned short data) {
  unsigned short ret=0,i;

   // grab the data
   for(i = 0; i < 8; i++) {
   
      I2C_SCL_0; // Clock low
      if (data & 0x80) I2C_SDA_1; else I2C_SDA_0; // Data output
      data <<= 1;   // Next data bit.
      I2C_delay();  // low T/2.
      
      I2C_SCL_1;    // Clock released to high.
      I2C_delay();  // high T/2.
   }

   // get ACK or NACK
   I2C_SCL_0;
   I2C_SDA_1;    // Release the  data line
   SET_PIN_INPUT(I2C_SDA_PIN);
   I2C_delay();  // low T/2.
   
   I2C_SCL_1;
   // Sample the ACK
   ret = I2C_SDA_IN;
   I2C_delay();  // high T/2.
   
   I2C_SCL_0;    // Return clock to safe state
   SET_PIN_OUTPUT(I2C_SDA_PIN);

   return ret;
}
开发者ID:BackupTheBerlios,项目名称:uwsdr-svn,代码行数:33,代码来源:I2C.c

示例5: I2C_WaitAck

BUS_ACK_Status I2C_WaitAck(void)
{
    //等待ACK应该是在发送完数据之后,所以之前:
    //    SCL=H  SDA=DATA
    unsigned char ucErrTime=0;
	
    //SDA_H;SDA_H;SDA_H;I2C_delay();           //初始化数据是NACK,不能拉低!
    SCL_L;          //假设你是从机->SCL=L时更新数据,SDA=H时数据是保持的
    I2C_delay();    //保持一下
    //while(1);


    SCL_H;          //此时拉高SCL,于是从机的数据应该是保持的
    I2C_delay();    //等待数据就位

    while(SDA_read)//读到H->NACK,适当等待
	{
		ucErrTime++;
        if(ucErrTime>=50)//一小段时间后还是NACK->是NACK
        {
            //ERROR_MACRO(IIC_DEV,I2C_ERROR_BUS_NACK);
            printf("NoACK\r\n");
            //此时SCL=H SDA =H,直接STOP
            I2C_Stop();
            return BUS_NACK;
        }
	}
    SCL_L;      //拉低SCL,保持总线BUSY
    SDA_H;      //更具I2C协议P10SDA应该在SCL变为L之后拉高
    I2C_delay();

    //SCL=L SDA=ACK/NACK
    return BUS_ACK;
}
开发者ID:reynoldxu,项目名称:DWM,代码行数:34,代码来源:I2C_soft.c

示例6: I2C_ReceiveByte

unsigned char I2C_ReceiveByte(void)  //数据从高位到低位//
{ 
    unsigned char i=8;
    unsigned char ReceiveByte=0x00;

    while(i--)
    {
      ReceiveByte<<=1;      
      SCL_L;I2C_delay();
      SCL_H;//给出一个上升沿,使设备输出SDA数据
      I2C_delay();//保证数据从设备中输出了
      if(SDA_read)
      {
        ReceiveByte|=0x01;
      }
      I2C_delay();
    }

    SCL_L;
    //SDA_L;
    //I2/C_delay();I2C_delay();I2C_delay();I2C_delay();
    //I2C_delay();I2C_delay();I2C_delay();I2C_delay();

    return ReceiveByte;
}
开发者ID:reynoldxu,项目名称:DWM,代码行数:25,代码来源:I2C_soft.c

示例7: I2C_byte_xfer

// Run the shift register until the counter overflows
// Function resets SDA line to output on return
uint8_t I2C_byte_xfer(uint8_t reg) {
	// Preset counter
	USISR = reg;
	// Setup control register for clock strobe
	reg = (1<<USIWM1) | (1<<USICS1) | (1<<USICLK) | (1<<USITC);

	do {
		I2C_delay(I2C_T1);
		// Positive edge
		USICR = reg;
		// Wait for clock stretching
		while (!(I2C_PIN & (1<<I2C_SCL))) ;
		I2C_delay(I2C_T2);
		// Negative edge
		USICR = reg;
	} while (!(USISR & (1<<USIOIF)));

	I2C_delay(I2C_T1);
	// Save shift register
	reg = USIDR;
	// Release SDA
	USIDR = 0xFF;
	// Set SDA as output
	I2C_DDR |= (1<<I2C_SDA);

	return reg;
}
开发者ID:Luden,项目名称:main,代码行数:29,代码来源:USI_I2C.c

示例8: IIC_NAck

//不产生ACK应答		    
static void IIC_NAck(void)
{
	SDA_OUT();
	IIC_SDA(1);
	IIC_SCL(1);
    I2C_delay();
	IIC_SCL(0);
	I2C_delay();
}					 	
开发者ID:dammstanger,项目名称:FCU_UCOSII150617,代码行数:10,代码来源:I2C_1.c

示例9: IIC_Stop

//产生IIC停止信号
static void IIC_Stop(void)
{
	SDA_OUT();//sda线输出
	IIC_SDA(0);//STOP:when CLK is high DATA change form low to high
	IIC_SCL(1); 
	I2C_delay();
	IIC_SDA(1);//发送I2C总线结束信号
	I2C_delay();
}
开发者ID:dammstanger,项目名称:FCU_UCOSII150617,代码行数:10,代码来源:I2C_1.c

示例10: I2C_Stop

/*******************************************************************************
* Function Name  : I2C_Stop
* Description    : None
* Input          : None
* Output         : None
* Return         : None
* Attention		 : None
*******************************************************************************/
static void I2C_Stop(void)
{
	SDA_L;
	I2C_delay();
	SCL_H;
	I2C_delay();
	SDA_H;
	I2C_delay();
}
开发者ID:12019,项目名称:stm32-camera,代码行数:17,代码来源:SCCB.c

示例11: lib_i2c_stop

/*************************************************************************
Terminates the data transfer and releases the I2C bus
*************************************************************************/
void lib_i2c_stop(void)
{
    SCL_L;
    I2C_delay();
    SDA_L;
    I2C_delay();
    SCL_H;
    I2C_delay();
    SDA_H;
    I2C_delay();
}
开发者ID:Mattnez,项目名称:bradwii-X4,代码行数:14,代码来源:lib_i2c.c

示例12: I2C_Stop

/**************************************
*	I2Cstop:keep SCL high, SDA low to high
*           ________________
*	SCL:
*                    ______
*	SDA:      ________/
*	函数返回时:SDA,SCL均为高电平
***************************************/
void I2C_Stop(void)
{
	SCL_L;
	I2C_delay();
	
	SDA_L;
	I2C_delay();
	SCL_H;
	I2C_delay();
	SDA_H;
}
开发者ID:MaxStudio,项目名称:GPS_TRACER_CODE,代码行数:19,代码来源:user_i2c.c

示例13: I2C_ACK

void I2C_ACK()
{
  SCL_L;
  I2C_delay();
  SDA_L;
  I2C_delay();
  SCL_H;
  I2C_delay();
  SCL_L;
  I2C_delay();
}
开发者ID:bsmr-multicopter,项目名称:mbtx,代码行数:11,代码来源:i2c_ee.cpp

示例14: I2C_STOP

void I2C_STOP()
{
  SCL_L;
  I2C_delay();
  SDA_L;
  I2C_delay();
  SCL_H;
  I2C_delay();
  SDA_H;
  I2C_delay();
}
开发者ID:bsmr-multicopter,项目名称:mbtx,代码行数:11,代码来源:i2c_ee.cpp

示例15: i2c_read_bit

unsigned char i2c_read_bit(void) {
	unsigned char bit;
	read_SDA();
	I2C_delay();
	while (read_SCL() == 0); // Clock stretching
	bit = read_SDA();
	I2C_delay();
	clear_SCL();
	I2C_delay();
	return bit;
}
开发者ID:JorgeGzm,项目名称:JAGA,代码行数:11,代码来源:hal_i2c_virtual.c


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