#ifndef I2C_FAST_MODE # warning: I2C_FAST_MODE not defined, assume not #endif #ifdef I2C_FAST_MODE #define I2C_T2 2 #define I2C_T4 1 #else #define I2C_T2 5 #define I2C_T4 4 #endif #define I2C8BIT 0xF0 #define I2C1BIT 0xFE ////////////////////////////////////////////////////////////////////////// //Microcontroller Dependent Definitions #if defined (__AVR_ATtiny24__) | defined (__AVR_ATtiny44__) | defined (__AVR_ATtiny84__) |\ defined (__AVR_ATtiny24A__) | defined (__AVR_ATtiny44A__) | defined (__AVR_ATtiny84A__) #define DDR_USI DDRA #define PORT_USI PORTA #define PIN_USI PINA #define USI_SDA PINA6 #define USI_SCL PINA4 #endif #if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__) #define DDR_USI DDRB #define PORT_USI PORTB #define PIN_USI PINB #define USI_SDA 5 #define USI_SCL 7 #endif /**********************************************************************/ /*! @brief Initialize USI as I2C-Master @param none @returns nothing */ /**********************************************************************/ void I2CinitM(); /**********************************************************************/ /*! @brief Transfers 8/1 bit of data, used by other functions @param config configuration for 8/1 bit @returns received data */ /**********************************************************************/ uint8_t I2Ctransfer(uint8_t config); /**********************************************************************/ /*! @brief Starts new transmission, sends address and R/!W @param address Address of device @param mode 1 Read, 0 Write @returns 1 device reacting, 0 no device reacting */ /**********************************************************************/ uint8_t I2Cstart(uint8_t address, uint8_t mode); /**********************************************************************/ /*! @brief Writes data to device @param *data data buffer with data to write @param bufsize size of data buffer @returns 1 success, 0 failure */ /**********************************************************************/ uint8_t I2Cwrite(uint8_t *data, uint8_t bufsize); /**********************************************************************/ /*! @brief Reads data from device @param *data data buffer with data to write @param bufsize size of data buffer @returns 1 success, 0 failure */ /**********************************************************************/ uint8_t I2Cread(uint8_t *data, uint8_t bufsize); /**********************************************************************/ /*! @brief Stops transmission @param none @returns nothing */ /**********************************************************************/ void I2Cstop();