Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

USI_TWI_Master.h

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation.
00033 #include <iotiny24.h>   // standard IAR header file with 4.11A and later
00034 
00035 //********** Defines **********//
00036 
00037 // Defines controlling timing limits
00038 //#define TWI_FAST_MODE
00039 
00040 #define SYS_CLK   1000.0  // [kHz]
00041 
00042 #ifdef TWI_FAST_MODE               // TWI FAST mode timing limits. SCL = 100-400kHz
00043   #define T2_TWI    ((SYS_CLK *1300) /1000000) +1 // >1,3us
00044   #define T4_TWI    ((SYS_CLK * 600) /1000000) +1 // >0,6us
00045 
00046 #else                              // TWI STANDARD mode timing limits. SCL <= 100kHz
00047   #define T2_TWI    ((SYS_CLK *4700) /1000000) +1 // >4,7us
00048   #define T4_TWI    ((SYS_CLK *4000) /1000000) +1 // >4,0us
00049 #endif
00050 
00051 // Defines controling code generating
00052 //#define PARAM_VERIFICATION
00053 //#define NOISE_TESTING
00054 //#define SIGNAL_VERIFY
00055 
00056 //USI_TWI messages and flags and bit masks
00057 //#define SUCCESS   7
00058 //#define MSG       0
00059 /****************************************************************************
00060   Bit and byte definitions
00061 ****************************************************************************/
00062 
00063 #define W                               0                                       //Data transfer direction WRITE
00064 #define R                               1                                       //Data transfer direction READ
00065 #define OWN_ADR                 60                              //Own slave address
00066 #define SUCCESS                 0xFF
00067 
00068 #define TWI_READ_BIT  0       // Bit position for R/W bit in "address byte".
00069 #define TWI_ADR_BITS  1       // Bit position for LSB of the slave address bits in the init byte.
00070 #define TWI_NACK_BIT  0       // Bit position for (N)ACK bit.
00071 
00072 #define USI_TWI_NO_DATA             0x00  // Transmission buffer is empty
00073 #define USI_TWI_DATA_OUT_OF_BOUND   0x01  // Transmission buffer is outside SRAM space
00074 #define USI_TWI_UE_START_CON        0x02  // Unexpected Start Condition
00075 #define USI_TWI_UE_STOP_CON         0x03  // Unexpected Stop Condition
00076 #define USI_TWI_UE_DATA_COL         0x04  // Unexpected Data Collision (arbitration)
00077 #define USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data
00078 #define USI_TWI_NO_ACK_ON_ADDRESS   0x06  // The slave did not acknowledge  the address
00079 #define USI_TWI_MISSING_START_CON   0x07  // Generated Start Condition not detected on bus
00080 #define USI_TWI_MISSING_STOP_CON    0x08  // Generated Stop Condition not detected on bus
00081 
00082 // Device dependant defines: these are ATtin24 specific
00083 #define DDR_USI             DDRA
00084 #define PORT_USI            PORTA
00085 #define PIN_USI             PINA
00086 #define PORT_USI_SDA        PORTA6
00087 #define PORT_USI_SCL        PORTA4
00088 #define PIN_USI_SDA         PINA6
00089 #define PIN_USI_SCL         PINA4
00090 
00091 #define TRUE  1
00092 #define FALSE 0
00093 
00094 /****************************************************************************
00095         Struct definitions
00096         tx_type is the data struct used as input to the "Send_to_TWI" function
00097         and contain information about:
00098         Slave address
00099         Send or receive data to/from the slave
00100         Number of bytes to send or receive
00101         Pointer to a buffer containing the bytes to send, or to a buffer for the
00102         bytes to receive
00103 ****************************************************************************/
00104 typedef struct
00105 {
00106   unsigned char slave_adr;          //Slave address and W/R byte
00107   unsigned char size;               //Number of bytes to send or receive        
00108   unsigned char *data_ptr;          //Pointer to bytes to send or to RX buffer
00109 } tx_type;
00110 
00111 //********** Prototypes **********//
00112 
00113 void              USI_TWI_Master_Initialise( void );
00114 unsigned char     USI_TWI_Start_Transceiver_With_Data(unsigned char *, unsigned char);
00115 //__x unsigned char USI_TWI_Start_Transceiver_With_Data(unsigned char *, unsigned char);
00116 //unsigned char     USI_TWI_Start_Transceiver_With_Data(tx_type*);
00117 unsigned char     USI_TWI_LCD_Test(void);
00118 unsigned char     USI_TWI_Get_State_Info( void );
00119 
00120 #pragma vector = USI_START_vect
00121 __interrupt void USI_START_ISR(void);

Generated on Mon Oct 10 15:25:09 2005 for AVR245: Code Lock with 4x4 Keypad and I2C(TM) LCD by  doxygen 1.4.4