Fail to write to Flash memory

Hi at all! I'm using Arduino Uno with Optiboot, and a BLE (Bluetooth Low Energy) HM-10 module.
I'm using this guide:
http://baldwisdom.com/bootloading/

I can talk with the bootloader, and communication happens, but during the uploading, the normal program starts. Why doesn't the bootloader wait for finishing?

Why? Am I missing something?
Plz ti'z important xdxd!!11

Hi Be...

Can you provide any additional details on your setup and what you mean when you say "communication happens?" I'm not an Optiboot guy, but I'm sure you'll need to provide more info so one of the experts here can help.

Hi patduino!
I can receive the 0x14 and 0x10 bytes everytime I send something to the arduino, but due to the BLE limitations, I can only send 20 bytes each time.

So this is basically what I do:

  1. I start from address 0
  2. I pick the higher and lower part of the address, then increment by 4
  3. I make a byte array like this: [ STK_LOAD_ADDRESS, lower_part, higher_part, SYNC_CRC_EOP ]
  4. I send to the arduino and wait for response
  5. If response if [ 0x14 , … , 0x10 ] I send the hex file
  6. Sending the hex file like this:

size = binaryFile.length - programIndex < 8 ? binaryFile.length - programIndex : 8;

sync = new byte[size + 5];

sync[0] = STK_PROGRAM_PAGE;
sync[1] = 0x00;
sync[2] = (byte) size;
sync[3] = STK_FLASH_MEMORY;

for (int i = 4; i < sync.length - 1; i++)
sync = binaryFile[programIndex++];
sync[sync.length - 1] = SYNC_CRC_EOP;
7) I iterate 5 and 6 until the binaryFile has reached the end.
8) I leave programming mode, and receive the [ 0x14 , … , 0x10 ]
But sketch bytes are not correct on the arduino. It doesn’t print anything.
What am I doing wrong?
This guy:
http://baldwisdom.com/bootloading/
makes a max page size of 128, and increment the address by 64. I basically changed the max page size to 8 and the increment of 4, to match the BLE max size (20 bytes).
Can this be the problem? But I don’t think so…
Can you help me???
Thanks in advance!!

Anyone???’