stimmt das wär wohl ganz nützlich:
also ich hab folgenden code hier um forum gefunden:
Code:
int read2_compass()
{
int data;
i2c_start(0xc0); // start the I2C bus
i2c_write(0xc1); // device address of the compass
i2c_write(1); // memory address first part
i2c_stop();
i2c_start(0xc1); // restart
data = i2c_readAck(); // read 1 byte
data += i2c_readNak(); // read 1 byte
i2c_stop(); // stopp
return data; // return the number of direction
}
das hat aber nicht wirklich funktioniert, also hab ich selber was geschrieben:
Code:
int read_compass()
{
int data_1;
int data_2;
int value;
i2c_start(compass_add+I2C_WRITE);
i2c_write(2);
i2c_stop();
i2c_start(compass_add+I2C_READ);
data_1=i2c_readNak();
i2c_stop();
i2c_start(compass_add+I2C_WRITE);
i2c_write(3);
i2c_stop();
i2c_start(compass_add+I2C_READ);
data_2=i2c_readNak();
i2c_stop();
value=(data_1*256)+data_2;
return value;
}
Für beides sind die bibliotheken von Peter Fleury benutzt worden, vielleicht weiß ja jemand was dararn nicht stimmt
Lesezeichen