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.

TMAG3001: How to use the example code

Part Number: TMAG3001


Tool/software:

Hi,

I'm trying to use the example code for TMAG3001 provided here: www.ti.com/.../TMAG3001, it looks to me like the RESULT_READ_CALCULATION_EXAMPLE is the most relevant to what I do, so I chose that one. So my code starts with all the hardware inits and InitTMAG3001(); then
int16_t xyz_raw_results[3] = {0}; // Array to store the raw data from the magnetic channel registers
    float   xyz_mT_results[3]  = {0}; // Array to store magnetic channel data in mT

    // Configure device settings
    TMAG3001enableMagChannels(MAG_CH_EN_XYZ);                // Configure MAG_CH_EN bits to enable magnetic channels
    TMAG3001enableAngleMeasurement(ANGLE_EN_X1stY2nd);       // Configure ANGLE_EN bits to enable angle calculations
    TMAG3001setRanges(RANGE_80mTor240mT, RANGE_80mTor240mT); // Sets the magnetic range of the device

    // Trigger data conversion
    TMAG3001readSingleRegisterWithTrigger(SENSOR_CONFIG_2_ADDRESS); // Trigger a conversion using an I2C read command
    delay_ms(1);                                                    // Delay to allow conversion to complete

    // Get result measurements
    float temperature = TMAG3001getMeasurementTEMP();  // Gets device temperature result measurement in degrees C
    float xResult     = TMAG3001getMeasurementX();     // Gets device X-axis result measurement in mT
    float yResult     = TMAG3001getMeasurementY();     // Gets device Y-axis result measurement in mT
    float zResult     = TMAG3001getMeasurementZ();     // Gets device Z-axis result measurement in mT
    float angle       = TMAG3001getMeasurementANGLE(); // Gets device angle result measurement in degrees
    float magnitude   = TMAG3001getMeasurementMAG();   // Gets device magnitude result measurement in mT

    // Gets all raw magnetic flux data as well as magnetic flux data in mT
    TMAG3001getMagResultsRegisters(xyz_raw_results); // Gets all magnetic flux data measurements in mT
    TMAG3001getMagMeasurements(xyz_mT_results);      // Gets all raw magnetic flux data

Everything I read from this code is 0.0. am I missing something here? I only have SCL SDA, VCC & GND connected. Do I need more?

Thanks in advance!

  • Hi Karen,

    Thank you for posting to the Sensors forum!

    As a baseline, are you able to successfully read/write to the device at all? Are you able to share a screenshot of a logic analyzer capture of the I2C communication?

    The goal of this is to help determine if the device is acknowledging any of the read/write commands. If the device isn't acknowledging any of the commands, one thing you can check is if the I2C address being used to communicate to the device is correct based on what pin the ADDR is tied to.

    Best,

    ~Alicia

  • Hi Alicia,

    I'm now able to read values from using the I2C_COMMAND_EXAMPLE, but I was not able to read the angle from using the RESULT_READ_CALCULATION_EXAMPLE, as I have mentioned, the values I got was all 0.0, I had no other errors apart from that. Is there any formula that convert the results from I2C_COMMAND_EXAMPLE and convert it to angles?

    Thanks

  • Hi Karen,

    I wonder if some conversion/calculation in the TMAG3001getMeasurementANGLE function is resulting in a returned value of 0. If able, one thing you can try is stepping through this function to see if the function is reading valid data.

    You can convert the results read by the angle register values using a formula similar to the function below:

    Though you would need to replace the TMAG3001getAngleMSBresult function with the data read from the angle MSB register and replace TMAG3001getAngleLSBresult with the data from the angle LSB register.

    Best,

    ~Alicia