SD card giving error after storing aprrox.6 mins of data.

I am using SanDisk Ultra 16GB micro SD of class 10.

I am trying to read data from 2 serial ports and storing it on to sd card. after some time (less than aprrox. 6 mins or less), the sd cards stops storing data.When I reset my Mega board, it starts storing data. again it stops storing data after some time.

I would like to know what could be the reason. I am using SD library in my program.
The baud rate for both of the serial data is 9600.

commu.ino (3.44 KB)

You're using a lot of String objects which can fragment your heap. Get rid of them and use C strings instead.