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: TMAG5273A1

Part Number: TMAG5273

Hello, I am trying to obtain the magnetic field readings in X, Y and Z directions by utilizing TMAG5273A1 with an arduino uno micro controller. I have created a simple code in order to complete this function, however, the only values I am getting are zeros. I am sharing my code here and it would be a great great help if someone can give any input on any possible error in the code as I have checked the hardware and the code several times and they seem to be correct to me. Thank you! 

#include <Wire.h>

const int TMAG5273_ADDRESS = 0x35; 

void setup() {
 Wire.begin(); // Join i2c bus
 Serial.begin(9600); // Start serial communication at 9600 bps

}

void loop() {
 Wire.beginTransmission(TMAG5273_ADDRESS);
 Wire.write(0x6B); 
 Wire.endTransmission(false);
 Wire.requestFrom(TMAG5273_ADDRESS, 6); // Request 6 bytes (2 bytes per axis)

 if (Wire.available()) {
    int xAxis = Wire.read() << 8 | Wire.read();
    int yAxis = Wire.read() << 8 | Wire.read();
    int zAxis = Wire.read() << 8 | Wire.read();

    Serial.print("X: ");
    Serial.println(xAxis);
    Serial.print("Y: ");
    Serial.println(yAxis);
    Serial.print("Z: ");
    Serial.println(zAxis);
 }

 delay(1000); // Wait for a second before taking the next measurement
}


  • Hi Asad,

    Thank you for posting to the Sensors Forum!

    Just as a quick sanity check, have you enabled the MAG_CH_EN bits, shown below? 

    Best,

    ~Alicia

  • Hello Alicia, thank you for your response! Actually I did not enable the MAG_CH_EN bits initially, however, now I have incorporated them yet I still have the same issue. I am attaching the modified code, maybe that could help rectify any error that I might be missing! 

    #include <Wire.h>

    const int TMAG5273_ADDRESS =  0x35; // Actual I2C address of the TMAG5273A1QDBVT sensor
    const int SENSOR_CONFIG_1_REGISTER =  0x6B; // Register address for SENSOR_CONFIG_1

    void setup() {
      Wire.begin(true); // Enable external pull-up resistors
      Serial.begin(9600); // Start serial communication at  9600 bps

      // Write to SENSOR_CONFIG_1 to enable all channels (X, Y, Z)
      Wire.beginTransmission(TMAG5273_ADDRESS);
      Wire.write(SENSOR_CONFIG_1_REGISTER); // Write to the SENSOR_CONFIG_1 register
      Wire.write(0x7); // Enable all channels (X, Y, Z)
      Wire.endTransmission();
    }

    void loop() {
      Wire.beginTransmission(TMAG5273_ADDRESS);
      Wire.write(0x6B); // Continue writing to the SENSOR_CONFIG_1 register to trigger a new measurement
      Wire.endTransmission(false);
      Wire.requestFrom(TMAG5273_ADDRESS,  6); // Request  6 bytes (2 bytes per axis)

      if (Wire.available()) {
        int xAxis = Wire.read() <<  8 | Wire.read();
        int yAxis = Wire.read() <<  8 | Wire.read();
        int zAxis = Wire.read() <<  8 | Wire.read();

        Serial.print("X: ");
        Serial.println(xAxis);
        Serial.print("Y: ");
        Serial.println(yAxis);
        Serial.print("Z: ");
        Serial.println(zAxis);
      }

      delay(1000); // Wait for a second before taking the next measurement
    }

    A few important notes;

     I have not connected the INT and GND(TEST) ports of the sensor to anything.

    The circuit involves TMAG5273 sensor soldered to a PCB, breadboard and arduino uno

  • Hi Asad,

    I noticed that you have set the register address for SENSOR_CONFIG_1 to 0x6B. I believe that this may be a mistake as the register address for SENSOR_CONFIG_1 should be 0x02.

    Best,

    ~Alicia

  • Hi Alicia, actually as the manual implementation of I2C was very complex, I ordered "SparkFun Mini Linear 3D Hall-Effect Sensor - TMAG5273 (Qwiic)" and utilizing the "SparkFun_TMAG5273_Arduino_Library" I was able to make the sensor work. Initially I used Arduino UNO as a microcontroller and everything was smooth, however, when I switched to Arduino nano, I was not able to get the readings anymore! I was faced with an error about programmer is not responding. Can you please advise me how to rectify this issue as it is essential for me to use arduino nano in the project due to dimension constraints. Thank you. 

  • Hi Asad,

    Are you able to share a waveform of the I2C communication that you are doing with the device, preferably using a logic analyzer?

    Best,

    ~Alicia

  • HI Asad,

    Just wanted to check in to see if your issue has been resolved. If it has, please mark this thread as "Resolved". I am going to close this thread, for now, due to inactivity. If you have any additional questions, please feel free to re-open this thread or ask a related question.

    Best,

    ~Alicia