8160ac2e7ef9d330dacbcb56b4cd21c1503e7c19
[owSlave2.git] / common / I2C / MAX1164x.h.c
1 #define F_CPU 8000000UL
2 #include <avr/io.h>
3 #include <avr/interrupt.h>
4 #include <util/delay.h>
5 #include <avr/wdt.h>
6 #include <avr/sleep.h>
7 #include "USI_TWI_Master.h"
8 #include "MAX1164x.h"
9
10 void MAX1164x_init(){
11         
12         
13 }
14 void MAX1164x_config(uint8_t setup,uint8_t config){
15         I2c_StartCondition();
16         I2c_WriteByte (0b01101100);
17         I2c_WriteByte (setup|0x80);
18         I2c_WriteByte (config);
19         I2c_StopCondition();
20         
21 }
22 int16_t MAX1164x_read() {
23         uint16_t res;
24         I2c_StartCondition();
25         I2c_WriteByte (0b01101101);
26         //DDR_USI&=~(1<<PIN_USI_SCL);
27         //while ((PIN_USI&(1<<PIN_USI_SCL))==0);
28         //DDR_USI|=(1<<PIN_USI_SCL);
29         _delay_us(80);
30         res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;
31         res|=I2c_ReadByte(NO_ACK);
32         
33         
34         I2c_StopCondition();
35         return res;
36         
37 }
38
39
40 int16_t MAX1164x_read8() {
41         uint16_t res;
42         I2c_StartCondition();
43         I2c_WriteByte (0b01101101);
44         //DDR_USI&=~(1<<PIN_USI_SCL);
45         //while ((PIN_USI&(1<<PIN_USI_SCL))==0);
46         //DDR_USI|=(1<<PIN_USI_SCL);
47         _delay_us(80);
48         res=((int16_t)(I2c_ReadByte(ACK)&0x0F))<<8;
49         res|=I2c_ReadByte(NO_ACK);
50         
51         
52         I2c_StopCondition();
53         return res;
54         
55 }