i2c Wire.read() duplicating last parameter sent?

Hi!

I'm using the i2c for 2 atmegas talk to each other..

Its working fine, but when one of the values gets higher then 10, seems to increase the string and the slave duplicate the last parameter...

Master:

char buffer_envio_i2c[40];
char vbuffer_para_float_climb[10];
sprintf(buffer_envio_i2c, "%s,%d,%d,%d,%d", dtostrf(vclimb_smooth, 5, 2, vbuffer_para_float_climb), EEPROM.read(4), EEPROM.read(5), parametro_diverso_modulo_beep, EEPROM.read(1));

Wire.beginTransmission(7); 
Wire.write(buffer_envio_i2c);    
Wire.endTransmission();

The values are comma delimited.. ie 5.21,2,0,0,4

Seems like when the first value, go higher than 10, it seems to duplicate the last parameter(in this case, the value 4).

Slave:

void loop()
{
    if (haveData)
    {
        String vmonta_string_para_envio_i2c;
        vmonta_string_para_envio_i2c = "";

        int i = 0;
        while (Wire.available())
        {
            vretorno[i] = Wire.read(); // receive a byte
            i++;
        }


        char delimitador[] = ",";
        char *resultado = NULL;
        resultado = strtok(vretorno, delimitador);

        int vint_resultado = 0;
        while (resultado != NULL) {
            vint_resultado++;
            if (vint_resultado == 1)
            {
                vmedia_climb_smooth = atof(resultado);
            }
            else if (vint_resultado == 2)
            {
                valerta_descendente = atoi(resultado);
            }
            else if (vint_resultado == 3)
            {
                valerta_ascendente = atoi(resultado);
            }
            else if (vint_resultado == 4)
            {
                parametro_recebido = atoi(resultado);
            }
            else if (vint_resultado == 5)
            {
                vtom_cliente = atoi(resultado);
                //THATS WHERE THE PROBLEM OCCURS...
                //THE VALUE is 4 sent as 4, but here it arrives 44
            }
            resultado = strtok(NULL, delimitador);
        }




        haveData = false;
    }


}

I’d be concerned about whether your program has a memory leak.

It is unclear where the memory for all those resultados is coming from, and whether it is being reclaimed.

You need to null terminate your string after reading the data on the slave...

        int i = 0;
        while (Wire.available())
        {
            vretorno[i] = Wire.read(); // receive a byte
            i++;
        }
                vretorno[i] = '\0';

I'd be concerned about whether your program has a memory leak.

strtok() does not allocate memory.

After tons of tests I figured out.

When I have a parameter of example(10 characters) it works forever.

But when this length increases and then retracts again it keeps "returning" the old values.

The solution was create a new parameter (comma separated) even empty... not it works fine!

tks all