I2C: Send 2 variables from Arduino nano 33 IoT (IMU) to another Arduino

Hi friends!
I am writing you to ask some help. I tried all…but I don’t know what else to do.
I am trying to send the pitch and roll from Arduino Nano 33 IoT (master) to another Arduino (slave). With Arduino nano 33 IoT and MadgwickAHRS library is possible to get very well angles. But, it is going slowly and I am getting strange values.
Can you help me, please?
Thank you very much.

MASTER

#include "Wire.h";
#include <Arduino_LSM6DS3.h>
#include <MadgwickAHRS.h>
Madgwick filter;
const float sensorRate = 104.00;
const byte I2C_SLAVE_ADDR = 0x20;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU");
    while (true);
  }
  filter.begin(sensorRate);

}
void loop() {

  float xAcc, yAcc, zAcc;
  float xGyro, yGyro, zGyro;
  float roll, pitch, heading;
  if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
    // read accelerometer & gyrometer:
    IMU.readAcceleration(xAcc, yAcc, zAcc);
    IMU.readGyroscope(xGyro, yGyro, zGyro);
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.setClock(3400000UL);

    // update the filter, which computes orientation:
    filter.updateIMU(xGyro, yGyro, zGyro, xAcc, yAcc, zAcc);

    // print the heading, pitch and roll
    roll = filter.getRoll();
    pitch = filter.getPitch();

    Wire.write((int) roll);
    Wire.write((int) pitch);
  }
  Wire.endTransmission();
}

SLAVE

#include "Wire.h"

const byte I2C_SLAVE_ADDR = 0x20;

void setup() {
  Wire.begin(I2C_SLAVE_ADDR);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}
void loop() {
}

void receiveEvent(int bytes)
{
  int numero, numeroAnterior;
  while (Wire.available())
  {
    numero = Wire.read();

    if (numero != numeroAnterior) {
      Serial.print("numero: ");
      Serial.println(numero);
      Serial.print("numero Anterior: ");
      Serial.println(numeroAnterior);
      Serial.println(" ");
    }
    numeroAnterior = numero;
    //Serial.println(bytes);
  }
}

i2c write() will only transmit one byte. You can not write in 'int' directly.

You master should not be changing the clock speed every time through loop() - that goes in setup() [or leave it out entirely]

master

#include "Wire.h";
#include <Arduino_LSM6DS3.h>
#include <MadgwickAHRS.h>
Madgwick filter;
const float sensorRate = 104.00;
const byte I2C_SLAVE_ADDR = 0x20;

void setup() {
  Wire.begin();
  Wire.setClock(3400000UL);
  Serial.begin(9600);
  if (!IMU.begin()) {
    Serial.println("Failed to initialize IMU");
    while (true);
  }
  filter.begin(sensorRate);

}
void loop() {

  float xAcc, yAcc, zAcc;
  float xGyro, yGyro, zGyro;
  float roll, pitch, heading;
  if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) {
    // read accelerometer & gyrometer:
    IMU.readAcceleration(xAcc, yAcc, zAcc);
    IMU.readGyroscope(xGyro, yGyro, zGyro);

    // update the filter, which computes orientation:
    filter.updateIMU(xGyro, yGyro, zGyro, xAcc, yAcc, zAcc);

    // print the heading, pitch and roll
    roll = filter.getRoll();
    pitch = filter.getPitch();

    byte rollH = ((int)roll)>>8;
    byte rollL = (byte)roll;
    byte pitchH = ((int)pitch)>>8;
    byte pitchL = (byte)pitch;
    Wire.beginTransmission(I2C_SLAVE_ADDR);
    Wire.write(rollH);
    Wire.write(rollL);
    Wire.write(pitchH);
    Wire.write(pitchL);
  Wire.endTransmission();
  }
}

Slave

#include "Wire.h"

const byte I2C_SLAVE_ADDR = 0x20;

void setup() {
  Wire.begin(I2C_SLAVE_ADDR);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}
void loop() {
}

void receiveEvent(int bytes)
{
  int numero, numeroAnterior;
  while (Wire.available())
  {
    int roll = Wire.read() << 8 + Wire.read();
    int pitch =Wire.read() << 8 + Wire.read();

    if (numero != numeroAnterior) {
      Serial.print("numero: ");
      Serial.println(numero);
      Serial.print("numero Anterior: ");
      Serial.println(numeroAnterior);
      Serial.println(" ");
    }
    numeroAnterior = numero;
    //Serial.println(bytes);
  }
}