private async Task Begin() { Debug.WriteLine("BME280::Begin"); // A buffer that contains the data that you want to write to the I2 C device. // This data should not include the bus address. byte[] writeBuffer = { (byte)RegisterMemoryAddress.RegisterChipId }; // The buffer to which you want to read the data from the I2 C bus. // The length of the buffer determines how much data to request from the device. byte[] readBuffer = { 0xFF }; // Read the device signature _bme280Device.WriteRead(writeBuffer, readBuffer); Debug.WriteLine("BME280 Signature: " + readBuffer[0]); // Verify this is the BME280 which has chip number 0x60 if (readBuffer[0] != ChipIdentificationNumber) { Debug.WriteLine("BME280::Begin Signature Mismatch."); return; } // Set the initialize variable to true _isInitialized = true; // Read the coefficients table _calibrationData = await ReadCalibrationData(); // Write control register await WriteControlRegister(); // Write humidity control register // await WriteControlRegisterHumidity(); }
/// <summary> /// To read the calibration data from the registers /// </summary> /// <returns></returns> private async Task <CalibrationData> ReadCalibrationData() { // 16 bit calibration data is stored as Little Endian, the helper method will do the byte swap. _calibrationData = new CalibrationData(); // Read temperature calibration data _calibrationData.CompensationT1 = (ushort)Read16BitValueFromAssignedMemory((byte)RegisterMemoryAddress.CompensationT1); _calibrationData.CompensationT2 = (short)Read16BitValueFromAssignedMemory((byte)RegisterMemoryAddress.CompensationT2); _calibrationData.CompensationT3 = (short)Read16BitValueFromAssignedMemory((byte)RegisterMemoryAddress.CompensationT3); await Task.Delay(1); return(_calibrationData); }