Sending data from ATmega1284p to PC with LoRa

Hello,
I have set up a system based on an ATmega1284pa, which collects data, and then sends them via LoRa to my PC. The LoRa modules I use are Dorji DRF1276DM.
On the PC side, I have written a C program that handles the com port to receive data from LoRa and store them to a file, using the windows fileapi.h and winbase.h.
I also have created a simple handshaking mechanism (the windows timeouts are not used). When the PC has received ‘nNumberOfBytesToRead’ characters, it sends character ‘A’ back to the ATmega, as an acknowledgement.

The ATmega waits for a certain time to receive the acknowledgement, and if it does not receive it after some time, I try to resend the data package.
Here is the basic functionality on the PC side:

HANDLE hComm;
	hComm = CreateFile( ComPortName,  
	                    GENERIC_READ | GENERIC_WRITE, 
	                    0, 
	                    0, 
	                    OPEN_EXISTING,
	                    0,
	                    0);
	if (hComm == INVALID_HANDLE_VALUE)
	   printf("Error opening port.\n");
	   
	//////////////////////////////////////////////////////   
	DCB dcb;

   	FillMemory(&dcb, sizeof(dcb), 0);
   	if (!GetCommState(hComm, &dcb))     // get current DCB
      printf("Error GetCommState.\n");

   	// Update DCB rate.
   	dcb.BaudRate = CBR_38400 ;
   	dcb.ByteSize = 8;             // Setting ByteSize = 8
	dcb.StopBits = ONESTOPBIT;    // Setting StopBits = 1
	dcb.Parity = NOPARITY;        // Setting Parity = None 
	dcb.DCBlength = sizeof(dcb);
  	 // Set new state.
   	if (!SetCommState(hComm, &dcb))
   		printf("Error SetCommState.\n");
      	// Error in SetCommState. Possibly a problem with the communications 
     	 // port handle or a problem with the DCB structure itself.

	if (!SetupComm(hComm,512,512))
   		printf("Error SetupComm.\n");
	/////////////////////////////////////////////////////////////////////
	COMMTIMEOUTS timeouts;
	
	timeouts.ReadIntervalTimeout = 0; 					//50
	timeouts.ReadTotalTimeoutMultiplier = 0;			//10
	timeouts.ReadTotalTimeoutConstant = 0;				//50
	timeouts.WriteTotalTimeoutMultiplier = 0;
	timeouts.WriteTotalTimeoutConstant = 0;
	
	if (!SetCommTimeouts(hComm, &timeouts))
	   printf("Error timeouts.\n");
	
	
	////////////////////////////////////////
	for ( ; ; ) {
		if(!PurgeComm(hComm,PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT))
	  		printf("Error PurgeComm.\n");
		if (!SetCommMask(hComm, 0))
	   		printf("Error CommMask.\n");
	   	
		if (!SetCommMask(hComm, EV_RXCHAR))
	   		printf("Error CommMask.\n");
	   		
		printf("Waiting for characters.. \n\n");
		printf("Meas Size: %d\n",TOTAL_SIZE);
		printf("Date Size: %d\n",DATE_SIZE);
		
	    if (WaitCommEvent(hComm, &dwCommEvent, NULL)) {
        	if (ReadFile(hComm, SerialBufferPtr, nNumberOfBytesToRead, &dwRead, NULL)){
                    if(!WriteFile(hComm,&reply,sizeof(reply),&dwWrite,NULL))
					printf("Error WriteFile.\n");
                    //do stuff
            }

On the ATmega side, the code is:

uint8_t fram_rd_data[SRAM_BUFFER_SIZE+10];   //FRAM read buffer

Serial.write(fram_rd_data,strlen(fram_rd_data));                            // Send data with LoRa
        unsigned long check1=millis();
        unsigned long check2=check1;
        do{                                                                         // wait for handshake. Poling for 10 seconds
           check2=millis();
        }while(Serial.read()!='A' && check2-check1<12000);
        
        if((check2-check1<12000)){                                                   // This means That the reason for exiting the while loop is because I read 'A'. In that case, I break.
          LoRaFlag=1;
          break;                                                                   // In the other case i.e. 10 seconds passed, I try to resend the fram_data
        }

The above system works like a charm, with data package size of 100 bytes or 200 bytes (i.e. SRAM_BUFFER_SIZE and nNumberOfBytesToRead equal to 200). That is, I successfully send and receive 200bytes of data from ATmega to PC.

When I, however, increase these numbers to 300 or greater, I can no longer receive data on the PC side. To be specific, the C program waits forever on the ‘ReadFile’ command and the ATmega keeps on resending the data package.

Let me also add that I have increased the Serial Buffer Size from the HardwareSerial.h file to be greater than 300.
Any ideas?

Edit: To avoid answering later on, after I compile my sketch, these are the memory information:

  Sketch uses 37832 bytes (29%) of program storage space. Maximum is 130048 bytes.
  Global variables use 3354 bytes (20%) of dynamic memory, leaving 13030 bytes for local variables. Maximum is 16384 bytes.

So I believe there should be more than enough memory for the larger character array. Also, I can print the data successfully, so I do not believe it is a memory issue.

That the module is a LoRa one is probably not relavent, your not actually talking to a LoRa device (which are SPI based) but to the microcontroller on the Doji module which makes the board act like a modem.

I note you said that sending up to 200 bytes works OK, but it fails at 300 or more, so obvious question, and what point between 200bytes and 300bytes does it actually fail ?

Than you for the reply. You are right about the LoRa module. It has a Serial interface.

It took some time to exactly figure out the behaviour of the system, so these are the results:

  • If the size is 207 bytes or less, everything works as expected.
  • If the size is between 208 and 211 included, the first attempt to send a data package usually fails. Re-sending the data works successfully, and after that, every next package I send is usually received successfully with the first try (sometimes, a resend is required).
  • If the size is >= 212 bytes, the data packages are never received.