Requesting data from two I2C sensors at the same time

Happy New Year all!

I currently have Sparkfun’s MMA8452 3-axis accelerometer https://www.sparkfun.com/products/10955 and ITG3200 3-axis gyro https://www.sparkfun.com/products/9801 breakouts hooked up to an Arduino Mega master. My current setup, as with most examples that I’ve drawn from and tested, is to request XYZ data from the accelerometer, wait for the data to become available, perform calculations, then request data from the gyro, wait for the data to become available, and perform those calculations. For the sake of making this process faster and have the accelerometer and gyro readings closer in terms of time, I was wondering if it would be possible to send a read request to both sensors concurrently and receive a consistent “joint” response or if this is just wishful thinking?

Here’s my code if it helps (I know my register management is terrible but this was only a quick test written at 2:30 in the morning :P):

#include <Wire.h>
#define gyro 0x69
#define accel 0x1D
// Read bytesToRead sequentially, starting at addressToRead into the dest byte array
void readRegisters(int dev, byte addressToRead, int bytesToRead, byte * dest)
{
  Wire.beginTransmission(dev);
  Wire.write(addressToRead);
  Wire.endTransmission(false); //endTransmission but keep the connection active

  Wire.requestFrom(dev, bytesToRead); //Ask for bytes, once done, bus is released by default

  while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect

  for(int x = 0 ; x < bytesToRead ; x++)
    dest[x] = Wire.read();    
    
    
}

// Read a single byte from addressToRead and return it as a byte
byte readRegister(int dev, byte addressToRead)
{
  Wire.beginTransmission(dev);
  Wire.write(addressToRead);
  Wire.endTransmission(false); //endTransmission but keep the connection active

  Wire.requestFrom(dev, 1); //Ask for 1 byte, once done, bus is released by default

  while(!Wire.available()) ; //Wait for the data to come back
  return Wire.read(); //Return this one byte
}

// Writes a single byte (dataToWrite) into addressToWrite
void writeRegister(int dev, byte addressToWrite, byte dataToWrite)
{
  Wire.beginTransmission(dev);
  Wire.write(addressToWrite);
  Wire.write(dataToWrite);
  Wire.endTransmission(); //Stop transmitting
}

void setup() {
  Wire.begin();
  Serial.begin(115200);
  byte c = readRegister(accel, 0x2A);
  Wire.beginTransmission(accel);
  Wire.write(0x2A);
  Wire.write(c & ~(0x01)); //standby mode
  Wire.endTransmission();
  Wire.beginTransmission(accel);
  Wire.write(0x0E);
  Wire.write(0x01); //4G
  Wire.endTransmission();
  Wire.beginTransmission(accel);
  Wire.write(0x2A);
  Wire.write(c | 0x01); //standby mode
  Wire.endTransmission();
  
  Wire.beginTransmission(gyro);
  Wire.write(0x16);
  Wire.write(B00011001);//±2000º/s, 1kHz internal sampling rate
  Wire.endTransmission();
  Wire.beginTransmission(gyro);
  Wire.write(0x15);
  Wire.write(0x04); //set to 100hz sampling rate
  
}
void loop() {
  byte accels[6];
  readRegisters(accel, 0x01, 6, accels); //0x01 = MSB
  float accel_int_vals[3] = {0};
  for(byte i=0; i<6; i+=2) {
    Serial.print((float)(((accels[i]<<8 | accels[i+1]))/16) / (1<<(12-3)), 4);
    Serial.print('\t');
  }
  Serial.print('\n');
  delay(100);
  
  for(byte i=0; i<6; i+=2) {
    byte MSB = 0x1D;
    int temp = (readRegister(gyro, MSB+i)<<8) | readRegister(gyro, MSB+i+1);
    Serial.print((float)(temp/16)/14.375, 4);
    Serial.print('\t');
  }
  Serial.print('\n');
}

or if this is just wishful thinking?

Yes.