Пример #1
0
        private async Task Begin()
        {
            Debug.WriteLine("BME280::Begin");
            byte[] WriteBuffer = new byte[] { (byte)eRegisters.BME280_REGISTER_CHIPID };
            byte[] ReadBuffer  = new byte[] { 0xFF };

            //Read the device signature
            bme280.WriteRead(WriteBuffer, ReadBuffer);
            Debug.WriteLine("BME280::Signature: " + ReadBuffer[0].ToString());

            //Verify the device signature
            if (ReadBuffer[0] != BME280_Signature)
            {
                Debug.WriteLine("BME280::Begin Signature Mismatch.");
                return;
            }

            //Set the initalize variable to true
            init = true;

            //Read the coefficients table
            CalibrationData = await ReadCoefficeints();

            //Write control register
            await WriteControlRegister();

            //Write humidity control register
            await WriteControlRegisterHumidity();
        }
Пример #2
0
        //Method to read the caliberation data from the registers
        private async Task <BME280_CalibrationData> ReadCoefficeints()
        {
            // 16 bit calibration data is stored as Little Endian, the helper method will do the byte swap.
            CalibrationData = new BME280_CalibrationData();

            // Read temperature calibration data
            CalibrationData.dig_T1 = ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_T1);
            CalibrationData.dig_T2 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_T2);
            CalibrationData.dig_T3 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_T3);

            // Read presure calibration data
            CalibrationData.dig_P1 = ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P1);
            CalibrationData.dig_P2 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P2);
            CalibrationData.dig_P3 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P3);
            CalibrationData.dig_P4 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P4);
            CalibrationData.dig_P5 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P5);
            CalibrationData.dig_P6 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P6);
            CalibrationData.dig_P7 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P7);
            CalibrationData.dig_P8 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P8);
            CalibrationData.dig_P9 = (Int16)ReadUInt16_LittleEndian((byte)eRegisters.BME280_REGISTER_DIG_P9);

            CalibrationData.dig_H1 = ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H1_REG);
            CalibrationData.dig_H2 = (Int16)((ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H2_MSB) << 8) | ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H2_LSB));
            CalibrationData.dig_H3 = ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H3_REG);
            CalibrationData.dig_H4 = (Int16)((ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H4_MSB) << 4) | (ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H4_LSB) & 0xF));
            CalibrationData.dig_H5 = (Int16)((ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H5_MSB) << 4) | (ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H5_LSB) >> 4));
            CalibrationData.dig_H6 = ReadByte((byte)eRegisters.BME280_REGISTER_DIG_H6_REG);


            //p_bme280->cal_param.dig_H1 = a_data_u8[BME280_HUMIDITY_CALIB_DIG_H1];

            //com_rslt += p_bme280->BME280_BUS_READ_FUNC(
            //p_bme280->dev_addr,
            //BME280_HUMIDITY_CALIB_DIG_H2_LSB_REG, a_data_u8,
            //BME280_HUMIDITY_CALIB_DATA_LENGTH);

            //p_bme280->cal_param.dig_H2 = (s16)((((s16)((s8)a_data_u8[BME280_HUMIDITY_CALIB_DIG_H2_MSB])) << BME280_SHIFT_BIT_POSITION_BY_08_BITS) | a_data_u8[BME280_HUMIDITY_CALIB_DIG_H2_LSB]);

            //p_bme280->cal_param.dig_H3 = a_data_u8[BME280_HUMIDITY_CALIB_DIG_H3];

            //p_bme280->cal_param.dig_H4 = (s16)((( (s16)((s8)a_data_u8[ BME280_HUMIDITY_CALIB_DIG_H4_MSB])) << BME280_SHIFT_BIT_POSITION_BY_04_BITS) |
            //(((u8)BME280_MASK_DIG_H4) & a_data_u8[BME280_HUMIDITY_CALIB_DIG_H4_LSB]));

            //p_bme280->cal_param.dig_H5 = (s16)((( (s16)((s8)a_data_u8[ BME280_HUMIDITY_CALIB_DIG_H5_MSB])) << BME280_SHIFT_BIT_POSITION_BY_04_BITS) |
            //(a_data_u8[BME280_HUMIDITY_CALIB_DIG_H4_LSB] >> BME280_SHIFT_BIT_POSITION_BY_04_BITS));

            //p_bme280->cal_param.dig_H6 = (s8)a_data_u8[BME280_HUMIDITY_CALIB_DIG_H6];

            await Task.Delay(1);

            return(CalibrationData);
        }