MMC5983MA Example 6-SPI_Fast_continuous_measurement

Hi,

I am trying to use MMC5983MA on Arduino R4, I am aiming to get a data output rate of ~700 Hz (and this magnetometer is rated for that). I am following example 6, which is included in the library, but I can’t get it to work. Has anyone else managed to get high Data rate with this sensor? Or is example 6 working for you guys?

Specific Question:
The example file states Hardware connections. Init, I need to connect CS to pin4 on an Arduino, but this sensor doesn’t have a CS pin. Am I missing something?

1 Like

If you are getting the ‘…connected’ message and data is being read then CS doesn’t matter.

Can you describe what is meant by ‘can’t get it to work’? Are you getting interrupts to occur at the default 100 rate? Are you able to read the values and do the conversion? Or is all this working but you aren’t able to push the continuous measurement frequency above a certain value? If so, what is the value and happens when you try?

If the problem is that you can’t get the rate high enough then it might be a part of the code is taking too long to execute. You can test by deleting code to find where the delay is. Start by deleting everything in the main loop except for a counter for the interrupts, and flash the led on a regular count (eg, mod 1000). That will enable you to see the interrupt timing when there is minimal delay in the processing loop. If that indicates that the device is generating interrupts at the expected rate then add back code portions (get data, do calculation, display result) to see which procedure is creating the excessive delay.

5 Likes

Hey @Gaurav275352,

The CS pin the example file is referring to is a ‘Chip Select’ pin that is part of the SPI protocol. If your MMC5983MA module doesn’t have this pin there is a chance it uses something else to communicate like I2C.

Would you be able to let us know the exact magnetometer you have or send us a product link? A photo would also work.

4 Likes

Good point. The example I referred to is example 3 which is I2C. If OP is running example 6 as stated then it will be SPI and CS will be relevant. It is pin 4 on the chip. If it’s not available on the module breakout then the module is configured for I2C only and example 6 will not work.

Screenshot 2024-08-21 101050

Hi, thanks for the reply. This is the output on the serial monitor (attached picture). These are first few lines of code

#include <SPI.h>

#include <SparkFun_MMC5983MA_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_MMC5983MA

SFE_MMC5983MA myMag;

int csPin = 4;

int interruptPin = 2;

volatile bool newDataAvailable = true;
uint32_t rawValueX = 0;
uint32_t rawValueY = 0;
uint32_t rawValueZ = 0;
double scaledX = 0;
double scaledY = 0;
double scaledZ = 0;
double heading = 0;

void setup()
{
    Serial.begin(115200);
    Serial.println("MMC5983MA Example");

    SPI.begin();

    // Configure the interrupt pin for the "Measurement Done" interrupt
    pinMode(interruptPin, INPUT);
    attachInterrupt(digitalPinToInterrupt(interruptPin), interruptRoutine, RISING);

    while (myMag.begin(csPin) == false)
    {
        Serial.println("MMC5983MA did not respond. Retrying...");
        delay(500);
        myMag.softReset();
        delay(500);
    }

    myMag.softReset();

    Serial.println("MMC5983MA connected");

SparkFun Micro Magnetometer - MMC5983MA (Qwiic) | SEN-19921 | Core Electronics Australia (core-electronics.com.au)

This is the product I am using.

I will try what you mentioned in Example-3, I am getting an output rate of 10Hz using I2C_continuos_measurement.
Update: With an empty loop, I get a data rate of ~725000Hz.
After adding these 3 lines the output rates drops to 10Hz

newDataAvailable = false; // Clear interrupt flag
myMag.clearMeasDoneInterrupt(); // Clear the MMC5983 interrupt

myMag.readFieldsXYZ(&rawValueX, &rawValueY, &rawValueZ);

That module has CS tied high - the chip is permanently selected and CS is not required. So if Example 6 isn’t working I would suspect a problem with how it is connected.

If that’s not a typo then it can’t be right. Perhaps the minimum code required to measure the maximum interrupt rate includes clearMeasDoneInterrupt() as well as resetting the flag.

1 Like