/*
 * device.cpp
 *
 * Created: 25. 5. 2017 22:25:56
 *  Author: User
 */ 

 #include <avr/io.h>
 #include <avr/interrupt.h>
 #include "comm.hpp"
 #include "device.hpp"

 void Device_init (void)
 {
	 ResetIO(); // Reset I/O to safe vales
	 TWI_init(); // Initialize I2C for communication with sensors
	 UART_init(9600); // Initialize serial (RS-485) communication with master device
	 sei(); // Enable global interrupts (for correct function must be placed after TWI and UART initialization)
 }

 void ResetIO (void) // Always use as first initialization (changes all I/O bits to safe levels)
 {
	 DDRB = 0b00000000;
	 PORTB = 0b01111111;

	 DDRC = 0b00001000;
	 PORTC = 0b00000111;

	 DDRD = 0b11100010;
	 PORTD = 0b00010000;
 }