Example #1
0
void MS5837::init() {
    // Reset the MS5837, per datasheet
    Wire.beginTransmission(MS5837_ADDR);
    Wire.write(MS5837_RESET);
    Wire.endTransmission();

    // Wait for reset to complete
    delay(10);

    // Read calibration values and CRC
    for ( uint8_t i = 0 ; i < 8 ; i++ ) {
        Wire.beginTransmission(MS5837_ADDR);
        Wire.write(MS5837_PROM_READ+i*2);
        Wire.endTransmission();

        Wire.requestFrom(MS5837_ADDR,2);
        C[i] = (Wire.read() << 8) | Wire.read();
    }

    // Verify that data is correct with CRC
    uint8_t crcRead = C[0] >> 12;
    uint8_t crcCalculated = crc4(C);

    if ( crcCalculated == crcRead ) {
        // Success
    } else {
        // Failure - try again?
    }
}
Example #2
0
int MS5837::init()
{
    // Reset the MS5837, per datasheet
    Wire.beginTransmission(MS5837_ADDR);
    if (Wire.write(MS5837_RESET) != 1)
    {
        return -1;
    }

    if (Wire.endTransmission())
    {
        return -1;
    }

    // Wait for reset to complete
    delay(10);

    // Read calibration values and CRC
    for (uint8_t i = 0 ; i < 7 ; i++)
    {
        Wire.beginTransmission(MS5837_ADDR);
        if (Wire.write(MS5837_PROM_READ+i*2) != 1)
        {
            return -1;
        }

        if (Wire.endTransmission())
        {
            return -1;
        }

        if (Wire.requestFrom(MS5837_ADDR, 2) != 2)
        {
            return -1;
        }

        C[i] = (Wire.read() << 8) | Wire.read();
    }

    // Verify that data is correct with CRC
    uint8_t crcRead = C[0] >> 12;

    return (crc4(C) != crcRead);
}
Example #3
0
bool MS5837::readProm() {
	// Read calibration values and CRC
	for (uint8_t i = 0 ; i < 8 ; i++) {
		Wire.beginTransmission(MS5837_ADDR);
		Wire.write(MS5837_PROM_READ+i*2);
		Wire.endTransmission();

		Wire.requestFrom(MS5837_ADDR,2);
		C[i] = (Wire.read() << 8) | Wire.read();
	}

	// Verify that data is correct with CRC
	uint8_t crcRead = C[0] >> 12;
	uint8_t crcCalculated = crc4(C);

	if (crcCalculated == crcRead) {
		// succses
		return true;
	}
	// Fail
	return false;
}