Sd card logging messing my sensors

Hi i've been work with IMU(Inertial measurement unit) for a while.
Few weeks ago,I change all sensors interface into SPI,then some issue coming out..

My sensor include two IMU chip(2*(accelerometer、gyroscope)) 、two magnetometer.
Total have six of 3axis data,working in 100hz,MCU i'm using is teensy 4.0.

When i add " logFile.println(logdata); " this line into the code,which mean writing the data to sd card.Issues is coming out...
IMU1(accelerometer1、gyroscope1)'s readings will all go 0 after around 4000s later.
and the magnetometer will have so kind off 8hz noise at y、z axis.

Before i change the circuit ,magnetometers was IIC interface,and was works well.

At first i add some delay around the reading sensors,but it didnt work..
I think there is some more component i need to add to the circuit for
stablize..help..
I already add 820u and 2.2u capacitor to the teensy vin and 3.3v.But still happening.

MAIN CODE


void loop() {
  t0 = millis() * 0.001;

  delayMicroseconds(2000);

  IMU.configSPI();

  delayMicroseconds(2000);
   if (digitalRead(acc16475_DR) == HIGH) {
    getmydata475();
  }  
  if (digitalRead(acc16507_DR) == HIGH) {
    getmydata507();
  }
  
  mag_data_SPI();  //5 27  

  magdata = String(xm[1], 5) + ", " + String(ym[1], 5) + ", " + String(zm[1], 5) + ", " + String(xm[2], 5) + ", " + String(ym[2], 5) + ", " + String(zm[2], 5);
  accdata = String(ax, 7) + ", " + String(ay, 7) + ", " + String(az, 7) + ", " + String(ax2, 7) + ", " + String(ay2, 7) + ", " + String(az2, 7);
  gyrdata = String(gx, 6) + ", " + String(gy, 6) + ", " + String(gz, 6) + ", " + String(gx2, 6) + ", " + String(gy2, 6) + ", " + String(gz2, 6);
  logdata =  String(timee, 3) + ", " + accdata + "," + gyrdata + ", " + magdata + ", " + String(f, 2) + ", " + String(delayy);

  
  Serial.println(logdata);

    if (!logFile) {
    logFile = SD.open(logFileName, FILE_WRITE);
  }
    logFile.println(logdata);


  //timer
  if (t0 >= 5) {
    if (i == 0) {
      t1 = millis();
    }
    i++;
    timer();
  }
  delayMicroseconds(delayy);
}

Presumably you are in the process of posting your schematic


somewhere like this.
Mag pin
p1-2:SCLK
p1-3:MISO
p1-4:MOSI
p2-1:vcc
p2-2:gnd
p2-3:CS

IMU pin
1:vcc
2:gnd
3:CS
4:MOSI
6:MISO
8:SCLK

SD pin
1:vcc
2:gnd
3:CS
4:MOSI
5:SCLK
6.MISO

Which SD card module do you have?

this one

That's the correct one for a 3.3v system like you have. At least we can rule out the usual issue with the MISO line on the SD card.

Next step is to post all the code, rather than part of it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.