I am excited to know how Arduino UNO or nano differentiate between program data that is to be burned into its flash when we press Upload Sketch and serial terminal data when we press Send? Is there any special sequence to identify those? How it will be identified by Bootloader?

And I have this understanding can anyone correct if I am wrong or anything you want to add will be helpful:

  1. When we press Upload Sketch then a RST signal is sent.
  2. ATmega controller when it receives RST signal jumps to Bootloader section of flash and waits for a perticular sequence from UART
  3. If it receives then starts to write the data buffered from UART to flash. This process is handled by Bootloader.
  4. If it doesn't receive the sequence waits till timeout and then jumps to flash section and starts to execute from 0x0000
  • 4
    That pretty much sums up the sequence, yes.
    – Majenko
    Sep 25 '20 at 20:10

Unlike out kids it does what it is told, not what we thought we told it to do. Different instructions do different things. Serial.print("Hi"); is stored in RAM will print from Ram, however if you Serial.print(F("Hi"); it will print from flash. The "F" macro tells it where to print from. The Serial.print("Hi"); is stored in flash but moved to RAM and stored there while your program is started and is running whether you print it or not. The "F" macro keeps it in flash not using RAM. Everything that happens when it starts either in your code or the boot loader is code that has been programed and stored in the flash. The Boot loader decodes the code data stream when uploading and stores it in the specified location. It does not know what it is it just reads it and stores it. I do not know what it is called here but there use to be a program module called "CSTART" that upon reset got control; initialized all the memory and set up the variables before turning control over to the user program. Arduino does the same thing, data has to be placed in the right place before starting.

  • 1
    Did you read the question? Sep 29 '20 at 7:31
  • Hi Gil. Thanks for long answer explaining all the stuff but it's not answer to my question. You started a different topic or answered wrong post. My question is not related to RAM and Flash. Arduino uses avrdude to write to Flash right? I want to know the byte sequence or the exchange of data that happens while programming Arduino Hardware. And how Flash data and Serial data are differentiated.
    – Next-93
    Oct 3 '20 at 12:31
  • You can find that in the boot loader source code. Try this link to get started: electronicwings.com/arduino/…
    – Gil
    Oct 4 '20 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.