Setting up the FXOS8700CQ Magnetometer side only?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting up the FXOS8700CQ Magnetometer side only?

Jump to solution
2,961 Views
lukelynch
Contributor III

Hello,

I want to use the magnetometer side of the FXOS8700CQ only. I basically what to see when a magnet passes a point in front of the device.

Basically i want to know what registers do i need to write to and what to write so to configure the device for the magnetometer.

Also i would like to configure the interrupt so to make me aware when new data is available, how is this set up?

I have this component placed on one of my boards and is communicating over I2C to a stm32 micro controller.  

I have my i2c all configured and have a function wrote so i can read data from a specific or write data to a specific register.

I have read from the who am i register and i am receiving the 0xC7. I have a logic analyzer proving this.  

If any one could help i would be grateful.

Regards,

Luke.

Labels (1)
1 Solution
1,889 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Luke,

If you simply want to use the INT1 pin to indicate when a new set of magnetometer data is available to be read, you can use the following example sequence:

1. Write M_CTRL_REG1 = 0x1D     // Max oversampling to reduce magnetometer noise, only magnetometer active

2. Write CTRL_REG4 = 0x01          // Data-ready interrupt enabled

3. Write CTRL_REG5 = 0x01          // Data-ready interrupt routed to INT1 pin

4. Write CTRL_REG1 = 0x29          // 12.5Hz ODR, active mode

5. Idle until INT1 is triggered. Note that INT1 signal polarity can be set through the IPOL bit in the CTRL_REG3 register.

6. In your ISR, read magnetometer data from registers 0x33 to 0x38. INT1 is automatically cleared when register 0x33 is read.

However, for your application I would recommend using the embedded magnetic threshold or vector-magnitude functions. Both functions can also generate an inrepput once a preset threshold value is exceeded. For more information on these functions and register settings, please refer to sections 10.16 and 10.18 of the FXOS8700CQ datasheet​.

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

View solution in original post

10 Replies
1,890 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Luke,

If you simply want to use the INT1 pin to indicate when a new set of magnetometer data is available to be read, you can use the following example sequence:

1. Write M_CTRL_REG1 = 0x1D     // Max oversampling to reduce magnetometer noise, only magnetometer active

2. Write CTRL_REG4 = 0x01          // Data-ready interrupt enabled

3. Write CTRL_REG5 = 0x01          // Data-ready interrupt routed to INT1 pin

4. Write CTRL_REG1 = 0x29          // 12.5Hz ODR, active mode

5. Idle until INT1 is triggered. Note that INT1 signal polarity can be set through the IPOL bit in the CTRL_REG3 register.

6. In your ISR, read magnetometer data from registers 0x33 to 0x38. INT1 is automatically cleared when register 0x33 is read.

However, for your application I would recommend using the embedded magnetic threshold or vector-magnitude functions. Both functions can also generate an inrepput once a preset threshold value is exceeded. For more information on these functions and register settings, please refer to sections 10.16 and 10.18 of the FXOS8700CQ datasheet​.

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

1,889 Views
lukelynch
Contributor III

Just another question to add for you tomas. I decided i want to set the value of my threshold for the z axis. "the M_THS_X/Y/Z registers contain the unsigned 15-bit magnetic thresholds". "Each register has a resolution of 0.1 uT/LSB". Within the M_THS_Z register you have the LSB[7:0] and MSB[14:8]. I know from using my evaluation kit my threshold should be: 150uT. How do you work out what HEX value to send? Obliviously this is divided into two separate hex values (lower half to the LSB and the upper to the MSB).

The M_THS_COUNT. Is it set by the ODR value(set by m_os of M_CTRL_REG2) or do you physically have to write to the M_THS_COUNT to set this?

As you set M_CTRL_REG1 to 0x1D, this puts it in 800hz mode, this will not work yes?

Regards,

Luke. 

0 Kudos
1,889 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Luke,

There are 9 registers associated with the embedded magnetic threshold function. These are registers 0x52 to 0x5A.

1. Register 0x52 M_THS_CFG: Magnetic threshold function - configuration register

2. Register 0x53 M_THS_SRC: Magnetic threshold function - interrupt source register

3. Registers 0x54 – 0x59 M_THS_XYZ: Magnetic threshold function - threshold limits

4. Register 0x5A M_THS_COUNT: Magnetic threshold function – debounce counter

Here is an example settings considering your requirements:

1. Write CTRL_REG1 = 0x00          // Standby mode to change registers

2. Write M_THS_CFG = 0xE3         // Enable latch, “OR” condition, z-axis, interrupt and route it to INT1 pin

3. Write M_THS_Z_MSB = 0x05     // Set z-axis threshold to 150 uT = 1500 counts = 0x05DC

4. Write M_THS_Z_LSB = 0xDC

5. Write M_THS_COUNT = 0x01    // Set debounce time to e.g. 80 ms at 12.5 Hz (see table 194 for more info)

6. Write M_CTRL_REG1 = 0x1D    // Max oversampling to reduce magnetometer noise, only magnetometer active

7. Write CTRL_REG1 = 0x29         // 12.5 Hz ODR, active mode

8. Idle until INT1 is triggered.

9. In your ISR, read the M_THS_SRC register 0x53 to clear the event flags and deassert the INT1 interrupt.

I hope that helps.

Regards,

Tomas

1,889 Views
lukelynch
Contributor III

Thank you very much.

I have a question reading how the interrupt works. Once M_THS_SRC register is read it clears the flag, what happens if the z-axis is still above the threshold? will the flag be reset? What happenes the interrupt if you disable the latching (m_ths_ele=0)?

Should I be calibrating the device? Do i need to do anything with M_OFF_X/Y/Z_MSB/LSB?

Regards,

Luke.

0 Kudos
1,889 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Luke,

If you disable the latching (m_ths_ele = 0), both the m_ths_ea and m_ths_zhe flags as well as the corresponding INT pin will change their state with the realtime status of the magnetic threshold detection logic. On the other hand, if the latch is enabled (m_ths_ele = 1), the flags and the INT pin remain active until the M_THS_SRC register is read. It is actually illustrated in Figure 20 through Figure 23 of the FXOS21002 datasheet.

The FXOS8700CQ has a very small offset of 10 uT typically, so I do not think you need to deal with initial calibration unless there is a significant spurious magnetic field resulting from any nearby ferromagnetic components on the PCB.

You can also consider using the vector-magnitude function, if the simple threshold function will not meet your needs. Then I would refer to the AN4458 including the example code.

Regards,

Tomas

1,889 Views
lukelynch
Contributor III

I have a good understanding of the latching now. 

Calibration is something i can consider later.

From my testing i have a question. If i enable the z-axis only and set my m_ths_z_msb/lsb to 150uT (1500 counts = 0x05DC) and then bring a magnetic from behind/below the device (-z-axis) it sets my interrupt. Does the 150uT mean +-150uT? Is there away to set it so i can decide + only?

Or will i have to set up a latching interrupt, read the source and then read polarity and determine if it plus or minus this way?

I will look into vector-magnitude function and see is it applicable to what im doing.

Regards,

Luke.

0 Kudos
1,889 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Luke,

The FXOS8700CQ does not allow to set the threshold as positive or negative, it is an absolute value (unsigned 15-bit, 0.1 uT/LSB) and the easiest way to distinguish the polarity is, as you correctly mentioned, using the m_ths_zhp flag in the M_THS_SRC register (0x53).

Regards,

Tomas

1,889 Views
lukelynch
Contributor III

pastedImage_0.png

This image will give you an idea of my set-up.

0 Kudos
1,889 Views
lukelynch
Contributor III

Hello again Tomas,

I set up the interrupt as latching and when it goes low i read the M_THS_SRC register to check if it was positive or negative polarity. I wanted to do this to eliminate an interrupt if someone stuck a magnet against the back of the PCB (-Z-axis) the FXOS8700CQ is mounted on to stop false detections. From testing i see its not the positive or negative of the z-axis but the polarity of the magnet? would that be correct?

Would any off the other functions allow me to detect a magnet force within lets say 200 counts of x/y/z coordinate(in counts, example: 500,500,1100)

Or can you think of another way? or by software etc?

Basically i dont want it to give out an interrupt if some was to stick a magnet against the rear of the PCB (rear of the magnetometer).

Regards,

Luke

0 Kudos
1,889 Views
lukelynch
Contributor III

Thank you for your reply Tomas. I think you are correct about using the threshold function. I basically want the magnetometer to act as a switch, when a magnet is in front of it generate a interrupt and none when its not present. Setting the threshold value will be my on off point.

Ok so if I want to go down this route where would i start? (I have read the datasheet, gone through all the registers but it can be a bit confusing as there are also all the accelerometer registers as well).

Obviously the points 1 to 6 will be different now yes?

If i was to use the threshold function, can i set the "High-g Positive Threshold value" for each x y and x (so all have a different value) and when all of them exceed their value generate an interrupt or is it (from my reading of the datasheet) when any of the 3 cross the  "High-g Positive Threshold value" it will generate an interrupt?

Regards,

Luke.