This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMAG5273: tmag5273

Part Number: TMAG5273

Hello,

We are currently trying to use TMAG 5273 for linear position sensing application.

We are trying to use this along with a arduino.

Since we are new to I2C communication, any sample code for arduino would be appreciated.

Thank you.

Regards,

Benaka G

  • Hello Benaka,

    Thanks for posting to the sensing forum! Unfortunately, we do not have code examples for the TMAG5273 yet. We are working on developing some, but unfortunately they would be using an MSP432 and not an Arduino. If you have any other examples that you are looking into in specific please let me know and I can provide feedback to my teammate that will be developing the examples.

    If you are looking on how to use I2C on your Arduino there is some info online that might be beneficial: docs.arduino.cc/.../wire

    Best,

    Isaac

  • Hello Benaka,

    I did find some Arduino code that another user posted not sure if this will help you communicate with the device. You will most likely need to make edits to the sensor configuration but I hope this helps!

    #include <Wire.h>
    
    #define BOARD_HALL_I2C_ADDR 0x35
    #define DEVICE_CONFIG_1 0x00
    #define DEVICE_CONFIG_2 0x01
    #define SENSOR_CONFIG_1 0x02
    #define SENSOR_CONFIG_2 0x03
    #define X_THR_CONFIG 0x04
    #define Y_THR_CONFIG 0x05
    #define Z_THR_CONFIG 0x06
    #define T_CONFIG 0x07
    #define INT_CONFIG_1 0x08
    #define DEVICE_ID 0x0D
    #define MANUFACTURER_ID_LSB 0x0E
    #define MANUFACTURER_ID_MSB 0x0F
    #define Y_MSB_RESULT 0x14
    #define Y_LSB_RESULT 0x14
    #define FORCE_CONVERSION 0x80
    
    #define INTR_PIN  3
    
    unsigned char g_nDirByte = 0x20;
    
    void ConfigSensor();
    void I2CWrite(unsigned char nReg, unsigned char nVal);
    void I2CRead(unsigned char nReg, unsigned char* pData, unsigned char nLen);
    
    void setup()
    {
      pinMode(LED_BUILTIN, OUTPUT);
      pinMode(PIN_LED2, OUTPUT);
      pinMode(3, INPUT_PULLUP);
    
      Wire.begin();
      Serial.begin(115200);
    
      Serial.println("Init");
      ConfigSensor();
    }
    
    void loop()
    {
    
    }
    
    void ConfigSensor()
    {
      unsigned char aConfig[9] = {0};
    
      Serial.println("Configuring sensor");
    
      // Configure hall sensor.
      I2CWrite(DEVICE_CONFIG_2, 0x22); // Wake up
      I2CWrite(DEVICE_CONFIG_2, 0x22); // Continuous mode
      I2CWrite(DEVICE_CONFIG_1, 0x34);
      I2CWrite(SENSOR_CONFIG_1, 0x27);
      I2CWrite(SENSOR_CONFIG_2, g_nDirByte);
      I2CWrite(Y_THR_CONFIG, 0x02);
      I2CWrite(INT_CONFIG_1, 0x44);
    
      // Read regs to check.
      I2CRead(DEVICE_CONFIG_1, aConfig, sizeof(aConfig));
      for (int i=0; i < sizeof(aConfig); i++)
      {
        Serial.print(i);
        Serial.print(": ");
        Serial.println(aConfig[i], HEX);
      }
    
      // Enter W&S mode
      I2CWrite(DEVICE_CONFIG_2, 0x23);
    }
    
    void I2CWrite(unsigned char nReg, unsigned char nVal)
    {
      Wire.beginTransmission(BOARD_HALL_I2C_ADDR);
      Wire.write(nReg);
      Wire.write(nVal);
      Wire.endTransmission();
    }
    
    void I2CRead(unsigned char nReg, unsigned char* pData, unsigned char nLen)
    {
      int i = 0;
    
      Wire.beginTransmission(BOARD_HALL_I2C_ADDR);
      Wire.write(nReg);
      Wire.endTransmission(false);
      Wire.requestFrom(BOARD_HALL_I2C_ADDR, nLen, true);
      while (nLen > 0)
      {
        if (Wire.available() > 0)
        {
          pData[i++] = Wire.read();
          nLen--;
        }
      }
    }

    Best,

    Isaac