2025-10-03 6:50 AM
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, ®Val)) 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;
}
Solved! Go to Solution.
2025-10-06 12:30 AM
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.
2025-10-06 12:30 AM
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.
2025-10-06 12:34 AM
Thank you very much!!!!