/* ********************************************************************* * Knihovna: I2C * Projekt: DUNIT * Prekladac: AVR-GCC * Autor: Tomas Kakac (c)2010 * Datum: 2010-04-08 * Verze: 1.0 * Popis: Knihovna funkci I2C master ********************************************************************* */ #include #include #include "I2C.h" #ifndef F_CPU #define F_CPU 14745600UL // frekvence hodin CPU #endif #define SCL_CK 100000L // frekvence hodin I2C /* Inicializace rozhrani sbernice I2C ----------------------------- */ /* Vstup: - */ /* Vraci: - */ /* ---------------------------------------------------------------- */ void i2c_init(void) { TWSR = 0; // bez predrazene delicky TWBR = ((F_CPU/SCL_CK)-16)/2; // pro stabilni funkci musi byt > 10 } /* Vystaveni podminky START a vyslani adresy + smeru prenosu ------ */ /* Vstup: adresa I2C zarizeni a smer prenosu */ /* Vraci: 0 = zarizeni je dostupne */ /* 1 = neuspesny pristup k zarizeni */ /* ---------------------------------------------------------------- */ extern unsigned char i2c_start(unsigned char addr) { uint8_t twst; TWCR = (1<