Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

3D Hall (Magnetic sensor) Forum Discussions

MichaelJean
Level 1
First question asked Welcome!
Level 1

I'm trying to read data from Infineons Tle493d_w2b6 sensor with an Arduino Mega2560. But their example code doesn't compile because of some error in a header file but i can't figure out how to fix it nor where the actual problem is.

Infineon provides a Arduino Library for their Tle493d_w2b6 sensor on GitHub (https://github.com/Infineon/TLE493D-3DMagnetic-Sensor). But when i try running their included Cartesian example it won't compile due to some problems in the "tle493d_w2b6_conf.h" file.

Cartesian example provided in Infineons Library:

#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 file:

#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

error message:

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.

The lines that seem to be wrong in the tle493d_w2b6_conf.h ...

(These:

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

error: expected identifier before numeric constant

const RegMask_t regMasks[] = {

error: 'RegMask_t' does not name a type)

... all seem fine to me but somehow seem to be wrong.

Is there any obvious mistake i am making? Or any other library i can try to use?

0 Likes
2 Replies
PalY
Moderator
Moderator 10 likes received 100 sign-ins 50 replies posted
Moderator

Hi @MichaelJean ,

Have you made any changes to the code downloaded from the repository? If yes, can you list them or could you share the whole project as zip file. 

Could you also mention the IDE you are using?

For us, the the code is compiling even with the conf.h file you provided. 

Thanks and regards,
Yashraj

0 Likes
PalY
Moderator
Moderator 10 likes received 100 sign-ins 50 replies posted
Moderator

Hi @MichaelJean ,

Closing this thread due to inactivity, hope your query was resolved.
If you have other queries please create a new thread.

Thanks and regards,
Yashraj

0 Likes