TWI/TWI.h
00001
00002
00003
00004
00005 #ifndef __TWI_H__
00006 #define __TWI_H__
00007
00008 #include <inttypes.h>
00009
00014 #define TWI_BUFFER_SIZE 20
00015
00017
00021
00022 #define TWI_TWPS 0x00
00023 #define TWI_TWBR 0x34
00024
00025
00029 union twi_status_reg
00030 {
00031 unsigned char all;
00032 struct
00033 {
00034 unsigned char last_trans_ok:1;
00035 unsigned char unused_bits:7;
00036 };
00037 };
00038
00039 extern union twi_status_reg twi_status_reg;
00040
00044 void twi_master_init( void );
00045 unsigned char twi_busy_p( void );
00046 unsigned char twi_get_state( void );
00047 void twi_transmit( unsigned char * , unsigned char );
00048 void twi_resend( void );
00049 unsigned char twi_get_data( unsigned char *, unsigned char );
00050
00054
00055 #define TWI_READ_BIT 0
00056 #define TWI_ADR_BITS 1
00057
00058 #define TRUE 1
00059 #define FALSE 0
00060
00064
00068
00069 #define TWI_START 0x08
00070 #define TWI_REP_START 0x10
00071 #define TWI_ARB_LOST 0x38
00072
00076
00077 #define TWI_MTX_ADR_ACK 0x18
00078 #define TWI_MTX_ADR_NACK 0x20
00079 #define TWI_MTX_DATA_ACK 0x28
00080 #define TWI_MTX_DATA_NACK 0x30
00081
00085
00086 #define TWI_MRX_ADR_ACK 0x40
00087 #define TWI_MRX_ADR_NACK 0x48
00088 #define TWI_MRX_DATA_ACK 0x50
00089 #define TWI_MRX_DATA_NACK 0x58
00090
00094
00095 #define TWI_STX_ADR_ACK 0xA8
00096 #define TWI_STX_ADR_ACK_M_ARB_LOST 0xB0
00097
00098 #define TWI_STX_DATA_ACK 0xB8
00099 #define TWI_STX_DATA_NACK 0xC0
00100 #define TWI_STX_DATA_ACK_LAST_BYTE 0xC8
00101
00102
00103
00104
00105
00106 #define TWI_SRX_ADR_ACK 0x60
00107 #define TWI_SRX_ADR_ACK_M_ARB_LOST 0x68
00108
00109 #define TWI_SRX_GEN_ACK 0x70
00110 #define TWI_SRX_GEN_ACK_M_ARB_LOST 0x78
00111
00112
00113 #define TWI_SRX_ADR_DATA_ACK 0x80
00114
00115 #define TWI_SRX_ADR_DATA_NACK 0x88
00116
00117 #define TWI_SRX_GEN_DATA_ACK 0x90
00118
00119 #define TWI_SRX_GEN_DATA_NACK 0x98
00120
00121 #define TWI_SRX_STOP_RESTART 0xA0
00122
00123
00124
00125
00126
00127 #define TWI_NO_STATE 0xF8
00128 #define TWI_BUS_ERROR 0x00
00129
00130 #endif
Generated on Sun Dec 13 16:47:18 2009 by
1.6.1