Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/130.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 试图让i2c压力传感器将数据发送到ATtiny85,但我可用的库给了我';未申报的';错误_C++_Arduino_I2c_Attiny - Fatal编程技术网

C++ 试图让i2c压力传感器将数据发送到ATtiny85,但我可用的库给了我';未申报的';错误

C++ 试图让i2c压力传感器将数据发送到ATtiny85,但我可用的库给了我';未申报的';错误,c++,arduino,i2c,attiny,C++,Arduino,I2c,Attiny,我正在尝试将LPS331AP压力传感器连接到我的ATtiny85上,以便从中读取压力。我的代码在Arduino Uno上完美地工作,但是当在多个论坛上进行相关更改时,我会遇到一些我不太知道如何解决的错误。我正在使用Wire.h、twi.h、TinyWire.h和LPS.h库,但没有用 我曾尝试编辑库以符合不同的函数错误,并声明了pin,但我无法让它工作。我已经重置了所有内容,我使用的代码和库如下所示: #include <TinyWire.h> #include "USI_TWI_M

我正在尝试将LPS331AP压力传感器连接到我的ATtiny85上,以便从中读取压力。我的代码在Arduino Uno上完美地工作,但是当在多个论坛上进行相关更改时,我会遇到一些我不太知道如何解决的错误。我正在使用Wire.h、twi.h、TinyWire.h和LPS.h库,但没有用

我曾尝试编辑库以符合不同的函数错误,并声明了pin,但我无法让它工作。我已经重置了所有内容,我使用的代码和库如下所示:

#include <TinyWire.h>
#include "USI_TWI_Master.h"

#include <LPS.h>

LPS ps;

void setup()
{
  TinyWire.begin();

  ps.enableDefault();
}

void loop()
{
  float pressure = ps.readPressureMillibars();
  float altitude = ps.pressureToAltitudeMeters(pressure);
  float temperature = ps.readTemperatureC();

  delay(100);
}
我尝试执行的代码如下所示:

#include <TinyWire.h>
#include "USI_TWI_Master.h"

#include <LPS.h>

LPS ps;

void setup()
{
  TinyWire.begin();

  ps.enableDefault();
}

void loop()
{
  float pressure = ps.readPressureMillibars();
  float altitude = ps.pressureToAltitudeMeters(pressure);
  float temperature = ps.readTemperatureC();

  delay(100);
}
我使用的库如下所示。.h和.c库位于我的本地项目文件夹中:

TinyWire.h:

/*****************************************************************************
    *
    *
    * File              TinyWire.h
    * Date              Saturday, 10/29/17
    * Composed by       lucullus
 *********************************************************************************/

#ifndef tiny_twi_h
#define tiny_twi_h
    #include <inttypes.h>

    //********** Master Error Codes **********//
    // Note these have been renumbered from the Atmel Apps Note. Most likely errors are now
    //      lowest numbers so they're easily recognized as LED flashes.
    #define USI_TWI_NO_DATA             0x08  // Transmission buffer is empty
    #define USI_TWI_DATA_OUT_OF_BOUND   0x09  // Transmission buffer is outside SRAM space
    #define USI_TWI_UE_START_CON        0x07  // Unexpected Start Condition
    #define USI_TWI_UE_STOP_CON         0x06  // Unexpected Stop Condition
    #define USI_TWI_UE_DATA_COL         0x05  // Unexpected Data Collision (arbitration)
    #define USI_TWI_NO_ACK_ON_DATA      0x02  // The slave did not acknowledge  all data
    #define USI_TWI_NO_ACK_ON_ADDRESS   0x01  // The slave did not acknowledge  the address
    #define USI_TWI_MISSING_START_CON   0x03  // Generated Start Condition not detected on bus
    #define USI_TWI_MISSING_STOP_CON    0x04  // Generated Stop Condition not detected on bus
    #define USI_TWI_BAD_MEM_READ        0x0A  // Error during external memory read
    #define USI_TWI_BUS_BUSY            0x0B  // Another Master is using the bus
    #define USI_TWI_ARBITRATION_LOST    0x0C  // The master lost the arbitration due to the transmission of another master

    //********** Class Definition **********//
    class TinyTwi
    {
        private:
        bool master_mode=false;
        bool temp_master_mode=false;
        uint8_t slave_addr=0;
        static void (*user_onRequest)(void);
        static void (*user_onReceive)(int);
        static void onRequestService(void);
        static void onReceiveService(int numBytes);

        public:
        TinyTwi();
        void begin();
        void begin(uint8_t I2C_SLAVE_ADDR);
        uint8_t read();
        uint8_t receive();
        uint8_t available();
        uint8_t send(uint8_t data);
        uint8_t write(uint8_t data);
        void beginTransmission(uint8_t slaveAddr);
        uint8_t endTransmission();
        uint8_t requestFrom(uint8_t slaveAddr, uint8_t numBytes);
        void end();

        void onReceive( void (*)(int) );
        void onRequest( void (*)(void) );
    };

    extern TinyTwi TinyWire;

#endif
/*****************************************************************************
*
*
*文件TinyWire.h
*日期17年10月29日星期六
*卢库卢斯作曲
*********************************************************************************/
#如果有微小的两个
#定义微小的两个
#包括
//**********主错误代码**********//
//注意:这些已从Atmel应用程序注释中重新编号。最有可能的错误是现在
//最低的数字,因此很容易识别为LED闪烁。
#定义USI_TWI_NO_数据0x08//传输缓冲区为空
#定义USI_TWI_DATA_OUT_OF_BOUND 0x09//传输缓冲区在SRAM空间之外
#定义USI_TWI_UE_START_CON 0x07//意外启动条件
#定义USI_TWI_UE_STOP_CON 0x06//意外停止条件
#定义USI_TWI_UE_DATA_COL 0x05//意外数据冲突(仲裁)
#在数据0x02//上定义USI_TWI_NO_ACK_//从机未确认所有数据
#在地址0x01上定义USI_TWI_NO_ACK_//从机未确认该地址
#定义USI\u TWI\u缺少启动\u CON 0x03//在总线上未检测到生成的启动条件
#定义USI\u TWI\u缺少停止\u CON 0x04//在总线上未检测到生成的停止条件
#定义USI_TWI_BAD_MEM_READ 0x0A//外部内存读取期间出错
#定义USI_TWI_总线\u BUSY 0x0B//另一个主机正在使用该总线
#定义USI_TWI_仲裁_LOST 0x0C//由于另一个主机的传输,主机丢失了仲裁
//**********类定义**********//
TinyTwi类
{
私人:
bool master_mode=false;
bool temp_master_mode=假;
uint8从站地址=0;
静态无效(*用户请求)(无效);
静态无效(*用户接收)(int);
静态void onRequestService(void);
接收服务时静态无效(整数字节);
公众:
TinyTwi();
void begin();
无效开始(uint8_t I2C_SLAVE_ADDR);
uint8_t read();
uint8_t receive();
uint8_t可用();
uint8_t发送(uint8_t数据);
uint8_t写入(uint8_t数据);
无效开始传送(uint8\u t slaveAddr);
uint8_t end transmission();
uint8_t请求源(uint8_t slaveAddr,uint8_t numBytes);
空端();
接收无效(无效(*)(int));
一经请求无效(无效(*)(无效));
};
外部TinyTwi TinyWire;
#恩迪夫
LPS.h:

#ifndef LPS_h
#define LPS_h

#include <Arduino.h> // for byte data type

class LPS
{
  public:
    enum deviceType { device_331AP, device_25H, device_auto };
    enum sa0State { sa0_low, sa0_high, sa0_auto };

    // register addresses
    // Note: where register names differ between the register mapping table and
    // the register descriptions in the datasheets, the names from the register
    // descriptions are used here.
    enum regAddr
    {
      REF_P_XL                = 0x08,
      REF_P_L                 = 0x09,
      REF_P_H                 = 0x0A,

      WHO_AM_I                = 0x0F,

      RES_CONF                = 0x10,

      CTRL_REG1               = 0x20,
      CTRL_REG2               = 0x21,
      CTRL_REG3               = 0x22,
      CTRL_REG4               = 0x23, // 25H

      STATUS_REG              = 0x27,

      PRESS_OUT_XL            = 0x28,
      PRESS_OUT_L             = 0x29,
      PRESS_OUT_H             = 0x2A,

      TEMP_OUT_L              = 0x2B,
      TEMP_OUT_H              = 0x2C,

      FIFO_CTRL               = 0x2E, // 25H
      FIFO_STATUS             = 0x2F, // 25H

      AMP_CTRL                = 0x30, // 331AP

      RPDS_L                  = 0x39, // 25H
      RPDS_H                  = 0x3A, // 25H

      DELTA_PRESS_XL          = 0x3C, // 331AP
      DELTA_PRESS_L           = 0x3D, // 331AP
      DELTA_PRESS_H           = 0x3E, // 331AP


      // dummy addresses for registers in different locations on different devices;
      // the library translates these based on device type
      // value with sign flipped is used as index into translated_regs array

      INTERRUPT_CFG    = -1,
      INT_SOURCE       = -2,
      THS_P_L          = -3,
      THS_P_H          = -4,
      // update dummy_reg_count if registers are added here!


      // device-specific register addresses

      LPS331AP_INTERRUPT_CFG  = 0x23,
      LPS331AP_INT_SOURCE     = 0x24,
      LPS331AP_THS_P_L        = 0x25,
      LPS331AP_THS_P_H        = 0x26,

      LPS25H_INTERRUPT_CFG    = 0x24,
      LPS25H_INT_SOURCE       = 0x25,
      LPS25H_THS_P_L          = 0x30,
      LPS25H_THS_P_H          = 0x31,
    };

    LPS(void);

    bool init(deviceType device = device_auto, byte sa0 = sa0_auto);
    deviceType getDeviceType(void) { return _device; }
    byte getAddress(void) { return address; }

    void enableDefault(void);

    void writeReg(int reg, byte value);
    byte readReg(int reg);

    float readPressureMillibars(void);
    float readPressureInchesHg(void);
    int32_t readPressureRaw(void);
    float readTemperatureC(void);
    float readTemperatureF(void);
    int16_t readTemperatureRaw(void);

    static float pressureToAltitudeMeters(float pressure_mbar, float altimeter_setting_mbar = 1013.25);
    static float pressureToAltitudeFeet(float pressure_inHg, float altimeter_setting_inHg = 29.9213);

  private:
    deviceType _device; // chip type (331AP or 25H)
    byte address;

    static const int dummy_reg_count = 4;
    regAddr translated_regs[dummy_reg_count + 1]; // index 0 not used

    bool detectDeviceAndAddress(deviceType device, sa0State sa0);
    bool detectDevice(deviceType device);
    int testWhoAmI(byte address);
};

#endif
\ifndef LPS\u h
#定义LPS_h
#包含//字节数据类型
LPS类
{
公众:
枚举设备类型{device_331; ap,device_25H,device_auto};
枚举sa0State{sa0_低,sa0_高,sa0_自动};
//注册地址
//注:其中寄存器映射表和
//数据表中的寄存器描述,寄存器中的名称
//这里使用描述。
枚举地址
{
REF_P_XL=0x08,
REF_P_L=0x09,
REF_P_H=0x0A,
我是谁?我=0x0F,
RES_CONF=0x10,
CTRL_REG1=0x20,
CTRL_REG2=0x21,
CTRL_REG3=0x22,
CTRL_REG4=0x23,//25H
状态_REG=0x27,
按下\u OUT\u XL=0x28,
按出=0x29,
按下按钮H=0x2A,
温度输出=0x2B,
温度输出H=0x2C,
先进先出控制=0x2E,//25H
先进先出状态=0x2F,//25H
AMP_CTRL=0x30,//331AP
RPDS_L=0x39,//25H
RPDS_H=0x3A,//25H
DELTA_PRESS_XL=0x3C,//331AP
DELTA_PRESS_L=0x3D,//331AP
DELTA_PRESS_H=0x3E,//331AP
//不同设备上不同位置寄存器的虚拟地址;
//库根据设备类型转换这些内容
//符号翻转的值用作转换后的_regs数组的索引
中断\u CFG=-1,
INT_SOURCE=-2,
THS_P_L=-3,
th_P_H=-4,
//如果此处添加了寄存器,则更新虚拟\u reg\u计数!
//设备特定寄存器地址
LPS331AP\u中断\u CFG=0x23,
LPS331AP_INT_SOURCE=0x24,
LPS331AP_th_P_L=0x25,
LPS331AP_th_P_H=0x26,
LPS25H_中断_CFG=0x24,
LPS25H_INT_源=0x25,
LPS25H_th_P_L=0x30,
LPS25H_th_P_H=0x31,
};
LPS(void);
bool init(设备类型device=device\u auto,字节sa0=sa0\u auto);
deviceType getDeviceType(void){return\u device;}
字节getAddress(void){返回地址;}
void enablefault(void);
void writeReg(int reg,字节值);
字节readReg(int reg);
浮动读写库(无效);
浮子读数压力Incheshg(空隙);
int32_t readPressureRaw(无效);
浮动区
/*****************************************************************************
*
* Atmel Corporation
*
* File              : USI_TWI_Master.h
* Compiler          : AVRGCC Toolchain version 3.4.2
* Revision          : $Revision: 992 $
* Date              : $Date: 2013-11-07 $
* Updated by        : $Author: Atmel $
*
* Support mail      : avr@atmel.com
*
* Supported devices : All device with USI module can be used.
*                     The example is written for the ATmega169, ATtiny26 and ATtiny2313
*
* AppNote           : AVR310 - Using the USI module as a TWI Master
*
* Description       : This is an implementation of an TWI master using
*                     the USI module as basis. The implementation assumes the AVR to
*                     be the only TWI master in the system and can therefore not be
*                     used in a multi-master system.
* Usage             : Initialize the USI module by calling the USI_TWI_Master_Initialise() 
*                     function. Hence messages/data are transceived on the bus using
*                     the USI_TWI_Start_Transceiver_With_Data() function. If the transceiver
*                     returns with a fail, then use USI_TWI_Get_Status_Info to evaluate the 
*                     couse of the failure.
*
****************************************************************************/
    #include<avr/io.h> 
//********** Defines **********//

// Defines controlling timing limits
#define TWI_FAST_MODE

#define SYS_CLK   4000.0  // [kHz]

#ifdef TWI_FAST_MODE               // TWI FAST mode timing limits. SCL = 100-400kHz
  #define T2_TWI    ((SYS_CLK *1300) /1000000) +1 // >1,3us
  #define T4_TWI    ((SYS_CLK * 600) /1000000) +1 // >0,6us

#else                              // TWI STANDARD mode timing limits. SCL <= 100kHz
  #define T2_TWI    ((SYS_CLK *4700) /1000000) +1 // >4,7us
  #define T4_TWI    ((SYS_CLK *4000) /1000000) +1 // >4,0us
#endif

// Defines controling code generating
//#define PARAM_VERIFICATION
//#define NOISE_TESTING
//#define SIGNAL_VERIFY

//USI_TWI messages and flags and bit masks
//#define SUCCESS   7
//#define MSG       0
/****************************************************************************
  Bit and byte definitions
****************************************************************************/
#define TWI_READ_BIT  0       // Bit position for R/W bit in "address byte".
#define TWI_ADR_BITS  1       // Bit position for LSB of the slave address bits in the init byte.
#define TWI_NACK_BIT  0       // Bit position for (N)ACK bit.

#define USI_TWI_NO_DATA             0x00  // Transmission buffer is empty
#define USI_TWI_DATA_OUT_OF_BOUND   0x01  // Transmission buffer is outside SRAM space
#define USI_TWI_UE_START_CON        0x02  // Unexpected Start Condition
#define USI_TWI_UE_STOP_CON         0x03  // Unexpected Stop Condition
#define USI_TWI_UE_DATA_COL         0x04  // Unexpected Data Collision (arbitration)
#define USI_TWI_NO_ACK_ON_DATA      0x05  // The slave did not acknowledge  all data
#define USI_TWI_NO_ACK_ON_ADDRESS   0x06  // The slave did not acknowledge  the address
#define USI_TWI_MISSING_START_CON   0x07  // Generated Start Condition not detected on bus
#define USI_TWI_MISSING_STOP_CON    0x08  // Generated Stop Condition not detected on bus

// Device dependant defines

#if defined(__AVR_AT90Mega169__) | defined(__AVR_ATmega169PA__) | \
    defined(__AVR_AT90Mega165__) | defined(__AVR_ATmega165__) | \
    defined(__AVR_ATmega325__) | defined(__AVR_ATmega3250__) | \
    defined(__AVR_ATmega645__) | defined(__AVR_ATmega6450__) | \
    defined(__AVR_ATmega329__) | defined(__AVR_ATmega3290__) | \
    defined(__AVR_ATmega649__) | defined(__AVR_ATmega6490__)
    #define DDR_USI             DDRE
    #define PORT_USI            PORTE
    #define PIN_USI             PINE
    #define PORT_USI_SDA        PORTE5
    #define PORT_USI_SCL        PORTE4
    #define PIN_USI_SDA         PINE5
    #define PIN_USI_SCL         PINE4
#endif

#if defined(__AVR_ATtiny25__) | defined(__AVR_ATtiny45__) | defined(__AVR_ATtiny85__) | \
    defined(__AVR_AT90Tiny26__) | defined(__AVR_ATtiny26__)
    #define DDR_USI             DDRB
    #define PORT_USI            PORTB
    #define PIN_USI             PINB
    #define PORT_USI_SDA        PORTB0
    #define PORT_USI_SCL        PORTB2
    #define PIN_USI_SDA         PINB0
    #define PIN_USI_SCL         PINB2
#endif

#if defined(__AVR_AT90Tiny2313__) | defined(__AVR_ATtiny2313__)
    #define DDR_USI             DDRB
    #define PORT_USI            PORTB
    #define PIN_USI             PINB
    #define PORT_USI_SDA        PORTB5
    #define PORT_USI_SCL        PORTB7
    #define PIN_USI_SDA         PINB5
    #define PIN_USI_SCL         PINB7
#endif

// General defines
#define TRUE  1
#define FALSE 0

//********** Prototypes **********//

void              USI_TWI_Master_Initialise( void );
 unsigned char USI_TWI_Start_Transceiver_With_Data( unsigned char * , unsigned char );
unsigned char USI_TWI_Get_State_Info( void );