Skip to main content
Explorer
October 3, 2025
Solved

Problem with Resetting LSM303AGR sensor

  • October 3, 2025
  • 1 reply
  • 221 views

 

Hello everyone,

I am using I2C to communicate between an STM32F411 Discovery Board and the on-board LSM303AGR sensor. I have already configured it for a 400Hz ODR, normal power mode, and am reading temperature values (around 25°C to 27°C).

However, I am stuck on how to soft-reset the entire sensor. I tried to SET bit 5 in CFG_REG_A_MAG and adding a small delay, but this does not reset the values I configured in other registers. Those settings remain the same, no matter how many times I try to SET the reset bit.

The registers only reset when I unplug and plug the power back in.

Please help me.

Thank you very much.

bool LSM303AGR_softReset(const LSM303AGR_t* lsm303agrStruct){
	uint8_t regVal = 0;
	if(!readMag(lsm303agrStruct, LSM303AGR_CFG_REG_A_MAG, &regVal)) return false; //Extract the current status bit-field and assign it to regVal

	/* Start to assign and write regVal to CFG_REG_A to start FULL CHIP RESET */
	regVal |= (SET << REG_A_SOFT_RST_Pos);
	if(!writeMag(lsm303agrStruct, LSM303AGR_CFG_REG_A_MAG, regVal)) return false;
	HAL_Delay(50);
	return true;
}

 

    This topic has been closed for replies.
    Best answer by Federica Bossi

    Hi @DoBaoLong ,

    CFG_REG_A_M (register 0x60) bit 5 (SOFT_RST) triggers a soft reset: when this bit is set, the configuration registers and user registers are reset. Flash registers keep their values.

    The only way to fully reset all registers to default values is to power cycle the sensor (i.e., disconnect and reconnect power).

    Alternatively, you can manually re-initialize all registers in your firmware to desired default or startup values after a soft reset.

    1 reply

    Technical Moderator
    October 6, 2025

    Hi @DoBaoLong ,

    CFG_REG_A_M (register 0x60) bit 5 (SOFT_RST) triggers a soft reset: when this bit is set, the configuration registers and user registers are reset. Flash registers keep their values.

    The only way to fully reset all registers to default values is to power cycle the sensor (i.e., disconnect and reconnect power).

    Alternatively, you can manually re-initialize all registers in your firmware to desired default or startup values after a soft reset.

    DoBaoLongAuthor
    Explorer
    October 6, 2025

    Hi @Federica Bossi 

    Thank you very much!!!!