Hallo RoboPunk,
ganz egal ist es nicht, ob man NXTs I2C-Routinen kennt. Hier 'mal der CMPS03-Lesecode für den RP6. Es wird nur 1 Byte (Datareg) gesendet, dann werden entweder 1 oder 2 Bytes vom CMPS03 gelesen.
Vielleicht kannst du das ja auf deine I2C-Routinen anpassen.
Die Geschichte mit "Startbit" verstehe ich bei dir gar nicht,- evtl. ganz weglassen.
Gruß Dirk
Code:
// The I2C slave address of the compass module CMPS03 is 0xC0:
#define CMPS03_ADR 0xC0
// CMPS03 Data Registers:
#define GET_VERSION 0 // Software version
#define MEASURE_8_BIT 1 // 8-bit compass value
#define MEASURE_16_BIT 2 // 16-bit compass value
#define CALIBRATE 15 // Calibration (write only)
/**
* READ CMPS03 DATA REGISTERS
*
* This function reads the data registers of the CMPS03.
*
* datareg = 0 : Get the CMPS03 software version
* datareg = 1 : Read 8-bit compass value [0..254]
* datareg = 2 : Read 16-bit compass value [0..3599]
*
*/
uint16_t readCMPS03(uint8_t datareg)
{uint16_t result = 0xffff; uint8_t results[3];
I2CTWI_transmitByte(CMPS03_ADR, datareg);
if (datareg == MEASURE_16_BIT) {
I2CTWI_readBytes(CMPS03_ADR, results, 2);
result = (results[0] << 8) + results[1];
}
else {
result = I2CTWI_readByte(CMPS03_ADR);
}
return result;
}
Lesezeichen