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: Zephyr sensor example?

Part Number: TMAG5273
Other Parts Discussed in Thread: MSP432E401Y, MSPM0L1306

Tool/software:

I'm trying to integrate the TMAG5273 into Zephyr using the Sensor API. Are there any relevant code examples? How about with a similar sensor if not TMAG5273?

I've been searching but haven't found anything useful yet.

  • Hi Todd,

    Thank you for posting to the Sensors forum!

    We do have code examples for the TMAG5273 linked below:

    Best,

    ~Alicia

  • Unfortunately, those examples do not use the Zephyr sensor API. I had found those examples prior to posting my question.

  • Hi Todd,

    Unfortunately, we do not have any code examples that use the Zephyr sensor API. I would recommend using the above code examples as a guide, though I am not sure how useful they will be in integrating them with the Zephyr sensor API as I have never worked with it myself.

    Best,

    ~Alicia

  • I managed to get the tmag5273 integrated into my Zephyr build. I still have to configure it properly but I see I2C transactions for sensor initialization and subsequent sensor_read() calls.

    Before anyone asks, I cannot post a repository of my code. But here are the basics of what I have done for an nrf5340dk (development kit). I am new to Zephyr and so there maybe mistakes, oversights, or errors on my part. But this does yield basic function. I know that I have additional sensor configuration to do to get the sensor to operate the way I want it to.

    prog.conf

    # TMAG5273
    CONFIG_SENSOR=y
    CONFIG_SENSOR_ASYNC_API=y
    CONFIG_TMAG5273=y

    .overlay

    pinctrl {
        i2c2_default: i2c2_default {
            group1 {
                psels = <NRF_PSEL(TWIM_SDA, 1, 5)>, <NRF_PSEL(TWIM_SCL, 1, 6)>;
            };
        };
    
        i2c2_sleep: i2c2_sleep {
            group1 {
                psels = <NRF_PSEL(TWIM_SDA, 1, 5)>, <NRF_PSEL(TWIM_SCL, 1, 6)>;
                low-power-enable;
            };
        };
    };

    main.c

    Necessary includes ...

    #include <zephyr/drivers/sensor.h>
    #include <zephyr/drivers/sensor/tmag5273.h>

    Just prior main() ...

    SENSOR_DT_READ_IODEV(tmag5273_iodev, DT_NODELABEL(tmag5273), {TMAG5273_CHAN_ANGLE_MAGNITUDE});
    RTIO_DEFINE(tmag5273_ctx, 1, 1);

    In main() ...

    I doubt this is correct for what I want to do but it compiles ok and runs. For example, the size
    of the buffer and the data read is not what I want. This is where I know that configuration and code
    changes are needed ...

    uint8_t mag_data_buf[2];
    int rc;
    
    const struct device *tmag5273_dev;
    tmag5273_dev = DEVICE_DT_GET(DT_NODELABEL(tmag5273));
    
    if (!device_is_ready(tmag5273_dev)) {
        return 0;
    }

    And this code is in aperiodic loop in main()... something like 1 second, just for debug ...

    rc = sensor_read(&tmag5273_iodev, &tmag5273_ctx, mag_data_buf, sizeof(mag_data_buf));
    
    if (rc != 0) {
        printk("sensor_read() failed %d\n", rc);
    }


    Hope this helps others.