I2C read data from sensor (SHT21)

hello all,
i’m beginner at atmega so i want to know how to use I2C in order to get data from sensor and post it to the uart.

please ! here is my main program:
`
int main(void)

{

unsigned char ret;
DDRG  |=(1<<PG2);                              // use pins 2 on port G  for output 

                           // (active low LED's )

DDRD |=(1<<PD0);
DDRD |=(1<<PD1);
PORTD |=(1<<PD0);
PORTD |=(1<<PD1);

i2c_init();                                // init I2C interface

USART_Init(MYUBRR);
char c,k='U' ;
int dec;

while(1)
{
for(c=‘a’;c<=‘z’;c++) USART_Transmit©;
// PORTG |=(1<<PG2);
/* write 0x75 to eeprom address 0x05 (Byte Write) */

ret = i2c_start(ShT21+I2C_WRITE);       // set device address and write mode

if ( ret ) {

    /* failed to issue start condition, possibly no device found */

    i2c_stop();

PORTG &=~(1<<PG2); // desactivate all 8 LED to show error */
}
else {
PORTG |=(1<<PG2); // output byte on the LED’s
_delay_ms(1000);

    /* issuing start condition ok, device accessible */

    i2c_write(0xE6);                       // write address = E6 temperature
    i2c_write(0xE3);                       // ret=0 -> Ok, ret=1 -> no ACK 

    i2c_stop();                            // set stop conditon = release bus



    /* write ok, read value back from eeprom address 0x05, wait until 
       the device is no longer busy from the previous write operation */

    i2c_start_wait(ShT21+I2C_WRITE);     // set device address and write mode

    i2c_write(0xE6);                        // write address = E6

    i2c_rep_start(ShT21+I2C_READ);       // set device address and read mode

    ret = i2c_readNak();                    // read one byte
    PORTG &=~(1<<PG2);
   // _delay_ms(1000);
    i2c_stop();

  USART_Transmit(printf("%d",ret));

// dec=convToDec(ret);
// USART_Transmit(printf("%d",dec));

   }

//twi_match_write_slave();

} }

`

I think you are posting on the wrong forum

Sorry i’m new on this forum

Maybe you should ask the question on an Arduino related forum (they work with atmega and many projects are based on the SHT21).

The reference code example provided by Sensiron is here : http://www.google.ch/url?sa=t&rct=j&q=&esrc=s&source=web&cd=5&ved=0CFsQFjAE&url=http%3A%2F%2Fwww.sensirion.com%2Fnc%2Fen%2Fproducts%2Fhumidity-temperature%2Fdownload-center%2F%3Fcid%3D880%26did%3D102%26sechash%3Dc204b9cc&ei=vDmWUbKMIYajPYOQgUg&usg=AFQjCNFjabrMVBCZuI0SsAQfFuZziUiXwg&sig2=oSDFwtOBCSVTr9s3IyKwig&bvm=bv.46471029,d.ZWU&cad=rja. It should help you.