AVR-LibC  2.3.0git
Standard C library for AVR-GCC
 

AVR-LibC Documen­tation

AVR-LibC Development Pages

Main Page

User Manual

Library Refe­rence

FAQ

Example Projects

File List

Index

Loading...
Searching...
No Matches
util/twi.h
Go to the documentation of this file.
1/* Copyright (c) 2002, Marek Michalkiewicz
2 Copyright (c) 2005, 2007 Joerg Wunsch
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
14 distribution.
15
16 * Neither the name of the copyright holders nor the names of
17 contributors may be used to endorse or promote products derived
18 from this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE. */
31
32#ifndef _UTIL_TWI_H_
33#define _UTIL_TWI_H_ 1
34
35#include <avr/io.h>
36
37/** \file */
38/** \defgroup util_twi <util/twi.h>: TWI bit mask definitions
39 \code #include <util/twi.h> \endcode
40
41 This header file contains bit mask definitions for use with
42 the AVR TWI interface.
43*/
44/** \name TWSR values
45
46 Mnemonics:
47 <br>TW_MT_xxx - master transmitter
48 <br>TW_MR_xxx - master receiver
49 <br>TW_ST_xxx - slave transmitter
50 <br>TW_SR_xxx - slave receiver
51 */
52
53/**@{*/
54/* Master */
55/** \ingroup util_twi
56 \def TW_START
57 start condition transmitted */
58#define TW_START 0x08
59
60/** \ingroup util_twi
61 \def TW_REP_START
62 repeated start condition transmitted */
63#define TW_REP_START 0x10
64
65/* Master Transmitter */
66/** \ingroup util_twi
67 \def TW_MT_SLA_ACK
68 SLA+W transmitted, ACK received */
69#define TW_MT_SLA_ACK 0x18
70
71/** \ingroup util_twi
72 \def TW_MT_SLA_NACK
73 SLA+W transmitted, NACK received */
74#define TW_MT_SLA_NACK 0x20
75
76/** \ingroup util_twi
77 \def TW_MT_DATA_ACK
78 data transmitted, ACK received */
79#define TW_MT_DATA_ACK 0x28
80
81/** \ingroup util_twi
82 \def TW_MT_DATA_NACK
83 data transmitted, NACK received */
84#define TW_MT_DATA_NACK 0x30
85
86/** \ingroup util_twi
87 \def TW_MT_ARB_LOST
88 arbitration lost in SLA+W or data */
89#define TW_MT_ARB_LOST 0x38
90
91/* Master Receiver */
92/** \ingroup util_twi
93 \def TW_MR_ARB_LOST
94 arbitration lost in SLA+R or NACK */
95#define TW_MR_ARB_LOST 0x38
96
97/** \ingroup util_twi
98 \def TW_MR_SLA_ACK
99 SLA+R transmitted, ACK received */
100#define TW_MR_SLA_ACK 0x40
101
102/** \ingroup util_twi
103 \def TW_MR_SLA_NACK
104 SLA+R transmitted, NACK received */
105#define TW_MR_SLA_NACK 0x48
106
107/** \ingroup util_twi
108 \def TW_MR_DATA_ACK
109 data received, ACK returned */
110#define TW_MR_DATA_ACK 0x50
111
112/** \ingroup util_twi
113 \def TW_MR_DATA_NACK
114 data received, NACK returned */
115#define TW_MR_DATA_NACK 0x58
116
117/* Slave Transmitter */
118/** \ingroup util_twi
119 \def TW_ST_SLA_ACK
120 SLA+R received, ACK returned */
121#define TW_ST_SLA_ACK 0xA8
122
123/** \ingroup util_twi
124 \def TW_ST_ARB_LOST_SLA_ACK
125 arbitration lost in SLA+RW, SLA+R received, ACK returned */
126#define TW_ST_ARB_LOST_SLA_ACK 0xB0
127
128/** \ingroup util_twi
129 \def TW_ST_DATA_ACK
130 data transmitted, ACK received */
131#define TW_ST_DATA_ACK 0xB8
132
133/** \ingroup util_twi
134 \def TW_ST_DATA_NACK
135 data transmitted, NACK received */
136#define TW_ST_DATA_NACK 0xC0
137
138/** \ingroup util_twi
139 \def TW_ST_LAST_DATA
140 last data byte transmitted, ACK received */
141#define TW_ST_LAST_DATA 0xC8
142
143/* Slave Receiver */
144/** \ingroup util_twi
145 \def TW_SR_SLA_ACK
146 SLA+W received, ACK returned */
147#define TW_SR_SLA_ACK 0x60
148
149/** \ingroup util_twi
150 \def TW_SR_ARB_LOST_SLA_ACK
151 arbitration lost in SLA+RW, SLA+W received, ACK returned */
152#define TW_SR_ARB_LOST_SLA_ACK 0x68
153
154/** \ingroup util_twi
155 \def TW_SR_GCALL_ACK
156 general call received, ACK returned */
157#define TW_SR_GCALL_ACK 0x70
158
159/** \ingroup util_twi
160 \def TW_SR_ARB_LOST_GCALL_ACK
161 arbitration lost in SLA+RW, general call received, ACK returned */
162#define TW_SR_ARB_LOST_GCALL_ACK 0x78
163
164/** \ingroup util_twi
165 \def TW_SR_DATA_ACK
166 data received, ACK returned */
167#define TW_SR_DATA_ACK 0x80
168
169/** \ingroup util_twi
170 \def TW_SR_DATA_NACK
171 data received, NACK returned */
172#define TW_SR_DATA_NACK 0x88
173
174/** \ingroup util_twi
175 \def TW_SR_GCALL_DATA_ACK
176 general call data received, ACK returned */
177#define TW_SR_GCALL_DATA_ACK 0x90
178
179/** \ingroup util_twi
180 \def TW_SR_GCALL_DATA_NACK
181 general call data received, NACK returned */
182#define TW_SR_GCALL_DATA_NACK 0x98
183
184/** \ingroup util_twi
185 \def TW_SR_STOP
186 stop or repeated start condition received while selected */
187#define TW_SR_STOP 0xA0
188
189/* Misc */
190/** \ingroup util_twi
191 \def TW_NO_INFO
192 no state information available */
193#define TW_NO_INFO 0xF8
194
195/** \ingroup util_twi
196 \def TW_BUS_ERROR
197 illegal start or stop condition */
198#define TW_BUS_ERROR 0x00
199
200
201/**
202 * \ingroup util_twi
203 * \def TW_STATUS_MASK
204 * The lower 3 bits of TWSR are reserved on the ATmega163.
205 * The 2 LSB carry the prescaler bits on the newer ATmegas.
206 */
207#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|\
208 _BV(TWS3))
209/**
210 * \ingroup util_twi
211 * \def TW_STATUS
212 *
213 * TWSR, masked by TW_STATUS_MASK
214 */
215#define TW_STATUS (TWSR & TW_STATUS_MASK)
216/**@}*/
217
218/**
219 * \name R/~W bit in SLA+R/W address field.
220 */
221
222/**@{*/
223/** \ingroup util_twi
224 \def TW_READ
225 SLA+R address */
226#define TW_READ 1
227
228/** \ingroup util_twi
229 \def TW_WRITE
230 SLA+W address */
231#define TW_WRITE 0
232/**@}*/
233
234#endif /* _UTIL_TWI_H_ */