Xmega Application Note


twi_master_driver.h

Go to the documentation of this file.
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/
00059 #ifndef TWI_MASTER_DRIVER_H
00060 #define TWI_MASTER_DRIVER_H
00061 
00062 #include "avr_compiler.h"
00063 
00065 #define TWI_BAUD(F_SYS, F_TWI) ((F_SYS / (2 * F_TWI)) - 5)
00066 
00067 
00069 #define TWIM_STATUS_READY              0
00070 #define TWIM_STATUS_BUSY               1
00071 
00072 
00074 typedef enum TWIM_RESULT_enum {
00075         TWIM_RESULT_UNKNOWN          = (0x00<<0),
00076         TWIM_RESULT_OK               = (0x01<<0),
00077         TWIM_RESULT_BUFFER_OVERFLOW  = (0x02<<0),
00078         TWIM_RESULT_ARBITRATION_LOST = (0x03<<0),
00079         TWIM_RESULT_BUS_ERROR        = (0x04<<0),
00080         TWIM_RESULT_NACK_RECEIVED    = (0x05<<0),
00081         TWIM_RESULT_FAIL             = (0x06<<0),
00082 } TWIM_RESULT_t;
00083 
00085 #define TWIM_WRITE_BUFFER_SIZE         8
00086 #define TWIM_READ_BUFFER_SIZE          8
00087 
00088 
00094 typedef struct TWI_Master {
00095         TWI_t *interface;                  
00096         register8_t address;                            
00097         register8_t writeData[TWIM_WRITE_BUFFER_SIZE];  
00098         register8_t readData[TWIM_READ_BUFFER_SIZE];    
00099         register8_t bytesToWrite;                       
00100         register8_t bytesToRead;                        
00101         register8_t bytesWritten;                       
00102         register8_t bytesRead;                          
00103         register8_t status;                             
00104         register8_t result;                             
00105 }TWI_Master_t;
00106 
00107 
00108 
00109 void TWI_MasterInit(TWI_Master_t *twi,
00110                     TWI_t *module,
00111                     TWI_MASTER_INTLVL_t intLevel,
00112                     uint8_t baudRateRegisterSetting);
00113 TWI_MASTER_BUSSTATE_t TWI_MasterState(TWI_Master_t *twi);
00114 bool TWI_MasterReady(TWI_Master_t *twi);
00115 bool TWI_MasterWrite(TWI_Master_t *twi,
00116                      uint8_t address,
00117                      uint8_t * writeData,
00118                      uint8_t bytesToWrite);
00119 bool TWI_MasterRead(TWI_Master_t *twi,
00120                     uint8_t address,
00121                     uint8_t bytesToRead);
00122 bool TWI_MasterWriteRead(TWI_Master_t *twi,
00123                          uint8_t address,
00124                          uint8_t *writeData,
00125                          uint8_t bytesToWrite,
00126                          uint8_t bytesToRead);
00127 void TWI_MasterInterruptHandler(TWI_Master_t *twi);
00128 void TWI_MasterArbitrationLostBusErrorHandler(TWI_Master_t *twi);
00129 void TWI_MasterWriteHandler(TWI_Master_t *twi);
00130 void TWI_MasterReadHandler(TWI_Master_t *twi);
00131 void TWI_MasterTransactionFinished(TWI_Master_t *twi, uint8_t result);
00132 
00133 
00147 #endif /* TWI_MASTER_DRIVER_H */
@DOC_TITLE@
Generated on Tue Aug 11 12:42:12 2009 for AVR1308 Using the XMEGA TWI by doxygen 1.5.9