I would like to recover the result of my serial2 link. It's a char by char and concatenate them. I use pointers, my code works once when I don't free memory with free() function. When I want to free the memory after use I have directly one problem problems.
I put two pictures one with free, one without.
thank you
Code: Select all
void Wisol::getID()
{
printf("getID");
char * data=(char *) malloc(15);
char * data1=(char *) malloc(15);
char receive;
*(data)='\0';
//*(data1)='0';
//*(data1+1)='\0';
Serial2.begin(9600, SERIAL_8N1, RXPin, TXPin);
Serial2.println("AT$I=10");
delay(1000);
while (Serial2.available()) {
//Serial.println(char(Serial2.read()));
delay(100);
receive= Serial2.read();
*(data1)=receive;
printf("data1: %s \n",data1);
printf("receive: %c \n",receive);
data=strcat( data, data1 );
printf("data: %s \n",data);
}
//free(data);
// free(data1);
}