-
Notifications
You must be signed in to change notification settings - Fork 11
/
i2c.h
68 lines (55 loc) · 1.19 KB
/
i2c.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
/*
* i2c.h
*
* Created on: Jan 4, 2016
* Author: alex
*/
#ifndef I2C_H_
#define I2C_H_
/*
// Write to slave device with
// slave address e.g. say 0x20
// Init i2c ports first
I2CInit();
// Send start condition
I2CStart();
// Send slave address
ack = I2CSend(0x20);
* ack == 1 => NAK
* ack == 0 => ACK
ack = I2CSend(0x07);
// Send another data
ack = I2CSend(0x10);
// Send stop condition
I2CStop();
// Read from slave device with
// slave address e.g. say 0x20
// Init i2c ports first - Should be done once in main
I2CInit();
// Send start condition
I2CStart();
// Send slave address with Read bit set
// So address is 0x20 | 1 = 0x21
I2CSend(0x21);
data = I2CRead();
// Send ack
I2CAck();
// Read last byte
data = I2CRead();
// Send nak for last byte to indicate
// End of transmission
I2CNak();
// Send stop condition
I2CStop();
*/
#define SDA P11
#define SCL P10
void I2CInit();
void I2CStart();
void I2CRestart();
void I2CStop();
void I2CAck();
void I2CNak();
unsigned char I2CSend(unsigned char Data);
unsigned char I2CRead();
#endif /* I2C_H_ */