AVR-GCC Libraries
i2cmaster.h
Go to the documentation of this file.
1 #ifndef _I2CMASTER_H
2 #define _I2CMASTER_H
3 /*************************************************************************
4 * Title: C include file for the I2C master interface
5 * (i2cmaster.S or twimaster.c)
6 * Author: Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury
7 * File: $Id: i2cmaster.h,v 1.11 2015/01/17 12:16:05 peter Exp $
8 * Software: AVR-GCC 3.4.3 / avr-libc 1.2.3
9 * Target: any AVR device
10 * Usage: see Doxygen manual
11 **************************************************************************/
12 
85 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
86 #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
87 #endif
88 
89 #include <avr/io.h>
90 
92 #define I2C_READ 1
93 
95 #define I2C_WRITE 0
96 
97 
102 extern void i2c_init(void);
103 
104 
109 extern void i2c_stop(void);
110 
111 
119 extern unsigned char i2c_start(unsigned char addr);
120 
121 
129 extern unsigned char i2c_rep_start(unsigned char addr);
130 
131 
139 extern void i2c_start_wait(unsigned char addr);
140 
141 
148 extern unsigned char i2c_write(unsigned char data);
149 
150 
155 extern unsigned char i2c_readAck(void);
156 
161 extern unsigned char i2c_readNak(void);
162 
172 extern unsigned char i2c_read(unsigned char ack);
173 #define i2c_read(ack) (ack) ? i2c_readAck() : i2c_readNak();
174 
175 
176 
178 #endif
void i2c_stop(void)
Terminates the data transfer and releases the I2C bus.
unsigned char i2c_readAck(void)
read one byte from the I2C device, request more data from device
unsigned char i2c_read(unsigned char ack)
read one byte from the I2C device
unsigned char i2c_write(unsigned char data)
Send one byte to I2C device.
unsigned char i2c_rep_start(unsigned char addr)
Issues a repeated start condition and sends address and transfer direction.
void i2c_start_wait(unsigned char addr)
Issues a start condition and sends address and transfer direction.
unsigned char i2c_readNak(void)
read one byte from the I2C device, read is followed by a stop condition
unsigned char i2c_start(unsigned char addr)
Issues a start condition and sends address and transfer direction.
void i2c_init(void)
initialize the I2C master interace. Need to be called only once