So, die Ansteuerung funktioniert jetzt![]()
Code:oid i2c_init(void) { TWBR = (1 << 5) | (1 << 1) | (1 << 3); //TWBR = 11 } void i2c_send_stop(void) { TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO); while(!(TWCR & (1 << TWSTO))); } int i2c_read_ack(void) { TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); while(!(TWCR & (1<<TWINT))); if(!(TWSR & 0x50)) return -1; return TWDR; } int i2c_read_nack(void) { TWCR = (1<<TWINT) | (1<<TWEN); while(!(TWCR & (1<<TWINT))); if(!(TWSR & 0x58)) return -1; return TWDR; } int i2c_send_start(uint8_t adress) { TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); //Sende start Condition while(!(TWCR & (1 << TWINT))); //Warte bis ende if(!(TWSR & 0x08)) return -1; TWDR = adress; TWCR = (1 << TWINT) | (1 << TWEN); while(!(TWCR & (1 << TWINT))); if(!(TWSR & 0x40)) return(-2); return 0; } void readfromLM75(uint8_t *temp, uint8_t *nachkomma) { i2c_send_start(LM75_ADRESS | 1); //Sende Adresse + Read *temp = i2c_read_ack(); *nachkomma = i2c_read_nack(); i2c_send_stop(); if(bit_is_set(*nachkomma, 7)) *nachkomma = 5; else *nachkomma = 0; }







Zitieren

Lesezeichen