Esempio n. 1
0
UInt32 getBufferFromI2C0(UInt8 addr, UInt8 *buffer, UInt32 len)
{
    UInt32 i;
    UInt8 status;
    UInt8 *ptr;

    ptr = buffer;
    if( i2c0_start()!=I2C_OK)
    {
        //DebugPrintf("GetBufferFromI2C0.i2c0_start I2C_ERROR\r\n");
        //i2c0_stop();
        return I2C_ERROR;
    }

    addr = addr|1;
    while( i2c0_write(addr) == I2C_BUSY);

    for(i=0;i<len;i++)
    {
        while(1)
        {
            GET_I2C_STATUS();

            /*
             * SLA+R transmitted, ACK received or
             * SLA+R transmitted, ACK not received
             * data byte received in master mode, ACK transmitted
             */
            if((status == 0x40 ) || (status == 0x48 ) || (status == 0x50 ))
            {
                if(i==len-1)
                {
                        SEND_NACK();
                }
                else
                {
                        SEND_ACK();
                }

                while(i2c0_read(ptr)==I2C_EMPTY);

                ptr++;
                break;

            }
            else if(status != 0xf8 )
            {
                i2c0_stop();
                //DebugPrintf("GetBufferFromI2C0 I2C_ERROR\r\n");
                return I2C_ERROR;
            }

        }//while(1)
    }//for

    i2c0_stop();

    return I2C_OK;
}
Esempio n. 2
0
/**
 * Returns raw data from sensor
 *
 * @param adr adress of sensor
 * @return Data from sensor
 */
signed int lm75_get_temp_raw(unsigned char adr)
{
	unsigned char a[2];
	i2c0_start(adr);
	i2c0_receive(a, 2);
	i2c0_stop();
	return ((a[0] << 8) | a[1]) >> 7;
}
Esempio n. 3
0
UInt32 sendBufferToI2C0(UInt8 addr, UInt8 *buffer, UInt32 len)
{
    UInt32 i;
    //send start condition
    if(i2c0_start()!=I2C_OK)
    {
        //i2c0_stop();
        //DebugPrintf("SendBufferToI2C0.i2c0_start\r\n");
            return I2C_ERROR_START;
    }

    //send address
    SEND_AND_WAIT(addr);

    for(i=0;i<len;i++)
    {
            SEND_AND_WAIT(buffer[i]);
    }

    i2c0_stop();

    //DebugPrintf("SendBufferToI2C0 I2C_OK\r\n");
    return I2C_OK;
}