cancel
Showing results for 
Search instead for 
Did you mean: 

DRDY_MAG interrupt on LSM303C?

James Millard
Associate II
Posted on June 28, 2018 at 04:13

Can anyone tell me how to get a DRDY_MAG on the LSM303C?  Is that the correct interrupt to try and get for the magnetometer?  I'm trying to get mag data at about 10Hz and want an interrupt.  Nothing I have done has caused the interrupt to happen (using an oscilloscope to see the interrupt).

I have two spark fun breakout boards.  The accelerometer works fine.  The magnetometer does not call any interrupt that I can see.  The documentation shows the pin, but it doesn't say anything about it.

On startup, I am doing a reset of both the accelerometer and the magnetometer.  WHO_AM_I reads correctly for both.

I've attached the data sheet I'm using -- you can search for DRDY_MAG and find very little.

My configuration looks like this (I'm hoping it's self explanatory):

/* Accelerometer */

LSM_FIFO_CTRL reg_fifo_ctrl;

reg_fifo_ctrl.FMODE = LSM303C_A_FIFO_MODE_OFF;

lsm303c_set_register(true, LSM303C_REG_FIFO_CTRL, reg_fifo_ctrl.Byte);

LSM_CTRL_REG1_A reg_ctrl1_a;

reg_ctrl1_a.XEN = true;

reg_ctrl1_a.YEN = true;

reg_ctrl1_a.ZEN = true;

reg_ctrl1_a.BDU = true;

reg_ctrl1_a.ODR = LSM303C_A_OUTPUT_DATA_RATE_10_HZ;

reg_ctrl1_a.HR = false;

lsm303c_set_register(true, LSM303C_REG_CTRL_REG1_A, reg_ctrl1_a.Byte);

LSM_CTRL_REG2_A reg_ctrl2_a;

reg_ctrl2_a.Byte = 0;

lsm303c_set_register(true, LSM303C_REG_CTRL_REG2_A, reg_ctrl2_a.Byte);

LSM_CTRL_REG3_A reg_ctrl3_a;

reg_ctrl3_a.Byte = 0;

reg_ctrl3_a.INT_XL_DRDY = true;

lsm303c_set_register(true, LSM303C_REG_CTRL_REG3_A, reg_ctrl3_a.Byte);

LSM_CTRL_REG4_A reg_ctrl4_a;

reg_ctrl4_a.Byte = 0;

lsm303c_set_register(true, LSM303C_REG_CTRL_REG4_A, reg_ctrl4_a.Byte);

LSM_CTRL_REG5_A reg_ctrl5_a;

reg_ctrl5_a.Byte = 0;

lsm303c_set_register(true, LSM303C_REG_CTRL_REG5_A, reg_ctrl5_a.Byte);

/* Magnetometer */

LSM_CTRL_REG1_M reg_ctrl1_m;

reg_ctrl1_m.Byte = 0;

reg_ctrl1_m.DO = LSM303C_M_OUTPUT_DATA_RATE_1_2;

reg_ctrl1_m.OM = LSM303C_M_XY_OP_MODE_MEDIUM_PERF;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG1_M, reg_ctrl1_m.Byte);

LSM_CTRL_REG2_M reg_ctrl2_m;

reg_ctrl2_m.Byte = 0;

reg_ctrl2_m.FS = LSM303C_M_FULL_SCALE_16_GAUSS;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG2_M, reg_ctrl2_m.Byte);

LSM_CTRL_REG3_M reg_ctrl3_m;

reg_ctrl3_m.Byte = 0;

reg_ctrl3_m.MD = LSM303C_M_SYS_OP_MODE_SINGLE_CONVERSION;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG3_M, reg_ctrl3_m.Byte);

LSM_CTRL_REG4_M reg_ctrl4_m;

reg_ctrl4_m.Byte = 0;

reg_ctrl4_m.OMZ = LSM303C_M_Z_OP_MODE_MEDIUM_PERF;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG4_M, reg_ctrl4_m.Byte);

LSM_CTRL_REG5_M reg_ctrl5_m;

reg_ctrl5_m.Byte = 0;

reg_ctrl5_m.BDU = false;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG5_M, reg_ctrl5_m.Byte);

lsm303c_set_register(false, LSM303C_REG_INT_THS_L_M, 0x0);

lsm303c_set_register(false, LSM303C_REG_INT_THS_H_M, 0x0);

LSM_INT_CFG_M reg_int_cfg_m;

reg_int_cfg_m.IEN = false;

reg_int_cfg_m.IEL = false;

reg_int_cfg_m.IEA = false;

reg_int_cfg_m.ONE = 1; /* Must be one */

reg_int_cfg_m.ZERO = 0; /* Must be zero */

reg_int_cfg_m.ZIEN = false;

reg_int_cfg_m.YIEN = false;

reg_int_cfg_m.XIEN = false;

lsm303c_set_register(false, LSM303C_REG_INT_CFG_M, reg_int_cfg_m.Byte);
5 REPLIES 5
Miroslav BATEK
ST Employee
Posted on July 09, 2018 at 11:17

The device generated magnetometer DRDY signal all the time, no particular settings is needed.

Posted on July 10, 2018 at 03:19

Then I'm confused I guess, because my o-scope shows nothing happening on the DRDY pin.  Anybody know why?

Posted on July 13, 2018 at 11:12

Can you please check that the pin is not accidentally shorted? If it is connected to a MCU please check the GPIO is configured as input and dons't force VDD or GND.

Are you able to get the magnetometer data?

Posted on July 14, 2018 at 04:30

It's not connected to anything except my o-scope and it's not shorted.  I can read data, I just don't know if it's noise or data.

Posted on July 16, 2018 at 11:26

You configured the mode to single conversion:

LSM_CTRL_REG3_M reg_ctrl3_m;

reg_ctrl3_m.Byte = 0;

reg_ctrl3_m.MD = LSM303C_M_SYS_OP_MODE_SINGLE_CONVERSION;

lsm303c_set_register(false, LSM303C_REG_CTRL_REG3_M, reg_ctrl3_m.Byte);

Please change it to Continuous-conversion mode and then check the DRDY signal.