如何成功重新编程MAXREFDES100#?

时间:2018-07-24 10:55:03

标签: c++

我试图对组件进行重新编程,但是从教程中编译代码时遇到了一些错误。

这是我尝试从顶部和底部温度传感器读取和打印值的代码。

#include "mbed.h"
#include "MAX14720.h"
#include "MAX30205.h"

//Define all I2C addresses
#define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
#define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
#define I2C_ADDR_PMIC (0x54)

// I2C Masters
I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205 (1), MAX30205 (2), BMP280
I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, MAX30101, LIS2DH

//Top Local Temperature Senso
MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);

//Bottom Local Temperature Sensor
MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM);

// PMIC
MAX14720 max14720(&i2c2,I2C_ADDR_PMIC);

DigitalOut led(LED1);

//Serial
Serial pc(USBTX, USBRX);

int main()
{
    max14720.boostEn = MAX14720::BOOST_ENABLED;
    max14720.init();

    led = 0;

    // Temperature Variables
    uint16_t rawTemp_top, rawTemp_bottom;
    float celsius_top, celsius_bottom;

    // Endless loop

    while(1) {
        // Read temperature
        MAX30205_top.readTemperature(&rawTemp_top);
        MAX30205_bottom.readTemperature(&rawTemp_bottom);

        // Convert to Celsius
        celsius_top = MAX30205_top.toCelsius(rawTemp_top);
        celsius_bottom = MAX30205_bottom.toCelsius(rawTemp_bottom);

        // Print Celsius Values
        pc.printf("Top Temperature: %.2f\370C\n\rBottom Temperature: %.2f\370C \n\n\r", celsius_top, celsius_bottom);

        // Wait 1 second
        wait(1);
    }
}

这里有MAX30205的库(用于温度传感器)

MAX30205.h

/*******************************************************************************
 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the name of Maxim Integrated
 * Products, Inc. shall not be used except as stated in the Maxim Integrated
 * Products, Inc. Branding Policy.
 *
 * The mere transfer of this software does not imply any licenses
 * of trade secrets, proprietary technology, copyrights, patents,
 * trademarks, maskwork rights, or any other form of intellectual
 * property whatsoever. Maxim Integrated Products, Inc. retains all
 * ownership rights.
 *******************************************************************************
 */
#ifndef __MAX30205_H_
#define __MAX30205_H_

#include "mbed.h"

/**
 * @brief Library for the MAX30205\n
 * The MAX30205 temperature sensor accurately measures temperature and provide 
 * an overtemperature alarm/interrupt/shutdown output. This device converts the 
 * temperature measurements to digital form using a high-resolution, 
 * sigma-delta, analog-to-digital converter (ADC). Accuracy meets clinical 
 * thermometry specification of the ASTM E1112 when soldered on the final PCB. 
 * Communication is through an I2C-compatible 2-wire serial interface.
 *
 * @code
 * #include "mbed.h"
 * #include "max32630fthr.h"
 * #include "MAX30205.h"
 * 
 * MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
 *
 * //Get I2C instance
 * I2C i2cBus(I2C1_SDA, I2C1_SCL);
 *
 * //Get temp sensor instance
 * MAX30205 bodyTempSensor(i2cBus, 0x4D); //Constructor takes 7-bit slave adrs
 *
 * int main(void) 
 * {
 *     //use sensor
 * }
 * @endcode
 */

class MAX30205
{

public:
    /// MAX30205 Register Addresses
    enum Registers_e 
    {
        Temperature   = 0x00,
        Configuration = 0x01,
        THYST         = 0x02,
        TOS           = 0x03
    };

    ///MAX30205 Configuration register bitfields
    union Configuration_u
    {
        uint8_t all;
        struct BitField_s
        {
            uint8_t shutdown    : 1;
            uint8_t comp_int    : 1;
            uint8_t os_polarity : 1;
            uint8_t fault_queue : 2;
            uint8_t data_format : 1;
            uint8_t timeout     : 1;
            uint8_t one_shot    : 1;
        }bits;
    };

    /**
    * @brief  Constructor using reference to I2C object
    * @param i2c - Reference to I2C object
    * @param slaveAddress - 7-bit I2C address
    */
    MAX30205(I2C &i2c, uint8_t slaveAddress);

    /** @brief Destructor */
    ~MAX30205(void);

    /**
    * @brief Read the temperature from the device into a 16 bit value
    * @param[out] value - Raw temperature data on success
    * @return 0 on success, non-zero on failure
    */
    int32_t readTemperature(uint16_t &value);

    /**
    * @brief Read the configuration register
    * @param config - Reference to Configuration type
    * @return 0 on success, non-zero on failure
    */
    int32_t readConfiguration(Configuration_u &config);

    /**
    * @brief Write the configuration register with given configuration
    * @param config - Configuration to write
    * @return 0 on success, non-zero on failure
    */
    int32_t writeConfiguration(const Configuration_u config);

    /**
    * @brief Read the THYST value from a specified device instance
    * @param[out] value - THYST register value on success
    * @return 0 on success, non-zero on failure
    */
    int32_t readTHYST(uint16_t &value);

    /**
    * @brief Write the THYST to a device instance
    * @param value - 16-bit value to write
    * @return 0 on success, non-zero on failure
    */
    int32_t writeTHYST(const uint16_t value);

    /**
    * @brief Read the TOS value from device
    * @param[out] value - TOS register value on success
    * @return 0 on success, non-zero on failure
    */
    int32_t readTOS(uint16_t &value);

    /**
    * @brief Write the TOS register
    * @param value - 16-bit value to write
    * @return 0 on success, non-zero on failure
    */
    int32_t writeTOS(const uint16_t value);

    /**
    * @brief Convert a raw temperature value into a float
    * @param rawTemp - raw temperature value to convert
    * @return the convereted value in degrees C
    */
    float toCelsius(uint32_t rawTemp);

    /**
    * @brief Convert the passed in temperature in C to Fahrenheit
    * @param temperatureC Temperature in C to convert
    * @returns Returns the converted Fahrenheit value
    */
    float toFahrenheit(float temperatureC);

protected:

    /** 
    * @brief Write register of device at slave address
    * @param reg - Register address
    * @param value - Value to write
    * @return 0 on success, non-zero on failure
    */
    int32_t writeRegister(Registers_e reg, uint16_t value);

    /**
    * @brief  Read register of device at slave address
    * @param reg - Register address
    * @param[out] value - Read data on success
    * @return 0 on success, non-zero on failure
    */
    int32_t readRegister(Registers_e reg, uint16_t &value);

private:
    /// I2C object
    I2C & m_i2c;
    /// Device slave addresses
    uint8_t m_writeAddress, m_readAddress;
};

#endif /* __MAX30205_H_ */

MAX30205.cpp

/*******************************************************************************
     * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
     *
     * Permission is hereby granted, free of charge, to any person obtaining a
     * copy of this software and associated documentation files (the "Software"),
     * to deal in the Software without restriction, including without limitation
     * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     * and/or sell copies of the Software, and to permit persons to whom the
     * Software is furnished to do so, subject to the following conditions:
     *
     * The above copyright notice and this permission notice shall be included
     * in all copies or substantial portions of the Software.
     *
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
     * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
     * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     * OTHER DEALINGS IN THE SOFTWARE.
     *
     * Except as contained in this notice, the name of Maxim Integrated
     * Products, Inc. shall not be used except as stated in the Maxim Integrated
     * Products, Inc. Branding Policy.
     *
     * The mere transfer of this software does not imply any licenses
     * of trade secrets, proprietary technology, copyrights, patents,
     * trademarks, maskwork rights, or any other form of intellectual
     * property whatsoever. Maxim Integrated Products, Inc. retains all
     * ownership rights.
     *******************************************************************************
     */


    #include "MAX30205.h"


    //******************************************************************************
    MAX30205::MAX30205(I2C &i2c, uint8_t slaveAddress): 
    m_i2c(i2c), m_writeAddress(slaveAddress << 1), 
    m_readAddress((slaveAddress << 1) | 1)
    {
    }


    //******************************************************************************
    MAX30205::~MAX30205(void) 
    {
      //empty block
    }


    //******************************************************************************
    int32_t MAX30205::readTemperature(uint16_t &value) 
    {
      return readRegister(MAX30205::Temperature, value);
    }


    //******************************************************************************
    int32_t MAX30205::readConfiguration(Configuration_u &config)
    {
        uint16_t data;

        int32_t result = readRegister(MAX30205::Configuration, data);
        if(result == 0)
        {
            config.all = (0x00FF & data);
        }

        return result;

    }


    //******************************************************************************    
    int32_t MAX30205::writeConfiguration(const Configuration_u config)
    {
        uint16_t local_config = (0x00FF & config.all);

        return writeRegister(MAX30205::Configuration, local_config);
    }


    //******************************************************************************
    int32_t MAX30205::readTHYST(uint16_t &value) 
    {
      return readRegister(MAX30205::THYST, value);
    }


    //******************************************************************************
    int32_t MAX30205::writeTHYST(uint16_t value) 
    {
      return writeRegister(MAX30205::THYST, value);
    }


    //******************************************************************************
    int32_t MAX30205::readTOS(uint16_t &value)
    {
        return readRegister(MAX30205::TOS, value);
    }


    //******************************************************************************
    int32_t MAX30205::writeTOS(const uint16_t value)
    {
        return writeRegister(MAX30205::TOS, value);
    }


    //******************************************************************************
    float MAX30205::toCelsius(uint32_t rawTemp) 
    {
      uint8_t val1, val2;
      float result;

      val1 = (rawTemp >> 8);
      val2 = (rawTemp & 0xFF);

      result = static_cast<float>(val1 + (val2/ 256.0F));

      return result;
    }


    //******************************************************************************
    float MAX30205::toFahrenheit(float temperatureC) 
    {
      return((temperatureC * 1.8F) + 32.0f);
    }


    //******************************************************************************
    int32_t MAX30205::writeRegister(Registers_e reg, uint16_t value) 
    {
      int32_t result;

      uint8_t hi = ((value >> 8) & 0xFF);
      uint8_t lo = (value & 0xFF);
      char cmdData[3] = {reg, hi, lo};

      result = m_i2c.write(m_writeAddress, cmdData, 3);

      return result;
    }


    //******************************************************************************
    int32_t MAX30205::readRegister(Registers_e reg, uint16_t &value) 
    {
      int32_t result;

      char data[2];
      char cmdData[1] = {reg};

      result = m_i2c.write(m_writeAddress, cmdData, 1);
      if(result == 0)
      {
          result = m_i2c.read(m_readAddress, data, 2);
          if (result == 0)
          {
              value = (data[0] << 8) + data[1];
          }
      }

      return result;
    }

错误如下:

  

错误:没有构造函数“ MAX30205 :: MAX30205”的实例与   “ main.cpp”中的参数列表,行:15,列:24

     

错误:没有构造函数“ MAX30205 :: MAX30205”的实例与   “ main.cpp”中的参数列表,行:17,列:27

     

错误:对非常量的引用的初始值必须为的左值   “ main.cpp”,行:42,列:39

     

错误:对非常量的引用的初始值必须为的左值   “ main.cpp”,行:43,列:42

1 个答案:

答案 0 :(得分:0)

这会将传感器值打印到终端上。

此示例还包括来自BMP280气压传感器的数据,但如果愿意,可以轻松删除。您还可以轻松添加其他MAXREFDES100传感器。

#include "mbed.h"
#include "MAX14720.h"
#include "MAX30205.h"
#include "BMP280.h"

#define HVOUT_VOLTAGE 4500 // set to 4500 mV

// Define all I2C addresses
#define MAX30205_I2C_SLAVE_ADDR_TOP (0x92)
#define MAX30205_I2C_SLAVE_ADDR_BOTTOM (0x90)
#define I2C_ADDR_PMIC (0x54)
#define BMP280_I2C_SLAVE_ADDR (0xEC)

// I2C Masters
I2C i2c1(I2C1_SDA, I2C1_SCL); // used by MAX30205 (1), MAX30205 (2), BMP280
I2C i2c2(I2C2_SDA, I2C2_SCL); // used by MAX14720, MAX30101, LIS2DH

// Top Local Temperature Sensor
MAX30205 MAX30205_top(&i2c1, MAX30205_I2C_SLAVE_ADDR_TOP);
// Bottom Local Temperature Sensor
MAX30205 MAX30205_bottom(&i2c1, MAX30205_I2C_SLAVE_ADDR_BOTTOM);
// Barometric Pressure Sensor
BMP280 bmp280_pres(&i2c1, BMP280_I2C_SLAVE_ADDR);

// PMIC
MAX14720 max14720(&i2c2,I2C_ADDR_PMIC);
DigitalOut led(LED1);

// Serial
Serial pc(USBTX, USBRX);

int main()
{
    max14720.boostEn = MAX14720::BOOST_ENABLED;
    max14720.init();
    max14720.boostSetVoltage(HVOUT_VOLTAGE);

    led = 0;

    // Initialise the BMP280
    bmp280_pres.init(BMP280::OVERSAMPLING_X16_P, BMP280::OVERSAMPLING_X2_T, BMP280::FILT_4, BMP280::NORMAL_MODE, BMP280::T_62_5);

    // Use the POR configuration register values

    // Temperature Variables
    uint16_t rawTemp_top = 0;
    uint16_t rawTemp_bottom = 0;
    char bmp280_rawData = 0;
    float celsius_top, celsius_bottom, Temp_degC, Press_Pa, Press_Bar;


    wait(2);

    // Endless Loop
    while(1) 
    {       
            // Read Temperature
            MAX30205_top.readTemperature(&rawTemp_top);
            MAX30205_bottom.readTemperature(&rawTemp_bottom);

            // Read BMP280 Temp. and Pressure
            bmp280_pres.ReadCompDataRaw(&bmp280_rawData);
            bmp280_pres.ToFloat(&bmp280_rawData, &Temp_degC, &Press_Pa);

            // Convert to Celsius
            celsius_top = MAX30205_top.toCelsius(rawTemp_top);
            celsius_bottom = MAX30205_bottom.toCelsius(rawTemp_bottom);

            Press_Bar = Press_Pa / 100000;

            // Print celsius and pressure values
            pc.printf("%.2f,%.2f,%.2f,%.2f\r\n", celsius_top, celsius_bottom, Temp_degC, Press_Bar);

            // Wait 5 seconds
            wait(5);

    }
}