//------------------------------------------------------------------------------
// Function: SendAddr
// Description:
//------------------------------------------------------------------------------
static uint8_t I2CSendAddr(uint8_t addr, uint8_t read)
{
    volatile uint8_t x = 0;    //delay variable

    //generate START condition
    SET_SCL();
		#if 0
		if(GET_SCL)
			 TX_DEBUG_PRINT(("GET_SCL is high rightly \n"));
		else
			TX_DEBUG_PRINT(("GET_SCL is low wrong\n"));
		#endif
    x++;            //short delay to keep setup times in spec
    CLEAR_SDA();
		#if 0
		if(!GET_SDA)
			 TX_DEBUG_PRINT(("GET_SDA is low rightly\n"));
		else
			TX_DEBUG_PRINT(("GET_SDA is high wrong\n"));
		#endif
    x++;
    x++;
    x++;
    CLEAR_SCL();
		#if 0
		if(!GET_SCL)
			 TX_DEBUG_PRINT(("GET_SCL is low rightly\n"));
		else
			TX_DEBUG_PRINT(("GET_SCL is high wrong\n"));
		#endif
    x++;

    return (I2CSendByte(addr|read));  //send address uint8_t with read/write bit
}
//------------------------------------------------------------------------------
// Function: SetSCLHigh
// Description:
//------------------------------------------------------------------------------
static uint8_t SetSCLHigh(void)
{
    volatile uint8_t x = 0;    //delay variable
    uint32_t timeout = 0;
	
    // set SCL high, and wait for it to go high in case slave is clock stretching
    SET_SCL();
    x++;
    x++;
    x++;
    x++;

    while (!GET_SCL())
    {
        /* do nothing - just wait */
	//udelay(2);
	timeout++;
	    if( timeout > 100000 )   // about 1s is enough
	{
		printk("\n ************IIC SCL low timeout...\n");
		return IIC_SCL_TIMEOUT;
	}
    }
	
    return IIC_OK;
}
Beispiel #3
0
void WriteToAD5422(unsigned char count,unsigned char *buf)
{ 
    unsigned    char    ValueToWrite = 0;
    unsigned    char    i = 0;
    unsigned    char    j = 0;


    CLR_LATCH();

    for ( i=count;i>0;i-- )
    {
        ValueToWrite =  *(buf+i-1);
        for (j=0; j<8; j++)
        {
            CLR_SCL();
            if (0x80 == (ValueToWrite & 0x80))
            {
                SET_SDO();      /* Send one to SDIN pin of AD5422*/
            }
            else
            {
                CLR_SDO();      /* Send zero to SDIN pin of AD5422*/
            }

            delay(1);
            SET_SCL();
            delay(1);
            ValueToWrite <<= 1; /* Rotate data*/   
        }  
    }
    CLR_SCL();
    delay(1);
    SET_LATCH();
    delay(20);
}