-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi2csoft.h
120 lines (82 loc) · 2.57 KB
/
i2csoft.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**********************************************************
Software I2C Library for AVR Devices.
Copyright 2008-2012
eXtreme Electronics, India
www.eXtremeElectronics.co.in
**********************************************************/
#ifndef _I2CSOFT_H
#define _I2CSOFT_H
#include "autolight.h"
/*
I/O Configuration
*/
#define SCLPORT PORTB // TAKE PORTB as SCL OUTPUT WRITE
#define SCLDDR DDRB // TAKE DDRB as SCL INPUT/OUTPUT configure
#define SDAPORT PORTB // TAKE PORTB as SDA OUTPUT WRITE
#define SDADDR DDRB // TAKE PORTB as SDA INPUT configure
#define SDAPIN PINB // TAKE PORTB TO READ DATA
#define SCLPIN PINB // TAKE PORTB TO READ DATA
#define SDA PINB0 // PORTB.0 PIN AS SDA PIN
#define SCL PINB1 // PORTB.1 PIN AS SCL PIN
#define SOFT_I2C_SDA_LOW SDADDR |= (1 << SDA)
#define SOFT_I2C_SDA_HIGH SDADDR &= ~(1 << SDA)
#define SOFT_I2C_SCL_LOW SCLDDR |= (1 << SCL)
#define SOFT_I2C_SCL_HIGH SCLDDR &= ~(1 << SCL)
/**********************************************************
SoftI2CInit()
Description:
Initializes the Soft I2C Engine.
Must be called before using any other lib functions.
Arguments:
NONE
Returns:
Nothing
**********************************************************/
void SoftI2CInit();
/**********************************************************
SoftI2CStart()
Description:
Generates a START(S) condition on the bus.
NOTE: Can also be used for generating repeat start(Sr)
condition too.
Arguments:
NONE
Returns:
Nothing
**********************************************************/
void SoftI2CStart();
/**********************************************************
SoftI2CStop()
Description:
Generates a STOP(P) condition on the bus.
NOTE: Can also be used for generating repeat start
condition too.
Arguments:
NONE
Returns:
Nothing
**********************************************************/
void SoftI2CStop();
/**********************************************************
SoftI2CWriteByte()
Description:
Sends a Byte to the slave.
Arguments:
8 bit date to send to the slave.
Returns:
non zero if slave acknowledge the data receipt.
zero other wise.
**********************************************************/
uint8_t SoftI2CWriteByte(uint8_t data);
/**********************************************************
SoftI2CReadByte()
Description:
Reads a byte from slave.
Arguments:
1 if you want to acknowledge the receipt to slave.
0 if you don't want to acknowledge the receipt to slave.
Returns:
The 8 bit data read from the slave.
**********************************************************/
uint8_t SoftI2CReadByte(uint8_t ack);
#endif