-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathusi_i2c_master.h
56 lines (49 loc) · 1.76 KB
/
usi_i2c_master.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
/*-----------------------------------------------------*\
| USI I2C Slave Master |
| |
| This library provides a robust I2C master protocol |
| implementation on top of Atmel's Universal Serial |
| Interface (USI) found in many ATTiny microcontrollers.|
| |
| Adam Honse (GitHub: CalcProgrammer1) - 7/29/2012 |
\*-----------------------------------------------------*/
#ifndef USI_I2C_MASTER_H
#define USI_I2C_MASTER_H
#include <avr/io.h>
#include <util/delay.h>
//I2C Bus Specification v2.1 FAST mode timing limits
#ifdef I2C_FAST_MODE
#define I2C_TLOW 1.3
#define I2C_THIGH 0.6
//I2C Bus Specification v2.1 STANDARD mode timing limits
#else
#define I2C_TLOW 4.7
#define I2C_THIGH 4.0
#endif
//Microcontroller Dependent Definitions
#if defined (__AVR_ATtiny24__) | \
defined (__AVR_ATtiny44__) | \
defined (__AVR_ATtiny84__)
#define DDR_USI DDRA
#define PORT_USI PORTA
#define PIN_USI PINA
#define PORT_USI_SDA PA6
#define PORT_USI_SCL PA4
#define PIN_USI_SDA PINA6
#define PIN_USI_SCL PINA4
#endif
#if defined(__AVR_AT90Tiny2313__) | \
defined(__AVR_ATtiny2313__)
#define DDR_USI DDRB
#define PORT_USI PORTB
#define PIN_USI PINB
#define PORT_USI_SDA PB5
#define PORT_USI_SCL PB7
#define PIN_USI_SDA PINB5
#define PIN_USI_SCL PINB7
#endif
//USI I2C Master Transceiver Start
// Starts the transceiver to send or receive data based on the r/w bit
char USI_I2C_Master_Transceiver_Start(char *msg, char msg_size);
#endif