#include <inttypes.h>
#include <compat/twi.h>
#include "serial.h"
#include "i2cmaster.h"
#include <avr/interrupt.h>  
#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>




/* define CPU frequency in Mhz here if not defined in Makefile */
#ifndef F_CPU
#define F_CPU 16000000UL
#endif

/* I2C clock in Hz */
#define SCL_CLOCK  100000L
#define  adr_w 0xEE
#define  adr_r 0xEF
#define  comconv 0x40
#define  comred 0x00
#define  comres 0x1E


FILE mystdout = FDEV_SETUP_STREAM(sendchar, NULL, _FDEV_SETUP_WRITE);

int  main(void)
{
unsigned char data1;
unsigned char data2;
unsigned char data3;

inituart();
 stdout = &mystdout;      


i2c_init();

								

//RESET:
i2c_start_wait(adr_w);
printf("%s\n","1");							
i2c_write(comres);
i2c_stop();
printf("%s\n","2");

								

//CONVERSION:
i2c_start_wait(adr_w);
printf("%s\n","3");								
i2c_write(comconv);
i2c_stop();
_delay_ms(3);
printf("%s\n","4");

							

//BEFORE_READ:
i2c_start_wait(adr_w);
printf("%s\n","5");								
i2c_write(comred);
i2c_stop();
printf("%s\n","6");

								

//READ_DATA:
i2c_start_wait(adr_r);
printf("%s\n","7");
data1=i2c_readAck();
printf("%s\n","8");
data2=i2c_readAck();
data3=i2c_readNak();
i2c_stop();


	
printf("%c %c %c \n", data1,data2,data3);

 }



