AVR Libc Home Page AVRs AVR Libc Development Pages
Main Page User Manual Reference FAQ Example Projects

util/twi.h

Go to the documentation of this file.
01	1 Copyright (c) 2002, Marek Michalkiewicz
	022Copyright (c) 2005, 2007 Joerg Wunsch
033All rights reserved. 044 055Redistribution and use in source and binary forms, with or without 066modification, are permitted provided that the following conditions are met: 077 088* Redistributions of source code must retain the above copyright 099notice, this list of conditions and the following disclaimer. 1010 1111* Redistributions in binary form must reproduce the above copyright 1212notice, this list of conditions and the following disclaimer in 1313the documentation and/or other materials provided with the 1414distribution. 1515 1616* Neither the name of the copyright holders nor the names of 1717contributors may be used to endorse or promote products derived 1818from this software without specific prior written permission. 1919 2020THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2121AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2222IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2323ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2424LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2525CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2626SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2727INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2828CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2929ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3030POSSIBILITY OF SUCH DAMAGE. */ 3131 3232/* $Id: twi.h 1196 2007-01-23 15:34:58Z joerg_wunsch $ */ 3333/* copied from: Id: avr/twi.h,v 1.4 2004/11/01 21:19:54 arcanum Exp */ 3434 3535#ifndef _UTIL_TWI_H_ 3636#define _UTIL_TWI_H_ 1 3737 3838#include <avr/io.h> 3939 4040/** \file */ 4141/** \defgroup util_twi <util/twi.h>: TWI bit mask definitions 4242\code #include <util/twi.h> \endcode 4343 4444This header file contains bit mask definitions for use with 4545the AVR TWI interface. 4646*/ 4747/** \name TWSR values 4848 4949Mnemonics: 5050<br>TW_MT_xxx - master transmitter 5151<br>TW_MR_xxx - master receiver 5252<br>TW_ST_xxx - slave transmitter 5353<br>TW_SR_xxx - slave receiver 5454*/ 5555 5656/*@{*/ 5757/* Master */ 5858/** \ingroup util_twi 5959\def TW_START 6060start condition transmitted */ 61 61#define TW_START 0x08 6262 6363/** \ingroup util_twi 6464\def TW_REP_START 6565repeated start condition transmitted */ 66 66#define TW_REP_START 0x10 6767 6868/* Master Transmitter */ 6969/** \ingroup util_twi 7070\def TW_MT_SLA_ACK 7171SLA+W transmitted, ACK received */ 72 72#define TW_MT_SLA_ACK 0x18 7373 7474/** \ingroup util_twi 7575\def TW_MT_SLA_NACK 7676SLA+W transmitted, NACK received */ 77 77#define TW_MT_SLA_NACK 0x20 7878 7979/** \ingroup util_twi 8080\def TW_MT_DATA_ACK 8181data transmitted, ACK received */ 82 82#define TW_MT_DATA_ACK 0x28 8383 8484/** \ingroup util_twi 8585\def TW_MT_DATA_NACK 8686data transmitted, NACK received */ 87 87#define TW_MT_DATA_NACK 0x30 8888 8989/** \ingroup util_twi 9090\def TW_MT_ARB_LOST 9191arbitration lost in SLA+W or data */ 92 92#define TW_MT_ARB_LOST 0x38 9393 9494/* Master Receiver */ 9595/** \ingroup util_twi 9696\def TW_MR_ARB_LOST 9797arbitration lost in SLA+R or NACK */ 98 98#define TW_MR_ARB_LOST 0x38 9999 100100/** \ingroup util_twi 101101\def TW_MR_SLA_ACK 102102SLA+R transmitted, ACK received */ 103 103#define TW_MR_SLA_ACK 0x40 104104 105105/** \ingroup util_twi 106106\def TW_MR_SLA_NACK 107107SLA+R transmitted, NACK received */ 108 108#define TW_MR_SLA_NACK 0x48 109109 110110/** \ingroup util_twi 111111\def TW_MR_DATA_ACK 112112data received, ACK returned */ 113 113#define TW_MR_DATA_ACK 0x50 114114 115115/** \ingroup util_twi 116116\def TW_MR_DATA_NACK 117117data received, NACK returned */ 118 118#define TW_MR_DATA_NACK 0x58 119119 120120/* Slave Transmitter */ 121121/** \ingroup util_twi 122122\def TW_ST_SLA_ACK 123123SLA+R received, ACK returned */ 124 124#define TW_ST_SLA_ACK 0xA8 125125 126126/** \ingroup util_twi 127127\def TW_ST_ARB_LOST_SLA_ACK 128128arbitration lost in SLA+RW, SLA+R received, ACK returned */ 129 129#define TW_ST_ARB_LOST_SLA_ACK 0xB0 130130 131131/** \ingroup util_twi 132132\def TW_ST_DATA_ACK 133133data transmitted, ACK received */ 134 134#define TW_ST_DATA_ACK 0xB8 135135 136136/** \ingroup util_twi 137137\def TW_ST_DATA_NACK 138138data transmitted, NACK received */ 139 139#define TW_ST_DATA_NACK 0xC0 140140 141141/** \ingroup util_twi 142142\def TW_ST_LAST_DATA 143143last data byte transmitted, ACK received */ 144 144#define TW_ST_LAST_DATA 0xC8 145145 146146/* Slave Receiver */ 147147/** \ingroup util_twi 148148\def TW_SR_SLA_ACK 149149SLA+W received, ACK returned */ 150 150#define TW_SR_SLA_ACK 0x60 151151 152152/** \ingroup util_twi 153153\def TW_SR_ARB_LOST_SLA_ACK 154154arbitration lost in SLA+RW, SLA+W received, ACK returned */ 155 155#define TW_SR_ARB_LOST_SLA_ACK 0x68 156156 157157/** \ingroup util_twi 158158\def TW_SR_GCALL_ACK 159159general call received, ACK returned */ 160 160#define TW_SR_GCALL_ACK 0x70 161161 162162/** \ingroup util_twi 163163\def TW_SR_ARB_LOST_GCALL_ACK 164164arbitration lost in SLA+RW, general call received, ACK returned */ 165 165#define TW_SR_ARB_LOST_GCALL_ACK 0x78 166166 167167/** \ingroup util_twi 168168\def TW_SR_DATA_ACK 169169data received, ACK returned */ 170 170#define TW_SR_DATA_ACK 0x80 171171 172172/** \ingroup util_twi 173173\def TW_SR_DATA_NACK 174174data received, NACK returned */ 175 175#define TW_SR_DATA_NACK 0x88 176176 177177/** \ingroup util_twi 178178\def TW_SR_GCALL_DATA_ACK 179179general call data received, ACK returned */ 180 180#define TW_SR_GCALL_DATA_ACK 0x90 181181 182182/** \ingroup util_twi 183183\def TW_SR_GCALL_DATA_NACK 184184general call data received, NACK returned */ 185 185#define TW_SR_GCALL_DATA_NACK 0x98 186186 187187/** \ingroup util_twi 188188\def TW_SR_STOP 189189stop or repeated start condition received while selected */ 190 190#define TW_SR_STOP 0xA0 191191 192192/* Misc */ 193193/** \ingroup util_twi 194194\def TW_NO_INFO 195195no state information available */ 196 196#define TW_NO_INFO 0xF8 197197 198198/** \ingroup util_twi 199199\def TW_BUS_ERROR 200200illegal start or stop condition */ 201 201#define TW_BUS_ERROR 0x00 202202 203203 204204/** 205205* \ingroup util_twi 206206* \def TW_STATUS_MASK 207207* The lower 3 bits of TWSR are reserved on the ATmega163. 208208* The 2 LSB carry the prescaler bits on the newer ATmegas. 209209*/ 210 210#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|\ 211211_BV(TWS3)) 212212/** 213213* \ingroup util_twi 214214* \def TW_STATUS 215215* 216216* TWSR, masked by TW_STATUS_MASK 217217*/ 218 218#define TW_STATUS (TWSR & TW_STATUS_MASK) 219219/*@}*/ 220220 221221/** 222222* \name R/~W bit in SLA+R/W address field. 223223*/ 224224 225225/*@{*/ 226226/** \ingroup util_twi 227227\def TW_READ 228228SLA+R address */ 229 229#define TW_READ 1 230230 231231/** \ingroup util_twi 232232\def TW_WRITE 233233SLA+W address */ 234 234#define TW_WRITE 0 235235/*@}*/ 236236 237237#endif /* _UTIL_TWI_H_ */

io.h