/*
 * tc74.c
 *
 * Created: 17.4.2020 12:26:37
 *  Author: Martin Košút
 */ 

#include <avr/io.h>
#include "tc74.h"
#include "twi.h"

int8_t read_temperature(uint8_t senzor_address)
{
	uint8_t status;
	int8_t temperature = -100;
	
	status = twi_start((senzor_address<<1) + TWI_WRITE);	//start communication + write 0x00 which represents address of temperature register
	if(status == 0)
	{
		twi_write(0x00);
	}
	twi_stop();
	status = twi_start((senzor_address<<1) + TWI_READ);		//read 0x00 temperature register
	if(status == 0)
	{
		temperature = twi_read_nack();
	}
	twi_stop();
	return temperature;										//return measured temperature
}

