• Main Page
  • Data Structures
  • Files
  • File List
  • Globals

i2c.h

Go to the documentation of this file.
00001 
00002 #ifndef I2C_H
00003 #define I2C_H
00004 
00005 
00006 
00007 #include <avr/io.h>
00008 #include <config.h>
00009 
00010 /* 23/2/2011  svn 282  */
00011 
00012 
00013 #define         TW_START   0x08
00014 #define         TW_REP_START   0x10
00015 #define         TW_MT_SLA_ACK   0x18
00016 #define         TW_MT_SLA_NACK   0x20
00017 #define         TW_MT_DATA_ACK   0x28
00018 #define         TW_MT_DATA_NACK   0x30
00019 #define         TW_MT_ARB_LOST   0x38
00020 #define         TW_MR_ARB_LOST   0x38
00021 #define         TW_MR_SLA_ACK   0x40
00022 #define         TW_MR_SLA_NACK   0x48
00023 #define         TW_MR_DATA_ACK   0x50
00024 #define         TW_MR_DATA_NACK   0x58
00025 #define         TW_ST_SLA_ACK   0xA8
00026 #define         TW_ST_ARB_LOST_SLA_ACK   0xB0
00027 #define         TW_ST_DATA_ACK   0xB8
00028 #define         TW_ST_DATA_NACK   0xC0
00029 #define         TW_ST_LAST_DATA   0xC8
00030 #define         TW_SR_SLA_ACK   0x60
00031 #define         TW_SR_ARB_LOST_SLA_ACK   0x68
00032 #define         TW_SR_GCALL_ACK   0x70
00033 #define         TW_SR_ARB_LOST_GCALL_ACK   0x78
00034 #define         TW_SR_DATA_ACK   0x80
00035 #define         TW_SR_DATA_NACK   0x88
00036 #define         TW_SR_GCALL_DATA_ACK   0x90
00037 #define         TW_SR_GCALL_DATA_NACK   0x98
00038 #define         TW_SR_STOP   0xA0
00039 #define         TW_NO_INFO   0xF8
00040 #define         TW_BUS_ERROR   0x00
00041 
00042 
00043 
00044 /* 
00045 
00046 Return values from I2C for read,write,write-read
00047 0       0       0       success
00048 1       17      33      timeout waiting for start condition, device read
00049 2       18      34      failed to send start
00050 3       19      35      timeout waiting for send address
00051 4       20      36      slave failed to ACK address
00052 5                       arbitration lost
00053 6                       other failure while expecting slave ACK address
00054 7       23      39      timeout waiting for data sent
00055 8       24      40      slave failed to ACK data
00056                 41      timeout on repeated start
00057                 42      failed to assert repeated start on bus
00058                 43      timeout waiting for send address
00059                 44      slave failed to ACK address
00060                 45      arbitration lost
00061                 46      other failure while expecting slave ACK address
00062                 47      timeout waiting for data sent
00063                 
00064 */
00065 
00066 
00067 
00068 
00069 
00070 /* Note that there are no delays padding calls to these functions
00071  * If two calls occur in quick succession, you must add a delay (10uS should be plenty) to allow the
00072  * bus to recover. 
00073  *  You MUST also initialise the I2C bus registers TWSR and TWBR. For 8MHz :
00074         TWCR = 0x04 ;                                                   // Enable TWI. Overrides IO definitions
00075         TWSR = 2 ;                                                              // Clock rate is 8000000/(16 + 2xTWBR * 4 ^ TWSR)
00076         TWBR = 2 ;                                                              // = 8000000/(16 + (4 * 16)) = 100kHz
00077  */
00078  
00079  
00080 void i2c_timerproc (void); 
00081  
00082 
00092 uint8_t read_i2c_device(uint8_t address, uint8_t bytes, uint8_t *rdata);
00093 
00094 
00095 
00105 uint8_t write_i2c_device(uint8_t address, uint8_t bytes, uint8_t *wdata);
00106 
00107 
00108 
00120 uint8_t write_read_i2c_device(uint8_t address, uint8_t wbytes, uint8_t *wdata, uint8_t rbytes, uint8_t *rdata);
00121 
00122 #endif
00123 

Generated on Wed Aug 22 2012 11:44:35 by  doxygen 1.7.1