Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
359 kaklik 1
 
2
/****************************************************************************
3
 Title	:   C  include file for the I2C FUNCTIONS library (i2c.h)
4
 Author:    Chris efstathiou hendrix@otenet.gr
5
 Date:	    13/Jul/2002
6
 Software:  AVR-GCC with AVR-AS
7
 Target:    any AVR device
8
 Comments:  This software is FREE.
9
 
10
*****************************************************************************/
11
 
12
 
13
#ifndef I2C_H
14
#define I2C_H	1
15
 
16
/*##############################################################################################*/
17
/*			       START OF CONFIGURATION BLOCK					*/
18
/*##############################################################################################*/
19
 
20
#ifndef  F_CPU
21
#define  F_CPU		  3686400L  /* The cpu clock frequency in Hertz (used to calculate time)*/
22
#endif
23
 
24
#define I2C_SDA_PORT	  D	    /* The SDA port. Use capital letter (A,B,C,D... etc.) */
25
#define SDA_PIN 	  4	    /* The SDA port pin */
26
 
27
#define I2C_SCL_PORT	  D	    /* The SCL port. Use capital letter (A,B,C,D... etc.) */
28
#define SCL_PIN 	  5	    /* The SCL port pin */
29
/*
30
   The I2C_DELAY_TIME normally is 5 microseconds for a 100 Khz I2C bus ( (1/100000)/2 ).
31
   but due to bus capacitance and device responce time in my application i use 50 microseconds.
32
   The I2C_TIMEOUT_TIME is set to whatever is the maximum time you think your device will take
33
   to perform the requested task. After that time the i2c_transmit function will return
34
   a "I2C_ERROR_DEVICE_NOT_RESPONDING" or "I2C_ERROR_DEVICE_BUSY" error code. 
35
*/ 
36
#define I2C_DELAY_TIME	  50	   /* in microseconds (max over 1 second) */
37
#define I2C_TIMEOUT_TIME  1000	   /* in microseconds (max over 1 second) */
38
 
39
/*##############################################################################################*/
40
/*				END OF CONFIGURATION BLOCK					*/
41
/*##############################################################################################*/
42
 
43
/* Keyword definitions */
44
 
45
#define I2C_READ	1
46
#define I2C_WRITE	0
47
 
48
#define I2C_QUIT	0
49
#define I2C_CONTINUE	1
50
 
51
#define I2C_NO_ERROR			 0
52
#define I2C_ERROR_DEVICE_BUSY		 1
53
#define I2C_ERROR_DEVICE_NOT_RESPONDING  2
54
 
55
 
56
/* Function Declaration */
57
 
58
extern	void	      i2c_init(void);
59
extern	void	      i2c_start(void);
60
extern	void	      i2c_stop(void);
61
extern	unsigned char i2c_transmit(unsigned char data);
62
extern	unsigned char i2c_receive(unsigned char ack);
63
 
64
 
65
 
66
/* Macro definitions */
67
 
68
#define I2C_START(ADDRESS)     { i2c_start(); i2c_transmit(ADDRESS); }
69
#define I2C_START_TX(ADDRESS)  I2C_START(ADDRESS)
70
#define I2C_START_RX(ADDRESS)  I2C_START(ADDRESS | I2C_READ)
71
 
72
#endif	/*  #ifndef I2C_H */
73
/*######################################################################################################*/
74
/*					   T H E   E N D						*/
75
/*######################################################################################################*/
76