Exemple #1
0
/*********************************************************************
* Function:       getsI2C()
* Input:		array pointer, Length.
* Overview:		read Length number of Bytes into array
********************************************************************/
unsigned int getsI2C(unsigned char *rdptr, unsigned char Length)
{
	while (Length --)
	{
		*rdptr++ = getI2C();		//get a single byte
		
		if(I2C1STATbits.BCL)		//Test for Bus collision
		{
			return(-1);
		}

		if(Length)
		{
			AckI2C();				//Acknowledge until all read
		}
	}
	return(0);
}
Exemple #2
0
/*
 *   Gyro i2c interface, Read/Write
 */
UINT8 Gyro_I2C_R(UINT8 Address)
{
    UINT8 Data;
    IdleI2C();                              //wait for bus Idle
    StartI2C();                             //Generate Start Condition
    WriteI2C(Gyro_MPU6050_Address);         //Write Control Byte
    IdleI2C();                              //wait for bus Idle
    WriteI2C(Address);                      //Write start address
    IdleI2C();                              //wait for bus Idle

    RestartI2C();                           //Generate restart condition
    WriteI2C(Gyro_MPU6050_Address | 0x01);  //Write control byte for read
    IdleI2C();                              //wait for bus Idle

    Data = getI2C();                        //read Length number of bytes
    NotAckI2C();                            //Send Not Ack
    StopI2C();                              //Generate Stop

    return Data;
}