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 put the device in Wake&Sleep with triggering external interrupt does not work

Part Number: TMAG5273

Hi

I want to use the TMA5273 in our new product, but I got stuck by the implementation of the Wake&Sleep mode.

As far as I understand the mode the device will wake up on his own every x seconds, starts a measurement, compare the result and can trigger an interrupt through the INT pin if a treshold will be crossed. After this process the device switches back to sleep and continue.

Hoever I have initialized the device in my firmware, set the sleep time and put the device to wake&sleep mode. But the device will note woken up by an magnetic field. The interrupt function only works when I measure continiously. I need help to find the correct register settings to put the device in Wake&Sleep mode to measure every 20 seconds and trigger and external interrupt through INT to wake my host MCU by crossing a given threshold. I need to compare the settings with my current settings to figure out the problem of my device configuration.

Thank you and best regards

  • Hi Daniel,

    Thanks for posting to the sensing forum. Would you mind sharing your register configurations? 

    If your INT_CONFIG_1 register is set to all default values, try setting INT_CONFIG_1 -> INT_MODE to 0x01. This will enable interrupt through the INT pin as the default for INT_MODE is to have no interrupts enabled (see page 30 of the datasheet for more options). Additionally, you'll need to set INT_CONFIG_1 -> THRSLD_INT to 0x01 to enable an interrupt response when a threshold is crossed. You can also set the thresholds for the X, Y, and Z axis as well as for the temperature in Registers 4, 5, 6, and 7, respectively (these registers can be found on page 29 of the datasheet). 

    Best,

    ~Alicia

  • Hi @Alicia,

    please take a look at my code. Maybe you can find the issue in my configuration. In the meantime I will check our comments.

    main.cpp

    static const TMAG5273_Config_t Config = {
        .Average        = TMAG5273_AVG_2,
        .TempCo         = TMAG5273_TEMPCO_0,
        .Channel        = TMAG5273_CHANNEL_XYZ,
        .Mode           = TMAG5273_MODE_LP,
        .XY             = TMAG5273_RANGE_0,
        .Z              = TMAG5273_RANGE_0,
        .UseCRC         = false,
        .UseGlichFilter = false,
    };
    
    static TMAG5273_ThresConf_t SleepConfig = {
        .x              = 0,
        .y              = 0,
        .z              = 2,
        .useSymetric    = false,
        .use4xThres     = false,
        .useBelowThres  = false,
    };
    
    static const TMAG5273_IntConf_t IntConfig = {
        .Mode           = TMAG5273_INT_INT,
        .usePulsed      = false,
        .useConvInt     = false,
        .useThresInt    = true,
        .p_Threshold    = &SleepConfig,
    };
    
    static RTC_NOINIT_ATTR TMAG5273_t _Device;
    
    void Init(void)
    {
    	I2CM_Init(0, TRAP_1_PIN_I2C_SDA, TRAP_1_PIN_I2C_SCL);
    	if(TMAG5273_Init(&_Device, &Config) != TMAG5273_ERR_OK)
    	{
    		ESP_LOGE(TAG, "     Cannot initialize trap 1!");
    
    		I2CM_Deinit(0, PIN_I2C_SDA, PIN_I2C_SCL);
    
    		return ESP_ERR_INVALID_RESPONSE;
    	}
    }
    
    void PrepareSleep(void)
    {
    	TMAG5273_EnableInterrupt(&_Device, &IntConfig);
    	TMAG5273_EnableWakeAndSleep(&_Device, TMAG5273_SLEEP_100);
    }
    
    bool isInterrupt(void)
    {
        gpio_config_t _IO_Conf = {
            .pin_bit_mask = BIT(TRAP_PIN_INT),
            .mode = GPIO_MODE_INPUT,
            .pull_up_en =  GPIO_PULLUP_DISABLE,
            .pull_down_en = GPIO_PULLDOWN_DISABLE,
            .intr_type = GPIO_INTR_DISABLE,
        };
    
        gpio_config(&_IO_Conf);
    
        return gpio_get_level((gpio_num_t)(GPIO_NUM_0 + TRAP_PIN_INT));
    }
    
    int main(void)
    {
    	Init();
    	PrepareSleep();
    	while(1)
    	{
    		if(isInterrupt() == 0)
    		{
    			ESP_LOGI(TAG, "Interrupt");
    		}
    
    		vTaskDelay(1000 / portTICK_PERIOD_MS);
    	}
    }

    tmag5273.cpp


    #include <esp_log.h>
    
    #include <string.h>
    #include <cmath>
    
    #include "tmag5273.h"
    
    #define TMAG5273_REG_DEVICE_CONFIG_1        0x00
    #define TMAG5273_REG_DEVICE_CONFIG_2        0x01
    #define TMAG5273_REG_SENSOR_CONFIG_1        0x02
    #define TMAG5273_REG_SENSOR_CONFIG_2        0x03
    #define TMAG5273_REG_X_THR_CONFIG           0x04
    #define TMAG5273_REG_INT_CONFIG_1           0x08
    #define TMAG5273_REG_MAG_GAIN_CONFIG        0x09
    #define TMAG5273_REG_MAG_OFFSET_CONFIG_1    0x0A
    #define TMAG5273_REG_MAG_OFFSET_CONFIG_2    0x0B
    #define TMAG5273_REG_I2C_ADDRESS            0x0C
    #define TMAG5273_REG_DEVICE_ID              0x0D
    #define TMAG5273_REG_MANUFACTURER_ID_LSB    0x0E
    #define TMAG5273_REG_MANUFACTURER_ID_MSB    0x0F
    #define TMAG5273_REG_T_MSB                  0x10
    #define TMAG5273_REG_X_MSB                  0x12
    #define TMAG5273_REG_CONV_STATUS            0x18
    
    #define TMAG5273_BIT_RESULT_STATUS          (0x01 << 0x00)
    
    /** @brief TMAG5273 device address.
     */
    #define TMAG5273_ADDR                       0x35
    
    /** @brief TMAG5273 manufacturer identification.
     */
    #define TMAG5273_MANUFACTURER_ID            0x5449
    
    /** @brief 
     */
    typedef struct
    {
        uint16_t x;                                         /**< */
        uint16_t y;                                         /**< */
        uint16_t z;                                         /**< */
    } TMAG5273_Raw_t;
    
    static const char* TAG                      = "TMAG5273";
    
    /** @brief          Convert a two complements number into a decimal number.
     *  @param Input    Input number
     *  @return         Decimal number
     */
    static inline __attribute__((always_inline)) int16_t TMAG5273_ConvertTwoComplement(uint16_t Input)
    {
        if((Input & 0x8000) == false)
        {
            return Input;
        }
    
        return 0 - (int16_t)(~(Input - 0x01));
    }
    
    /** @brief          Read the device status register.
     *  @param p_Device Pointer to device object
     *  @param p_Status Pointer to status data
     *  @return         TMAG5273_ERR_OK when successful
     */
    static TMAG5273_Error_t TMAG5273_ReadStatus(const TMAG5273_t* const p_Device, uint8_t* const p_Status)
    {
        uint8_t Temp;
    
        if((p_Device == NULL) || (p_Status == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp = TMAG5273_REG_CONV_STATUS;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp, 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, p_Status, 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        return TMAG5273_ERR_OK;
    }
    
    /** @brief          Wait until a conversion is complete.
     *  @param p_Device Pointer to device object
     *  @return         TMAG5273_ERR_OK when successful
     */
    static TMAG5273_Error_t TMAG5273_WaitConversionComplete(const TMAG5273_t* const p_Device)
    {
        uint8_t Status;
    
        do
        {
            TMAG5273_ERROR_CHECK(TMAG5273_ReadStatus(p_Device, &Status));
            p_Device->Delay(10);
        } while((Status & TMAG5273_BIT_RESULT_STATUS) == false);
    
        return TMAG5273_ERR_OK;
    }
    
    /** @brief          Change given bits in a register.
     *  @param p_Device Pointer to device object
     *  @param Register Register address
     *  @param Mask     Bit mask
     *  @param Value    New value for the masked bits
     *  @return         TMAG5273_ERR_OK when successful
     */
    static TMAG5273_Error_t TMAG5273_ModifyBits(const TMAG5273_t* const p_Device, uint8_t Register, uint8_t Mask, uint8_t Value)
    {
        uint8_t Temp[2];
    
        if(p_Device == NULL)
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = Register;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        Temp[1] &= ~Mask;
        Temp[1] |= Value;
    
        Temp[0] = Register;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_Init(TMAG5273_t* const p_Device, const TMAG5273_Config_t* const p_Config, uint8_t Samples)
    {
        int32_t x_Temp = 0;
        int32_t y_Temp = 0;
        int32_t z_Temp = 0;
        uint16_t ID;
        uint8_t Temp[5];
    
        if((p_Device == NULL) || (p_Config == NULL) || (p_Device->Delay == NULL) || (p_Device->I2C.I2C_Read == NULL) || (p_Device->I2C.I2C_Write == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
    
        p_Device->Internal.isInitialized = false;
        p_Device->I2C.I2C_Address = TMAG5273_ADDR;
    
        Temp[0] = TMAG5273_REG_MANUFACTURER_ID_LSB;
    
        // One dummy write in case the device is in sleep mode.
        p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance);
    
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        ID = (((uint16_t)Temp[2]) << 0x08) | Temp[1];
        if(ID != TMAG5273_MANUFACTURER_ID)
        {
            ESP_LOGE(TAG, "No device found!");
    
            return TMAG5273_ERR_NO_DEVICE;
        }
    
        p_Device->Internal.UseCRC = p_Config->UseCRC;
    
        Temp[0] = TMAG5273_REG_DEVICE_ID;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        p_Device->Ver = Temp[1] & 0x03;
        if(p_Device->Ver == 1)
        {
            ESP_LOGI(TAG, "TMAG5273A1 detected!");
    
            p_Device->RangeXY = 40;
            if(p_Config->XY == TMAG5273_RANGE_1)
            {
                p_Device->RangeXY = 80;
            }
    
            p_Device->RangeZ = 40;
            if(p_Config->Z == TMAG5273_RANGE_1)
            {
                p_Device->RangeZ = 80;
            }
        }
        else if(p_Device->Ver == 2)
        {
            ESP_LOGI(TAG, "TMAG5273A2 detected!");
            p_Device->RangeXY = 133;
            if(p_Config->XY == TMAG5273_RANGE_1)
            {
                p_Device->RangeXY = 266;
            }
    
            p_Device->RangeZ = 133;
            if(p_Config->Z == TMAG5273_RANGE_1)
            {
                p_Device->RangeZ = 266;
            }
        }
    
        ESP_LOGI(TAG, "     ID: 0x%X", ID);
        ESP_LOGI(TAG, "     Set x/y range to: %u", p_Device->RangeXY);
        ESP_LOGI(TAG, "     Set z range to: %u", p_Device->RangeZ);
    
        Temp[0] = TMAG5273_REG_DEVICE_CONFIG_1;
        Temp[1] = (p_Config->UseCRC << 0x07) | (p_Config->TempCo << 0x05) | (p_Config->Average << 0x02);
        Temp[2] = (TMAG5273_MODE_LN << 0x04) | (p_Config->UseGlichFilter << 0x03) | TMAG5273_OPMODE_CONT;
        Temp[3] = (p_Config->Channel << 0x04);
        Temp[4] = (p_Config->XY << 0x01) | p_Config->Z;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 5, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        p_Device->Internal.isInitialized = true;
    
        if(Samples > 0)
        {
            for(uint8_t i = 0; i < Samples; i++)
            {
                TMAG5273_Data_t Data;
    
                TMAG5273_ReadFieldResults(p_Device, &Data);
    
                x_Temp += Data.Vec.x;
                y_Temp += Data.Vec.y;
                z_Temp += Data.Vec.z;
            }
    
            p_Device->Offset.Vec.x = x_Temp / Samples;
            p_Device->Offset.Vec.y = y_Temp / Samples;
            p_Device->Offset.Vec.z = z_Temp / Samples;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_SetPwrMode(p_Device, p_Config->Mode));
        TMAG5273_ERROR_CHECK(TMAG5273_SetOperationMode(p_Device, TMAG5273_OPMODE_STBY));
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_EnableInterrupt(const TMAG5273_t* const p_Device, const TMAG5273_IntConf_t* const p_Config)
    {
        if((p_Device == NULL) || (p_Config == NULL) || ((p_Config->useThresInt == true) && (p_Config->p_Threshold == NULL)))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        if(p_Config->p_Threshold != NULL)
        {
            TMAG5273_ERROR_CHECK(TMAG5273_SetThreshold(p_Device, p_Config->p_Threshold));
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_MaskINT(p_Device, true));
    
        return TMAG5273_ModifyBits(p_Device, 
                TMAG5273_REG_INT_CONFIG_1, 
                (0x01 << 0x07) | (0x01 << 0x06) | (0x01 << 0x05) | (0x03 << 0x02),
                (p_Config->useConvInt << 0x07) | (p_Config->useThresInt << 0x06) | (p_Config->usePulsed << 0x05) | ((p_Config->Mode & 0x03) << 0x02));
    }
    
    TMAG5273_Error_t TMAG5273_isPOR(const TMAG5273_t* const p_Device, bool* const p_POR)
    {
        uint8_t Temp;
    
        if((p_Device == NULL) || (p_POR == NULL) )
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp = TMAG5273_REG_CONV_STATUS;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp, 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp, 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        *p_POR = (Temp & (0x01 << 0x04)) >> 0x04;
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_DisableInterrupt(const TMAG5273_t* const p_Device)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_INT_CONFIG_1, (0x01 << 0x07) | (0x01 << 0x06), 0x00);
    }
    
    TMAG5273_Error_t TMAG5273_MaskINT(const TMAG5273_t* const p_Device, bool Enable)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_INT_CONFIG_1, (0x01 << 0x00), ((!Enable) << 0x00));
    }
    
    TMAG5273_Error_t TMAG5273_ReadTemperature(TMAG5273_t* const p_Device, uint16_t* p_Data)
    {
        if((p_Device == NULL) || (p_Data == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_ReadFieldResults(TMAG5273_t* const p_Device, TMAG5273_Data_t* const p_Data)
    {
        uint8_t Temp;
        TMAG5273_Raw_t RawData;
    
        if((p_Device == NULL) || (p_Data == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_WaitConversionComplete(p_Device));
    
        Temp = TMAG5273_REG_X_MSB;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp, 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, (uint8_t*)&RawData, sizeof(TMAG5273_Raw_t), p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        RawData.x = __builtin_bswap16(RawData.x);
        RawData.y = __builtin_bswap16(RawData.y);
        RawData.z = __builtin_bswap16(RawData.z);
    
        p_Data->Vec.x = RawData.x;
        p_Data->Vec.y = RawData.y;
        p_Data->Vec.z = RawData.z;
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_EnableUserAddress(TMAG5273_t* const p_Device, uint8_t Address)
    {
        uint8_t Temp[2];
    
        if(p_Device == NULL)
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_I2C_ADDRESS;
        Temp[1] = ((Address & 0x7F) << 0x01) | (0x01 << 0x00);
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        p_Device->I2C.I2C_Address = Address;
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_DisableUserAddress(TMAG5273_t* const p_Device)
    {
        uint8_t Temp[2];
    
        if(p_Device == NULL)
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_I2C_ADDRESS;
        Temp[1] = 0x00;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        p_Device->I2C.I2C_Address = TMAG5273_ADDR;
    
        return TMAG5273_ERR_OK;    
    }
    
    TMAG5273_Error_t TMAG5273_EnableGain(const TMAG5273_t* const p_Device)
    {
        if(p_Device == NULL)
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_EnableOffsetCompensation(const TMAG5273_t* const p_Device, TMAG5273_ChanSelection_t ActiveChannels)
    {
        uint8_t Temp[2];
        int16_t Offset_1 = 0;
        int16_t Offset_2 = 0;
        uint8_t Range_1 = 0;
        uint8_t Range_2 = 0;
    
        if((p_Device == NULL) || (ActiveChannels > TMAG5273_ANGLE_XZ))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        if(ActiveChannels == TMAG5273_ANGLE_XY)
        {
            Offset_1 = p_Device->Offset.Vec.x;
            Offset_2 = p_Device->Offset.Vec.y;
            Range_1 = p_Device->RangeXY;
            Range_2 = p_Device->RangeXY;
        }
        else if(ActiveChannels == TMAG5273_ANGLE_YZ)
        {
            Offset_1 = p_Device->Offset.Vec.y;
            Offset_2 = p_Device->Offset.Vec.z;
            Range_1 = p_Device->RangeXY;
            Range_2 = p_Device->RangeZ;
        }
        else if(ActiveChannels == TMAG5273_ANGLE_XZ)
        {
            Offset_1 = p_Device->Offset.Vec.x;
            Offset_2 = p_Device->Offset.Vec.z;
            Range_1 = p_Device->RangeXY;
            Range_2 = p_Device->RangeZ;
        }
    
        Offset_1 = std::ceil(-4096.0 * TMAG5273_CalcField(Range_1, Offset_1) / (2.0 * (float)Range_1));
        Offset_2 = std::ceil(-4096.0 * TMAG5273_CalcField(Range_2, Offset_2) / (2.0 * (float)Range_2));
    
        ESP_LOGI(TAG, "Offset calculated for 1: %i", Offset_1);
        Temp[0] = TMAG5273_REG_MAG_OFFSET_CONFIG_1;
        Temp[1] = Offset_1;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        ESP_LOGI(TAG, "Offset calculated for 2: %i", Offset_2);
        Temp[0] = TMAG5273_REG_MAG_OFFSET_CONFIG_2;
        Temp[1] = Offset_2;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_SENSOR_CONFIG_2, (0x03 << 0x02), (ActiveChannels << 0x02));
    }
    
    TMAG5273_Error_t TMAG5273_DisableOffsetCompensation(const TMAG5273_t* const p_Device)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_SENSOR_CONFIG_2, (0x03 << 0x02), 0x00);
    }
    
    TMAG5273_Error_t TMAG5273_EnableGain(const TMAG5273_t* const p_Device, uint8_t Gain, TMAG5273_ChanSelection_t ActiveChannels, TMAG5273_GainChannel_t Channel)
    {
        uint8_t Temp[2];
    
        if((p_Device == NULL) || (ActiveChannels > TMAG5273_ANGLE_XZ))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_MAG_GAIN_CONFIG;
        Temp[1] = Gain;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 2, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_2, (0x01 << 0x04), (Channel << 0x04)));
    
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_2, (0x03 << 0x02), (ActiveChannels << 0x02));
    }
    
    TMAG5273_Error_t TMAG5273_SetOperationMode(const TMAG5273_t* const p_Device, TMAG5273_OpMode_t Mode)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_2, 0x03 << 0x00, (Mode & 0x03) << 0x00);
    }
    
    TMAG5273_Error_t TMAG5273_GetOperationMode(const TMAG5273_t* const p_Device, TMAG5273_OpMode_t* const p_Mode)
    {
        uint8_t Temp[2];
    
        if((p_Device == NULL) || (p_Mode == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_DEVICE_CONFIG_2;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        *p_Mode = (TMAG5273_OpMode_t)(Temp[1] & 0x03);
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_SetAverage(const TMAG5273_t* const p_Device, TMAG5273_Avg_t Average)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_1, 0x07 << 0x00, (Average & 0x07) << 0x02);
    }
    
    TMAG5273_Error_t TMAG5273_GetAverage(const TMAG5273_t* const p_Device, TMAG5273_Avg_t* const p_Average)
    {
        uint8_t Temp[2];
    
        if((p_Device == NULL) || (p_Average == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_DEVICE_CONFIG_1;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        *p_Average = (TMAG5273_Avg_t)((Temp[1] & 0x07) >> 0x02);
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_SetPwrMode(const TMAG5273_t* const p_Device, TMAG5273_PwrMode_t Mode)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_2, 0x01 << 0x04, (Mode & 0x01) << 0x04);
    }
    
    TMAG5273_Error_t TMAG5273_GetPwrMode(const TMAG5273_t* const p_Device, TMAG5273_PwrMode_t* const p_Mode)
    {
        // TODO
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_SetSleepTime(const TMAG5273_t* const p_Device, TMAG5273_Sleep_t SleepTime)
    {
        return TMAG5273_ModifyBits(p_Device, TMAG5273_REG_SENSOR_CONFIG_1, 0x0F << 0x00, (SleepTime & 0x0F) << 0x00);
    }
    
    TMAG5273_Error_t TMAG5273_GetSleepTime(const TMAG5273_t* const p_Device, TMAG5273_Sleep_t* const p_SleepTime)
    {
        uint8_t Temp[2];
    
        if((p_Device == NULL) || (p_SleepTime == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        Temp[0] = TMAG5273_REG_DEVICE_CONFIG_1;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, &Temp[0], 1, p_Device->I2C.Instance) || p_Device->I2C.I2C_Read(p_Device->I2C.I2C_Address, &Temp[1], 1, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        *p_SleepTime = (TMAG5273_Sleep_t)(Temp[1] & 0x0F);
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_SetThreshold(const TMAG5273_t* const p_Device, const TMAG5273_ThresConf_t* const p_Threshold)
    {
        uint8_t Temp[4];
    
        if((p_Device == NULL) || (p_Threshold == NULL))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_ModifyBits(p_Device, TMAG5273_REG_DEVICE_CONFIG_2, 0x07 << 0x05, p_Threshold->useSymetric << 0x05));
        TMAG5273_ERROR_CHECK(TMAG5273_ModifyBits(p_Device, TMAG5273_REG_SENSOR_CONFIG_2, (0x01 << 0x06) | (0x01 << 0x05), (p_Threshold->use4xThres << 0x06) | (p_Threshold->useBelowThres << 0x05)));
    
        memcpy(&Temp[1], p_Threshold, 3);
    
        ESP_LOGD(TAG, "Threshold x: %u", Temp[1]);
        ESP_LOGD(TAG, "Threshold y: %u", Temp[2]);
        ESP_LOGD(TAG, "Threshold z: %u", Temp[3]);
    
        Temp[0] = TMAG5273_REG_X_THR_CONFIG;
        if(p_Device->I2C.I2C_Write(p_Device->I2C.I2C_Address, Temp, 4, p_Device->I2C.Instance))
        {
            return TMAG5273_ERR_INVALID_RESPONSE;
        }
    
        return TMAG5273_ERR_OK;
    }
    
    TMAG5273_Error_t TMAG5273_EnableWakeAndSleep(TMAG5273_t* const p_Device, TMAG5273_Sleep_t Sleeptime)
    {
        if((p_Device == NULL) || (Sleeptime > TMAG5273_SLEEP_20K))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_SetSleepTime(p_Device, Sleeptime));
        TMAG5273_ERROR_CHECK(TMAG5273_SetOperationMode(p_Device, TMAG5273_OPMODE_WS));
    
        return TMAG5273_ERR_OK;
    }

    tmag5273_defs.h

    #ifndef TMAG5273_DEFS_H_
    #define TMAG5273_DEFS_H_
    
    #include <cstddef>
    #include <stdint.h>
    #include <stdbool.h>
    
    /** @brief              I2C master write function definition.
     *  @param Address      Device address
     *  @param p_Data       Pointer to data buffer
     *  @param Size         Data length
     *  @param p_Instance   Pointer to interface instance
     *  @return             Status code
     */
    typedef int32_t (*TMAG5273_Write_t)(uint8_t Address, const uint8_t* p_Data, size_t Size, const void* p_Instance);
    
    /** @brief              I2C master read function definition.
     *  @param Address      Device address
     *  @param p_Data       Pointer to data buffer
     *  @param Size         Data length
     *  @param p_Instance   Pointer to interface instance
     *  @return             Status code
     */
    typedef int32_t (*TMAG5273_Read_t)(uint8_t Address, uint8_t* p_Data, size_t Size, const void* p_Instance);
    
    /** @brief          Milliseconds delay function.
     *  @param Delay    Delay time
     */
    typedef void (*TMAG5273_Delay_t)(uint32_t Delay);
    
    /** @brief TMAG5273 temperature coefficients definitions.
     */
    typedef enum
    {
        TMAG5273_TEMPCO_0 = 0,                                  /**< 0% (No temperature compensation). */
        TMAG5273_TEMPCO_1,                                      /**< 0.12%/ deg C (NdBFe). */
        TMAG5273_TEMPCO_2 = 3,                                  /**< 0.2%/deg C (Ceramic). */
    } TMAG5273_TempCo_t;
    
    /** @brief TMAG5273 range definitions.
     */
    typedef enum
    {
        TMAG5273_RANGE_0 = 0,                                   /**< ±40mT (TMAG5273A1) or ±133mT (TMAG5273A2). */
        TMAG5273_RANGE_1,                                       /**< ±80mT (TMAG5273A1) or ±266mT (TMAG5273A2). */
    } TMAG5273_Range_t;
    
    /** @brief TMAG5273 power mode definitions.
     */
    typedef enum
    {
        TMAG5273_MODE_LP = 0,                                   /**< Low active current mode. */
        TMAG5273_MODE_LN,                                       /**< Low noise mode. */
    } TMAG5273_PwrMode_t;
    
    /** @brief TMAG5273 mode definitions.
     */
    typedef enum
    {
        TMAG5273_OPMODE_STBY = 0,                               /**< Stand-by mode (starts new conversion at trigger event). */
        TMAG5273_OPMODE_SLEEP,                                  /**< Sleep mode. */
        TMAG5273_OPMODE_CONT,                                   /**< Continuous measure mode. */
        TMAG5273_OPMODE_WS,                                     /**< Wake-up and sleep mode (W&S mode). */
    } TMAG5273_OpMode_t;
    
    /** @brief TMAG5273 interrupt mode definitions.
     */
    typedef enum
    {
        TMAG5273_INT_NO = 0,                                    /**< No interrupt. */
        TMAG5273_INT_INT,                                       /**< Interrupt through INT. */
        TMAG5273_INT_INT_NO_BUSY,                               /**< Interrupt through INT except when I2C bus is busy. */
        TMAG5273_INT_SCL,                                       /**< Interrupt through SCL. */
        TMAG5273_INT_SCL_NO_BUSY,                               /**< Interrupt through SCL except when I2C bus is busy. */
    } TMAG5273_IntMode_t;
    
    /** @brief TMAG5273 channel selection definitions.
     */
    typedef enum
    {
        TMAG5273_ANGLE_OFF = 0,                                 /**< No angle calculation, magnitude gain, and offset correction enabled. */
        TMAG5273_ANGLE_XY,                                      /**< X 1st, Y 2nd. */
        TMAG5273_ANGLE_YZ,                                      /**< Y 1st, Z 2nd. */
        TMAG5273_ANGLE_XZ,                                      /**< X 1st, Z 2nd. */
    } TMAG5273_ChanSelection_t;
    
    /** @brief TMAG5273 gain correction channel definitions.
     */
    typedef enum
    {
        TMAG5273_GAIN_0 = 0,                                    /**< 1st channel is selected for gain adjustment. */
        TMAG5273_GAIN_1,                                        /**< 2st channel is selected for gain adjustment. */
    } TMAG5273_GainChannel_t;
    
    /** @brief TMAG5273 oversampling definitions.
     */
    typedef enum
    {
        TMAG5273_AVG_1 = 0,                                     /**< 1x average, 10.0-kSPS (3-axes) or 20-kSPS (1 axis). */
        TMAG5273_AVG_2,                                         /**< 2x average, 5.7-kSPS (3-axes) or 13.3-kSPS (1 axis). */
        TMAG5273_AVG_4,                                         /**< 4x average, 3.1-kSPS (3-axes) or 8.0-kSPS (1 axis). */
        TMAG5273_AVG_8,                                         /**< 8x average, 1.6-kSPS (3-axes) or 4.4-kSPS (1 axis). */
        TMAG5273_AVG_16,                                        /**< 16x average, 0.8-kSPS (3-axes) or 2.4-kSPS (1 axis). */
        TMAG5273_AVG_32,                                        /**< 32x average, 0.4-kSPS (3-axes) or 1.2-kSPS (1 axis). */
    } TMAG5273_Avg_t;
    
    /** @brief TMAG5273 sleeptime definitions.
     */
    typedef enum
    {
        TMAG5273_SLEEP_1 = 0,                                   /**< Sleep 1 ms. */
        TMAG5273_SLEEP_5,                                       /**< Sleep 5 ms. */
        TMAG5273_SLEEP_10,                                      /**< Sleep 10 ms. */
        TMAG5273_SLEEP_15,                                      /**< Sleep 15 ms. */
        TMAG5273_SLEEP_20,                                      /**< Sleep 20 ms. */
        TMAG5273_SLEEP_30,                                      /**< Sleep 30 ms. */
        TMAG5273_SLEEP_50,                                      /**< Sleep 50 ms. */
        TMAG5273_SLEEP_100,                                     /**< Sleep 100 ms. */
        TMAG5273_SLEEP_500,                                     /**< Sleep 500 ms. */
        TMAG5273_SLEEP_1K,                                      /**< Sleep 1000 ms. */
        TMAG5273_SLEEP_2K,                                      /**< Sleep 2000 ms. */
        TMAG5273_SLEEP_5K,                                      /**< Sleep 5000 ms. */
        TMAG5273_SLEEP_20K,                                     /**< Sleep 20000 ms. */
    } TMAG5273_Sleep_t;
    
    /** @brief TMAG5273 channel definitions.
     */
    typedef enum
    {
        TMAG5273_CHANNEL_OFF = 0,                               /**< All magnetic channels of. */
        TMAG5273_CHANNEL_X,                                     /**< X channel enabled. */
        TMAG5273_CHANNEL_Y,                                     /**< Y channel enabled. */
        TMAG5273_CHANNEL_XY,                                    /**< X, Y channel enabled. */
        TMAG5273_CHANNEL_Z,                                     /**< Z channel enabled. */
        TMAG5273_CHANNEL_ZX,                                    /**< Z, X channel enabled. */
        TMAG5273_CHANNEL_YZ,                                    /**< Y, Z channel enabled. */
        TMAG5273_CHANNEL_XYZ,                                   /**< X, Y, Z channel enabled. */
        TMAG5273_CHANNEL_XYX,                                   /**< XYX channel enabled. */
        TMAG5273_CHANNEL_YXY,                                   /**< YXY channel enabled. */
        TMAG5273_CHANNEL_YZY,                                   /**< YZY channel enabled. */
        TMAG5273_CHANNEL_XZX,                                   /**< XZX channel enabled. */
    } TMAG5273_Channel_t;
    
    /** @brief TMAG5273 threshold configuration object definition.
     */
    typedef struct
    {
        int8_t x;                                               /**< Threshold for the x axis. */
        int8_t y;                                               /**< Threshold for the y axis. */
        int8_t z;                                               /**< Threshold for the z axis. */
        bool useSymetric;                                       /**< Set to #false: Takes the 2's complement value of each x_THR_CONFIG
                                                                     register to create a magnetic threshold of the corresponding axis.
                                                                     Set to #true: Takes the 7 LSB bits of the x_THR_CONFIG register to create
                                                                     two opposite magnetic thresholds (one north, and another south) of
                                                                     equal magnitude. */
        bool use4xThres;                                        /**< Set to #false: Set the limit to 1 threshold crossing.
                                                                     Set to #true: Set the limit to 4 threshold crossing. */
        bool useBelowThres;                                     /**< Set to #false: Enable interrupt for field above the threshold.
                                                                     Set to #true: Enable interrupt for field below the threshold. */
    } __attribute__((packed)) TMAG5273_ThresConf_t;
    
    /** @brief TMAG5273 data point object definition.
     */
    typedef union
    {
        struct
        {
            int16_t x;                                          /**< Data for x axis. */
            int16_t y;                                          /**< Data for y axis. */
            int16_t z;                                          /**< Data for z axis. */
        } Vec;
        uint8_t Raw[8];                                         /**< Raw data. */
    } __attribute__((packed)) TMAG5273_Data_t;
    
    /** @brief TMAG5273 device object definition.
     */
    typedef struct
    {
        TMAG5273_Delay_t Delay;                                 /**< Platform specific delay function. */
        struct
        {
            TMAG5273_Write_t I2C_Write;                         /**< Platform specific I2C write function. */
            TMAG5273_Read_t I2C_Read;                           /**< Platform specific I2C read function. */
            const void* Instance;                               /**< Platform specific I2C instance. */
            uint8_t I2C_Address;                                /**< I2C address of the device. */
        } I2C;
        struct
        {
            bool isInitialized;                                 /**< Device was initialized successfully.
                                                                     NOTE: Managed by the driver. */
            bool UseCRC;                                        /**< Set to #true when a CRC is enabled.
                                                                     NOTE: Managed by the driver. */
        } Internal;
        uint8_t Ver:2;                                          /**< Device version.
                                                                     NOTE: Managed by the driver. */
        uint16_t RangeXY;                                       /**< Current device range for the x and y axis in mT.
                                                                     NOTE: Managed by the driver. */
        uint16_t RangeZ;                                        /**< Current device range for the x and y axis in mT.
                                                                     NOTE: Managed by the driver. */
        TMAG5273_Data_t Offset;                                 /**< Sensor offset. */
    } __attribute__((packed)) TMAG5273_t;
    
    /** @brief TMAG5273 interrupt object definition.
     */
    typedef struct
    {
        TMAG5273_IntMode_t Mode;                                /**< Interrupt mode. */
        bool usePulsed;                                         /**< INT latched or pulsed. Set to #true to enable latching. */
        bool useConvInt;                                        /**< Set to #true to enable conversion complete interrupts. */
        bool useThresInt;                                       /**< Set to #true to enable threshold cross interrupts. */
        const TMAG5273_ThresConf_t* const p_Threshold;          /**< Pointer to threshold data.
                                                                     NOTE: Only needed when \ref TMAG5273_IntConf_t.useThresInt is set to #true. */
    } __attribute__((packed)) TMAG5273_IntConf_t;
    
    /** @brief TMAG5273 device configuration object definition.
     */
    typedef struct
    {
        TMAG5273_Avg_t Average;                                 /**< */
        TMAG5273_TempCo_t TempCo;                               /**< */
        TMAG5273_Channel_t Channel;                             /**< */
        TMAG5273_PwrMode_t Mode;                                /**< */
        TMAG5273_Range_t XY;                                    /**< Range configuration for the x and y axis. */
        TMAG5273_Range_t Z;                                     /**< Range configuration for the z axis. */
        bool UseCRC;                                            /**< Set to #true to enable the CRC function. */
        bool UseGlichFilter;                                    /**< Enable the I2C glich filter. */
    } __attribute__((packed)) TMAG5273_Config_t;
    
    #endif /* TMAG5273_DEFS_H_ */

  • Hi Daniel,

    Thanks for sharing your code. I reviewed your tmag5273.cpp file and I noticed that in line 277, you are setting the INT_MODE field of INT_CONFIG_1 to 0x03, this setting configures the devices interrupt mode to interrupt through the serial clock instead of the INT pin. So when you meet your specified magnetic threshold your SCL pin will notify you of the interrupt instead of the pin on the device. To configure it correctly please refer to my suggestions in the previous post by setting INT_CONFIG_1 -> INT_MODE to 0x01. Let me know if you have any further questions!

    Best,

    ~Alicia  

  • Hi Alicia,

    thank you. I will check it on monday. I´m out of office for this week :) 

  • Hi @Alicia,

    Unfortunately, this wasn´t the issue. The line does set a bitmask for the INT_CONFIG_1 register. I have added a register dump before putting the device into wake&sleep mode:

    TMAG5273_Error_t TMAG5273_EnableWakeAndSleep(TMAG5273_t* const p_Device, TMAG5273_Sleep_t Sleeptime)
    {
        if((p_Device == NULL) || (Sleeptime > TMAG5273_SLEEP_20K))
        {
            return TMAG5273_ERR_INVALID_ARG;
        }
        else if(p_Device->Internal.isInitialized == false)
        {
            return TMAG5273_ERR_NOT_INITIALIZED;
        }
    
        TMAG5273_ERROR_CHECK(TMAG5273_SetSleepTime(p_Device, Sleeptime));
        TMAG5273_RegisterDump(p_Device);
        TMAG5273_ERROR_CHECK(TMAG5273_SetOperationMode(p_Device, TMAG5273_OPMODE_WS));
    
        return TMAG5273_ERR_OK;
    }

    And I got the following result:

    I (793) TMAG5273: Register 0x0: 0x14
    I (793) TMAG5273: Register 0x1: 0x12
    I (803) TMAG5273: Register 0x2: 0x77
    I (803) TMAG5273: Register 0x3: 0x0
    I (813) TMAG5273: Register 0x4: 0x0
    I (813) TMAG5273: Register 0x5: 0x0
    I (823) TMAG5273: Register 0x6: 0x2
    I (823) TMAG5273: Register 0x7: 0x0
    I (823) TMAG5273: Register 0x8: 0x44
    I (833) TMAG5273: Register 0x9: 0x0
    I (833) TMAG5273: Register 0xA: 0x0
    I (843) TMAG5273: Register 0xB: 0x0
    I (843) TMAG5273: Register 0xC: 0x6A
    I (843) TMAG5273: Register 0xD: 0x1
    I (853) TMAG5273: Register 0xE: 0x49
    I (853) TMAG5273: Register 0xF: 0x54
    I (863) TMAG5273: Register 0x10: 0x45
    I (863) TMAG5273: Register 0x11: 0x60
    I (873) TMAG5273: Register 0x12: 0xFF
    I (873) TMAG5273: Register 0x13: 0x92
    I (873) TMAG5273: Register 0x14: 0x0
    I (883) TMAG5273: Register 0x15: 0xC1
    I (883) TMAG5273: Register 0x16: 0x0
    I (893) TMAG5273: Register 0x17: 0x94

  • Hi Daniel,

    Thank you for sharing your register configurations. I noticed that you have only set a threshold for the z-axis, are you only checking to see if the threshold has been crossed in this direction? If this is the case, could it be possible that the magnet is approaching the sensor from from either the x- or y-axis instead of the z-axis? Just in case the image below is of the directions of sensitivity with relation to the device.

    If you are trying to have the threshold checked for both/either the x- and y-axis as well, make sure to set registers 0x4 and 0x5 as based off of your register dump they are set to 0, which means that there are no threshold comparisons for them.

    Best,

    ~Alicia

  • Hi Alicia,

    I have checked every side and have to change the interrupt source from threshold to conversion ready. It seems that the device isn´t generating any interrupt signa.

  • Hi Daniel,

    I checked the register configurations you sent, on my end the interrupt pin appeared to be working as expected. Please ensure that you have a pull-up resistor for the INT pin since it is open-drain and active low on this device. I included a capture of the EVM schematic below:

    Best,

    ~Alicia

  • Hi Alicia,

    thank you. I have figured out the issue. I have connected the wrong pin of the 12-pin connector from my TMAG5273EM to my MCU... Disappointed
    I have fixed the issue and the interrupt is generated now, but only when the device is in "Continious" mode. "Wake & Sleep" doesn´t work. I don´t get it...

    Is it possible to change the ticket to a private one and give you the whole firmware project and you can check it?

  • Hi Daniel,

    Glad to hear that you got the INT pint working! Unfortunately, we try not to review firmware projects since they can be lengthy and hard to understand at times. But I am glad to continue helping you to get the Wake & Sleep function working on your end. Please ensure that when entering Wake & Sleep mode, that it is the last communication that you do with the device, any additional I2C communication will send the device into Standby mode.

    Would it be possible for you to measure the current consumption you get in the state where you notice that Wake & Sleep mode is not working?

    Best,

    ~Alicia

  • Hi Alicia,

    the current consumption is around 88 mA before entering the Wake & Sleep mode and 86 mA after calling the function to enter the Wake & Sleep mode. So there is a small change in the current consumption.

  • Hey Daniel,

    Those numbers sound pretty high for the TMAG5273, but I am assuming that you are measuring the current of your entire system along with the sensor. The 86mA after calling the Wake & Sleep mode sounds like it could be right considering your active mode current of 88mA.

    To ensure you are in wake & sleep mode you can keep monitoring the current, you should see the current increase periodically based on the sampling period you configured. If you want to obtain more accurate readings I would recommend separating the sensors supply from your system and measuring the current off of just the sensor to ensure you are not accidentally picking up changes in your MCU.

    Best,

    ~Alicia

  • Hi Alicia,

    unfortunately, there is no way to measure the device alone.
    I don´t understand the behavior of the sensor, because it´s only one line of code that I change. The interrupt is correctly triggered in CONT mode (0x02) and when I change it to 0x03 (Wake & Sleep) no interrupt is started, but the current consumption goes down, indicating a mode switch from the device.

  • Hi Alicia,

    even the register configuration from the datasheet doesn´t work for me...

    I (692) TMAG5273: Register: 0x0, Mask: 0xFF, New Value: 0x1
    I (702) TMAG5273: Register: 0x2, Mask: 0xFF, New Value: 0x79
    I (702) TMAG5273: Register: 0x7, Mask: 0xFF, New Value: 0x1
    I (712) TMAG5273: Register: 0x8, Mask: 0xFF, New Value: 0xA4
    I (722) TMAG5273: Register: 0x1, Mask: 0xFF, New Value: 0x22
    I (722) TMAG5273: Register: 0x8, Mask: 0xFF, New Value: 0x64
    I (732) TMAG5273: Register: 0x1, Mask: 0xFF, New Value: 0x23

  • Hi Daniel,

    It's okay if you are unable to measure the current of the device separately, it was not a requirement but was more so recommended as a sanity check. However, when you do check the change in current, are you able to see it oscillate between wake & sleep mode, or do you just see the current go down and stay low?

    Best,

    ~Alicia  

  • Hi Alicia,

    I think I have a bug in my software. After testing a smaller software version without additional components, the problem was solved for sleep intervals up to 100 ms. Higher intervals don´t work, but I will try to figure out the problem.

  • Hi Daniel,

    I'm glad you were able to figure out the problem that you were having. If you have anymore questions that I can help with, please feel free to start a new post.

    Best,

    ~Alicia