Corrupted data after slave reset

In the last days, i have ventured into i2c.

I used two Arduino UNO (master and slave), two load cells and one hx711 connected to the arduino slave. The information read by the slave is sent by i2c to the master. Finally, the master Arduino displays the received data.

LOAD CELL -> HX711 -> SLAVE ARDUINO -> (I2C) -> Arduino Master -> (Serial.println)

Overall, what i did seems to work fine. However, when i reset the slave, the data received by the master arrives modified. For example: If the master receives the value 0.00kg, and soon after i reset the slave, the master will display unrealistic values: 767284.00kg, 717223.00kg, 7321312.00kg ...

Why does this happen? i already researched and couldn't reach big conclusions ...

Master code:

#include <Wire.h>

void setup() {
  Serial.begin(9600);
  Wire.begin();
  delay(3000);  
}


void loop() {
  Wire.requestFrom(8, 10);

  while(Wire.available()){
    Serial.print((char)Wire.read());
  }

  Serial.println();
  delay(10);
}

Slave code:

#include <HX711.h>
#include <Wire.h>

HX711 left_knee; //DOUT, CLK

float calibration_factor_left_knee =  2033.25; // this calibration factor is adjusted according to my load cell

String out; 
float units;

void setup() {
  Wire.begin(8);
  Wire.onRequest(requestEvent);
  
  left_knee.begin(2,3);
  left_knee.tare();  // Tara a balança
  left_knee.set_scale(calibration_factor_left_knee); // Ajusta fator de calibração
}

void loop() {
  delay(100);
}

void requestEvent() {
  out = "";
  units = left_knee.get_units(); 
  out = data();
  Wire.write(out.c_str(),out.length());
}

float data(){
  if (units < 0)
  {
    units = 0.00;
  }
  return (units);
}

btw, the communication only returns to normal when the master is rebooted.
Thanks in advance

zpx:
btw, the communication only returns to normal when the master is rebooted.

This is the normal behavior of a system. You must allow time for both systems to stabilize after interruption. Be sure that the sketch is designed in such a way so that the MCU can detect the interruption and saves the last states of the process in non-volatile memory.

Why does this happen? i already researched and couldn't reach big conclusions ...

I2C is designed to be an onboard communication channel between sensors and other chips and one master (usually the main processor). If such a board is reset all components get reset at the same time. In your case if the slave is reset, the master continues to request data from the slave. Once the slave has finished startup and is ready to answer requests the master may be in the middle of such a request. The slave simply sends it's data but the master interprets them completely different as the start bit is moved.

String out;

Don't use the String class on the AVR platform. It fragments the memory and sooner or later you'll run into problems because no big enough blocks may be available.

Thanks for the answers.
In the last days, i've made some code changes and i noticed that if the delay (in the master loop) is greater than 100ms, the master can sync again with the slave (after reset), stopping receiving unrealistic values.
However, to get a faster response, i kept the 10ms and introduced a function that resets the master whenever it receives too high values from the slave. Thanks again!