首页 > 解决方案 > Infineons Tle493d_w2b6 传感器示例中的编译错误

问题描述

我正在尝试使用 Arduino Mega2560 从 Infineons Tle493d_w2b6 传感器读取数据。但是他们的示例代码由于头文件中的一些错误而无法编译,但我不知道如何修复它,也不知道实际问题出在哪里。

英飞凌在 GitHub ( https://github.com/Infineon/TLE493D-3DMagnetic-Sensor )上为他们的 Tle493d_w2b6 传感器提供了一个 Arduino 库。但是当我尝试运行他们包含的笛卡尔示例时,由于“tle493d_w2b6_conf.h”文件中的一些问题,它不会编译。

英飞凌库中提供的笛卡尔示例:

#include <Tle493d_w2b6.h>

Tle493d_w2b6 Tle493dMagnetic3DSensor = Tle493d_w2b6();
void setup() {
  Serial.begin(9600);
  while (!Serial);
  Tle493dMagnetic3DSensor.begin();
  Tle493dMagnetic3DSensor.enableTemp();
}

void loop() {
  Tle493dMagnetic3DSensor.updateData();

  Serial.print(Tle493dMagnetic3DSensor.getX());
  Serial.print(" ; ");
  Serial.print(Tle493dMagnetic3DSensor.getY());
  Serial.print(" ; ");
  Serial.println(Tle493dMagnetic3DSensor.getZ());

  delay(500);
}

tle493d_w2b6_conf.h 文件:

#ifndef TLE493D_W2B6_CONF_H_INCLUDED
#define TLE493D_W2B6_CONF_H_INCLUDED

#include "RegMask.h"

#ifndef TRUE
#define TRUE    1
#endif
#ifndef FALSE
#define FALSE   0
#endif

//master contrlled mode should be used in combination with power down mode
#define TLE493D_W2B6_DEFAULTMODE            MASTERCONTROLLEDMODE

#define TLE493D_W2B6_STARTUPDELAY       60
#define TLE493D_W2B6_RESETDELAY         30

#define TLE493D_W2B6_NUM_OF_REGMASKS        50
#define TLE493D_W2B6_NUM_OF_ACCMODES        4
#define TLE493D_W2B6_MSB_MASK           0x07F1
#define TLE493D_W2B6_LSB_MASK           0x07
#define TLE493D_W2B6_MAX_THRESHOLD      1023
#define TLE493D_W2B6_MEASUREMENT_READOUT    7

#define TLE493D_W2B6_B_MULT                 0.13
#define TLE493D_W2B6_B_MULT_LOW         2.08 //for 8 bit resolution
#define TLE493D_W2B6_TEMP_MULT          0.24 //range 0.21 to 0.27
#define TLE493D_W2B6_TEMP_MULT_LOW      3.84 //for 8 bit resolution
#define TLE493D_W2B6_TEMP_OFFSET        1180 //range 1000 to 1360
#define TLE493D_W2B6_TEMP_25                25   //room temperature offset

namespace tle493d_w2b6
{

enum Registers_e
{
    BX1 = 0,
    BX2,
    BY1,
    BY2,
    BZ1,
    BZ2,
    TEMP1,
    TEMP2,
    ID,                             //diagnosis
    P, FF, CF, T, PD3, PD0, FRM,    //diagnosis (Diag)
    XL,                             //wake up threshold MSBs
    XH,
    YL,
    YH,
    ZL,
    ZH,
    WA, WU, XH2, XL2,               //wake up (WU) & wake up threshold LSBs
    TST, YH2, YL2,                  //TMode
    PH, ZH2, ZL2,                   //TPhase
    DT, AM, TRIG, X2, TL_mag, CP,   //Config
    FP, IICadr, PR, CA, INT, MODE,  //MOD1
    Res12,
    PRD, Res13,                     //MOD2
    Res14,
    Res15, 
    Ver,
};

/**
 * @enum Registers_e
 * names of register fields
 */

const RegMask_t regMasks[] = {
    { REGMASK_READ, 0, 0xFF, 0 },       // R_BX1
    { REGMASK_READ, 4, 0xF0, 4 },       // R_BX2
    { REGMASK_READ, 1, 0xFF, 0 },       // R_BY1
    { REGMASK_READ, 4, 0x0F, 0 },       // R_BY2
    { REGMASK_READ, 2, 0xFF, 0 },       // R_BZ1
    { REGMASK_READ, 5, 0x0F, 0 },       // R_BZ2
    { REGMASK_READ, 3, 0xFF, 0 },       // R_TEMP1
    { REGMASK_READ, 5, 0xC0, 6 },       // R_TEMP2
    { REGMASK_READ, 5, 0x30, 4 },       // ID

    { REGMASK_READ, 6, 0x80, 7},        // P
    { REGMASK_READ, 6, 0x40, 6},        // FF 
    { REGMASK_READ, 6, 0x20, 5},        // CF 
    { REGMASK_READ, 6, 0x10, 4},        // T 
    { REGMASK_READ, 6, 0x08, 3},        // PD3 
    { REGMASK_READ, 6, 0x04, 2},        // PD0
    { REGMASK_READ, 6, 0x03, 0},        // FRM

    { REGMASK_WRITE, 7, 0xFF, 0},       // XL (MSB)
    { REGMASK_WRITE, 8, 0xFF, 0},       // XH 
    { REGMASK_WRITE, 9, 0xFF, 0},       // YL 
    { REGMASK_WRITE, 10, 0xFF, 0},      // YH 
    { REGMASK_WRITE, 11, 0xFF, 0},      // ZL 
    { REGMASK_WRITE, 12, 0xFF, 0},      // ZH 

    { REGMASK_READ, 13, 0x80, 7},       // WA
    { REGMASK_WRITE, 13, 0x40, 6},      // WU
    { REGMASK_WRITE, 13, 0x38, 3},      // XH2 (LSB)
    { REGMASK_WRITE, 13, 0x07, 0},      // XL2

    { REGMASK_WRITE, 14, 0xA0, 6 },     // TST 
    { REGMASK_WRITE, 14, 0x38, 3 },     // YH2
    { REGMASK_WRITE, 14, 0x07, 0 },     // YL2 

    { REGMASK_WRITE, 15, 0xA0, 6 },     // PH 
    { REGMASK_WRITE, 15, 0x38, 3 },     // ZH2 
    { REGMASK_WRITE, 15, 0x07, 0 },     // ZL2 

    // CONFIG
    { REGMASK_WRITE, 16, 0x80, 7},      // DT
    { REGMASK_WRITE, 16, 0x40, 6},      // AM 
    { REGMASK_WRITE, 16, 0x30, 4},      // TRIG 
    { REGMASK_WRITE, 16, 0x04, 3},      // X2
    { REGMASK_WRITE, 16, 0x03, 1},      // TL_mag
    { REGMASK_WRITE, 16, 0x01, 0},      // CP 

    // MOD1
    { REGMASK_WRITE, 17, 0x80, 7},      // FP 
    { REGMASK_WRITE, 17, 0x60, 5},      // IICadr
    { REGMASK_WRITE, 17, 0x10, 4},      // PR
    { REGMASK_WRITE, 17, 0x08, 3},      // CA
    { REGMASK_WRITE, 17, 0x04, 2},      // INT
    { REGMASK_WRITE, 17, 0x03, 0},      // MODE

    { REGMASK_WRITE, 18, 0xFF, 0 },     // Res12
    { REGMASK_WRITE, 19, 0xE0, 5 },     // PRD 
    { REGMASK_WRITE, 19, 0x1F, 0 },     // RES13
    { REGMASK_WRITE, 20, 0xFF, 0 },     // Res14
    { REGMASK_WRITE, 21, 0xFF, 0 },     // Res15

    { REGMASK_READ, 22, 0xFF, 0 },      // Version 

};

const uint8_t resetValues[] = {
    //register 05h, 11h uses different reset values for different types
    //12h 14h 15h are reserved and initialized to 0
    //version register (16h) can be initialized with C9h, D9h or E9h
    0x80,
    0x80, 0x80, 0x80, 0x00, 0x00,
    0x60, 0x80, 0x7F, 0x80, 0x7F,
    0x80, 0x7F, 0x38, 0x38, 0x38,
    0x01, 0x00, 0x00, 0x00, 0x00,
    0x00, 0xC9,
};
}
#endif

错误信息:

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iom2560.h:38:0,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:174,

                 from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:90,

                 from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,

                 from sketch\Cartesian.ino.cpp:1:

c:\users\p.schmieder\documents\arduino\libraries\tle493d-w2b6-3dmagnetic-sensor\src\util\tle493d_w2b6_conf.h:47:16: error: expected identifier before numeric constant

  P, FF, CF, T, PD3, PD0, FRM,  //diagnosis (Diag)

                ^

c:\users\p.schmieder\documents\arduino\libraries\tle493d-w2b6-3dmagnetic-sensor\src\util\tle493d_w2b6_conf.h:47:16: error: expected '}' before numeric constant

c:\users\p.schmieder\documents\arduino\libraries\tle493d-w2b6-3dmagnetic-sensor\src\util\tle493d_w2b6_conf.h:47:16: error: expected unqualified-id before numeric constant

In file included from C:\Users\p.schmieder\Documents\Arduino\libraries\TLE493D-W2B6-3DMagnetic-Sensor\src/Tle493d_w2b6.h:43:0,

                 from C:\Users\PF014~1.SCH\AppData\Local\Temp\arduino_modified_sketch_931537\Cartesian.ino:1:

c:\users\p.schmieder\documents\arduino\libraries\tle493d-w2b6-3dmagnetic-sensor\src\util\tle493d_w2b6_conf.h:71:7: error: 'RegMask_t' does not name a type

 const RegMask_t regMasks[] = {

       ^

c:\users\p.schmieder\documents\arduino\libraries\tle493d-w2b6-3dmagnetic-sensor\src\util\tle493d_w2b6_conf.h:147:1: error: expected declaration before '}' token

 }

 ^

exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.

tle493d_w2b6_conf.h 中似乎有问题的行...

(这些:

P, FF, CF, T, PD3, PD0, FRM, //diagnosis (Diag)

错误:数字常量之前的预期标识符

const RegMask_t regMasks[] = {

错误:“RegMask_t”没有命名类型)

...在我看来一切都很好,但不知何故似乎是错误的。

我犯了什么明显的错误吗?或者我可以尝试使用的任何其他库?

标签: c++arduinosensors

解决方案


推荐阅读