1 |
/* Copyright (c) 2002, Marek Michalkiewicz |
/* Copyright (c) 2005 Joerg Wunsch |
2 |
All rights reserved. |
All rights reserved. |
3 |
|
|
4 |
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
29 |
POSSIBILITY OF SUCH DAMAGE. */ |
POSSIBILITY OF SUCH DAMAGE. */ |
30 |
|
|
31 |
/* $Id$ */ |
/* $Id$ */ |
|
/* copied from: Id: avr/twi.h,v 1.4 2004/11/01 21:19:54 arcanum Exp */ |
|
32 |
|
|
33 |
/* |
#ifndef _COMPAT_TWI_H_ |
34 |
compat/twi.h - definitions for TWI: Two-Wire Interface or Twi Was I2c(tm). |
#define _COMPAT_TWI_H_ |
35 |
|
|
36 |
Contributors: |
#include <util/twi.h> |
|
Created by Marek Michalkiewicz <marekm@linux.org.pl> |
|
37 |
|
|
38 |
Based on advance information Atmel datasheet Rev. 1142A-10/00 (ATmega163). |
#endif /* _COMPAT_TWI_H_ */ |
|
*/ |
|
|
|
|
|
#ifndef _AVR_TWI_H_ |
|
|
#define _AVR_TWI_H_ 1 |
|
|
|
|
|
#include <avr/io.h> |
|
|
|
|
|
/* TWSR values (not bits) */ |
|
|
/* Master */ |
|
|
#define TW_START 0x08 |
|
|
#define TW_REP_START 0x10 |
|
|
/* Master Transmitter */ |
|
|
#define TW_MT_SLA_ACK 0x18 |
|
|
#define TW_MT_SLA_NACK 0x20 |
|
|
#define TW_MT_DATA_ACK 0x28 |
|
|
#define TW_MT_DATA_NACK 0x30 |
|
|
#define TW_MT_ARB_LOST 0x38 |
|
|
/* Master Receiver */ |
|
|
#define TW_MR_ARB_LOST 0x38 |
|
|
#define TW_MR_SLA_ACK 0x40 |
|
|
#define TW_MR_SLA_NACK 0x48 |
|
|
#define TW_MR_DATA_ACK 0x50 |
|
|
#define TW_MR_DATA_NACK 0x58 |
|
|
/* Slave Transmitter */ |
|
|
#define TW_ST_SLA_ACK 0xA8 |
|
|
#define TW_ST_ARB_LOST_SLA_ACK 0xB0 |
|
|
#define TW_ST_DATA_ACK 0xB8 |
|
|
#define TW_ST_DATA_NACK 0xC0 |
|
|
#define TW_ST_LAST_DATA 0xC8 |
|
|
/* Slave Receiver */ |
|
|
#define TW_SR_SLA_ACK 0x60 |
|
|
#define TW_SR_ARB_LOST_SLA_ACK 0x68 |
|
|
#define TW_SR_GCALL_ACK 0x70 |
|
|
#define TW_SR_ARB_LOST_GCALL_ACK 0x78 |
|
|
#define TW_SR_DATA_ACK 0x80 |
|
|
#define TW_SR_DATA_NACK 0x88 |
|
|
#define TW_SR_GCALL_DATA_ACK 0x90 |
|
|
#define TW_SR_GCALL_DATA_NACK 0x98 |
|
|
#define TW_SR_STOP 0xA0 |
|
|
/* Misc */ |
|
|
#define TW_NO_INFO 0xF8 |
|
|
#define TW_BUS_ERROR 0x00 |
|
|
|
|
|
/* |
|
|
* The lower 3 bits of TWSR are reserved on the ATmega163. |
|
|
* The 2 LSB carry the prescaler bits on the newer ATmegas. |
|
|
*/ |
|
|
#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|\ |
|
|
_BV(TWS3)) |
|
|
#define TW_STATUS (TWSR & TW_STATUS_MASK) |
|
|
|
|
|
/* |
|
|
* R/~W bit in SLA+R/W address field. |
|
|
*/ |
|
|
#define TW_READ 1 |
|
|
#define TW_WRITE 0 |
|
|
|
|
|
#endif /* _AVR_TWI_H_ */ |
|