Do U Ever wonder How the Arduino Chip [atmel ATmega 328P] is programmed in factory to do all this magical stuff. I got the same doubt and started to digging the Net for it..
In process I came Across ICSP
ICSP is Acronym for In Circuit Serial Programming
As The Name Indicates We can Program Micro controller when the Circuit assembly is completed(In circuit)
from Wikipedia
In Circuit Serial Programming (ICSP) is a method directly programming AvR's and PIC controllers
ICSP is a way that allows us to program the chips when they are in circuits
In arduino It helps in arduino chip Directly with AVR Instructions Without need to arduino IDE. In general Avr Micro controller are programmed with an ICSP, which talks to the micro controller via Serial Peripheral Interface (SPI... Which is an another Long topic we can talk about this in another Post)
In General, ATMega microcontrollers are written in C or assembly Language and programmed via the ICSP interface using another Hardware to upload the Code
So what makes us possible In arduino to upload the code by simply plugging USB cable to our arduino?
that credit goes to the small chunk of program taking a 2k memory in our ATMega Chip which is loaded in factory Named boot loader
Boot Loader allows a Serial USART (Universal Synchronous/ Asynchronous Receiver/Transmitter) to load the arduino Program to the Arduino Without using a separate programmer
In Arduino Uno a secondary Micro controller serves as an interface between a USB cable and serial USART pins on Main Controller[ATMega 368p]
Nick gammon write everything in a one post about Arduino UNO PINOUT checkout here
Boot Loader is basically a HEX file that runs when you power on or reset the board
It is very similar to BIOS that runs on your PC
BIOS : [Basic Input / Ouput System] the bios software is built in PC and it is first software run by PC when you power ON.
the fundamental purpose of BIOS is to Initialize and test the system hardware components and to load the OS from a mass memory device
The BOOT LOADER does two things :
first, it looks around to see if computer is trying to program it. If it is, then It grabs the program From PC and upload it into IC's Memory in specific location so it is not overwrite the boot loader
secondly if computer isn't trying to upload the code, it tells the chip to run the code that's already stored in memory.
Once it locates and runs the program the arduino loops through the program and does as long as board power has power.
after reading all this you may get this small doubt:
Ok.. Boot loader is a chunk of code that runs initially when board power On or Reset to check whether computer is trying to upload the code... But we are not restart / reset the arduino each and every time we try to upload the code...
so how's arduino is doing this
the answer is when you try to upload the code you need to send the UPLOAD command from Arduino IDE, The command instructs USB to Serial chip to reset the Main MCU, hence forcing it into boot loader, then computer immediately begins to send the program contents, which MCU is ready to Receive it Over UART connection.
No comments:
Post a Comment