Hardware Reference
In-Depth Information
THE ARDUINO BOOTLOADER AND FIRMWARE SETUP
A bootloader isachunkofcodethatlivesinareservedspaceintheprogram
memoryoftheArduino'smainMCU.Ingeneral,AVRmicrocontrollersare
programmedwithanICSP,whichtalkstothemicrocontrollerviaaserial
peripheralinterface(SPI).Programmingviathismethodisfairlystraight-
forward,butnecessitatestheuserhavingahardwareprogrammersuchas
anSTK500oranAVRISPMKIIprogrammer(seeFigure1-2).
WhenyouirstboottheArduinoboard,itentersthebootloader,which
runsforafewseconds.Ifitreceivesaprogrammingcommandfromthe
IDEovertheMCU'sUART(serialinterface)inthattimeperiod,itloadsthe
programthatyouaresendingitintotherestoftheMCU'sprogrammemory.
Ifitdoesnotreceiveaprogrammingcommand,itstartsrunningyourmost
recentlyuploadedsketch,whichresidesintherestoftheprogrammemory.
Whenyousendan“upload”commandfromtheArduinoIDE,itinstructs
theUSB-to-serialchip(anATMega16U2or8U2inthecaseoftheArduino
Uno)toresetthemainMCU,henceforcingitintothebootloader.Then,your
computerimmediatelybeginstosendtheprogramcontents,whichtheMCU
isreadytoreceiveoveritsUARTconnection(facilitatedbytheUSB-to-serial
converter).
BootloadersaregreatbecausetheyenablesimpleprogrammingviaUSB
withnoexternalhardware.However,theydohavetwodownsides:
■ First,theytakeupvaluableprogramspace.Ifyouhavewrittenacom-
plicatedsketch,theapproximately2KBofspacetakenupbytheboot-
loadermightbereallyvaluable.
■ Second,usingabootloadermeansthatyourprogramwillalwaysbe
delayedbyafewsecondsatbootasthebootloaderchecksforapro-
grammingrequest.
Ifyouhaveaprogrammer(oranotherArduinothatcanbeprogrammedto
actasaprogrammer),youcanremovethebootloaderfromyourATMegaand
programitdirectlybyconnectingyourprogrammertotheICSPheaderand
usingtheFile d UploadUsingProgrammercommandfromwithintheIDE.
ArduinoBoards
This topic cannot possibly cover all the available Arduino boards; there are many,
and manufacturers are constantly releasing new ones with various features. The
following section highlights some of the features in the official Arduino boards.
The Uno (see Figure 1-3) is the flagship Arduino and will be used heavily
in this topic. It uses a 16U2 USB-to-serial converter chip and an ATMega 328p
as the main MCU. It is available in both DIP and SMD versions (which defines
whether the MCU is removable).
 
Search WWH ::




Custom Search