{"id":10144,"date":"2013-06-14T11:37:17","date_gmt":"2013-06-14T15:37:17","guid":{"rendered":"http:\/\/engineersgarag-main\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/"},"modified":"2023-05-24T12:01:49","modified_gmt":"2023-05-24T16:01:49","slug":"how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46","status":"publish","type":"post","link":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/","title":{"rendered":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The AVR flash memory is divided into two sections namely the application section and the Boot-Loader section (BLS). In case of the ATMEGA16 it has 16 KB of flash memory of which the 15KB is application section and the remaining 1KB is BLS. The memory architecture of the ATMEGA16 is shown in the following figure;<\/span><\/span><\/span><\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><img decoding=\"async\" alt=\"Flash Memory Architecture of ATMEGA16\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Flash-Memory-Architecture-of-ATMEGA16.jpg\" style=\"margin-left: auto;margin-right: auto\" title=\"Flash Memory Architecture of ATMEGA16\"><\/span><\/span><\/p>\n<p style=\"text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em>Fig. 2:&nbsp;Flash Memory Architecture of ATMEGA16<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The code for both the BLS and application section can be written as normally does and there is no much difference. The only thing to be careful about is the size of the code binary. It should not be more than 1KB, otherwise it won\u2019t be able to code programmed into the BLS. The <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">project<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">&nbsp;on AVR BLS coding discusses how to program a simple code into the BLS of ATMEGA16 microcontroller with the help of AVR studio as IDE, USBasp as the programmer and AVR-Burnomat as the burner software.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">In this particular project the Boot-Loader is coded to perform <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><a href=\"https:\/\/www.engineersgarage.com\/embedded\/avr-microcontroller-projects\/serial-communication-atmega16-usart\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">UART<\/span><\/span><\/a><span style=\"font-size: small\"><span style=\"font-family: Arial\"> initialization along with a simple <\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">LED<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\"> pin initialization and also an external hardware initialization of the 4 bit <\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">LCD<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">. Hence the application codes does not require those codes in them, still they works because before executing the application codes the initialization functions will be executed by the Boot-Loader.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The BLS code has the initialization functions which should not be there in the application codes. The initialization functions used in the Boot-Loader code for this project are given below;<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<div align=\"center\">\n<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"MsoTableGrid\" style=\"border-style: none\">\n<tbody>\n<tr>\n<td style=\"width: 113.4pt;border: 1pt solid windowtext;padding: 0in 5.4pt\" valign=\"top\" width=\"151\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">Function<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 365.4pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"487\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">Description<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 113.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"151\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">void lcd_init ( void )<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 365.4pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"487\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Initialize the LCD in 4 bit mode<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 113.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"151\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">void usart_init ( void )<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 365.4pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"487\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Initialize the usart in 9600 baud rate with transmission and reception enabled<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 113.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"151\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">DDRD |= 0x80; <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 365.4pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"487\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Initialization of the LED pin as output<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><em style=\"font-family: verdana, geneva, sans-serif;font-size: 12px\">Fig.3 :Initialization functions used Boot-Loader code of AVR<\/em><\/p>\n<\/div>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Any application code can directly use the following function calls to access the USART, LCD and LED without their initializing functions anywhere in their code.<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<div align=\"center\">\n<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"MsoTableGrid\" style=\"border-style: none\">\n<tbody>\n<tr>\n<td style=\"width: 131.4pt;border: 1pt solid windowtext;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">Function<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">Description<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 131.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">lcd_clear ()<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Clear the LCD<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 131.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">lcd_string ()<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Display a string in the LCD<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 131.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">usart_send_string ()<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Send a string via usart<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 131.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">PORTD &amp;= 0x7F;<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Turn ON the LED<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 131.4pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"175\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">PORTD |= 0x80;<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 134.55pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"179\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Turn OFF the LED<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em>&nbsp;Fig. 4:&nbsp;Function calls used by application code to access peripherals in AVR<\/em><\/span><\/span><\/p>\n<\/div>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The hardware initialization before executing the application code is explained in detail in a <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">project<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span class=\"MsoCommentReference\"><span style=\"line-height: 200%\">&nbsp;<\/span><\/span>on Initializing hardware from AVR BLS.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The major function of the Boot-Loader is load a code binary form storage medium or which can be received through the external communication with other devices to the flash memory. The SPM feature available for the code executing from the BLS helps in loading an application code binary to the flash memory. The task of writing the BLS code with SPM has been made simple by the APIs available in the header file &lt;avr\/boot.h&gt;. The following are the important APIs available in the header file which helps in the SPM.<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"MsoTableGrid\" style=\"width: 6.7in;border-style: none\" width=\"643\">\n<tbody>\n<tr>\n<td style=\"width: 180.9pt;border: 1pt solid windowtext;padding: 0in 5.4pt\" valign=\"top\" width=\"241\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">FUNCTION<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 184.5pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"246\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">DESCRIPTION<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 117pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"156\">\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">PARAMETER<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 180.9pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"241\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">boot_page_erase (address)<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 184.5pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"246\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Erase the flash page that is referred by address<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 117pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"156\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">A byte address in flash<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 180.9pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"241\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">boot_page_fill &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (address, data) &nbsp;&nbsp; <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 184.5pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"246\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Fill the Boot-Loader temporary page buffer for flash address with data word<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 117pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"156\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The address is a byte address. The data is a word<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 180.9pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"241\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">boot_page_write (address)<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 184.5pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"246\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Write the Boot-Loader temporary page buffer to flash page that contains address<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 117pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"156\">\n<p class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:  200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Byte address in flash<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em><span style=\"line-height: 200%\">Fig. 5:&nbsp;<\/span>Important APIs in AVR&nbsp;<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The steps required to do the SPM on the application flash memory is explained in a <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">project<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">&nbsp;on using SPM in AVR flash to flash programming.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">In this particular project the Boot-Loader is coded in such a way that it will try to load any application code binary which has been loaded into the built-in internal EEPROM of the AVR microcontroller. The APIs available in the &lt;avr\/eeprom.h&gt; is used to read the data bytes from the EEPROM and with the help of APIs from the &lt;avr\/boot.h&gt; the data bytes are stored into a temporary buffer and then flashed into the application section of the flash memory.<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The API provided by the &lt;avr\/eeprom.h&gt; to read the data bytes from the built-in EEPROM of the AVR microcontroller is;<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p align=\"center\" class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><i><span style=\"line-height: 200%\">uint8_t eeprom_read_byte (const uint8_t *p)<\/span><\/i><\/b><\/span><\/span><b><i><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/i><\/b><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">&nbsp;<\/span><\/span><\/span><\/p>\n<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" class=\"MsoTableGrid\" style=\"border-style: none\">\n<tbody>\n<tr>\n<td style=\"width: 126.9pt;border: 1pt solid windowtext;padding: 0in 5.4pt\" valign=\"top\" width=\"169\">\n<p align=\"center\" class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">FUNCTION<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:  200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 192.3pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"256\">\n<p align=\"center\" class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">DESCRIPTION<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:  200%\"><\/span><\/b><\/p>\n<\/td>\n<td style=\"width: 159.6pt;border-style: solid solid solid none;border-top-color: windowtext;border-right-color: windowtext;border-bottom-color: windowtext;border-top-width: 1pt;border-right-width: 1pt;border-bottom-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"213\">\n<p align=\"center\" class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><span style=\"line-height: 200%\">PARAMETER<\/span><\/b><\/span><\/span><b><span style=\"font-size:12.0pt;line-height:  200%\"><\/span><\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 126.9pt;border-style: none solid solid;border-right-color: windowtext;border-bottom-color: windowtext;border-left-color: windowtext;border-right-width: 1pt;border-bottom-width: 1pt;border-left-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"169\">\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">uint8_t eeprom_read_byte (const uint8_t *p)<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 192.3pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"256\">\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The function returns one data byte which is stored in the EEPROM address referred by the pointer p<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<td style=\"width: 159.6pt;border-style: none solid solid none;border-bottom-color: windowtext;border-bottom-width: 1pt;border-right-color: windowtext;border-right-width: 1pt;padding: 0in 5.4pt\" valign=\"top\" width=\"213\">\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom:0in;margin-bottom:.0001pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">The pointer refers to the EEPROM address from which the data byte need to be read<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em><span style=\"line-height: 200%\">Fig. 6:&nbsp;<\/span>API &lt;avr\/eeprom.h&gt; to read data bytes from in-built EEPROM of AVR microcontroller&nbsp;<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">With the help of the above discussed APIs from both &lt;avr\/boot.h&gt; and &lt;avr\/eeprom.h&gt; one can use the SPM feature of the AVR microcontroller to write a Boot-Loader code which can load an application which has been programmed into the built-in EEPROM of the AVR microcontroller. For that one should follow the steps mentioned below which are explained in a <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">project<\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\">&nbsp;on using SPM in AVR EEPROM to flash programming.<\/span><\/span><\/span><\/p>\n<p class=\"MsoListParagraphCxSpFirst\" style=\"margin-bottom: 0.0001pt;text-indent: -0.25in;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[if !supportLists]--><span style=\"line-height: 200%\">\u00b7<span style=\"line-height: normal\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span>{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[endif]--><span style=\"line-height: 200%\">Step: 1 Erase the flash page which is about to write into<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p class=\"MsoListParagraphCxSpMiddle\" style=\"margin-bottom: 0.0001pt;text-indent: -0.25in;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[if !supportLists]--><span style=\"line-height: 200%\">\u00b7<span style=\"line-height: normal\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span>{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[endif]--><span style=\"line-height: 200%\">Step: 2 Store the code binary which are read from the EEPROM into a temporary buffer before write into a flash page<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p class=\"MsoListParagraphCxSpLast\" style=\"margin-bottom: 0.0001pt;text-indent: -0.25in;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[if !supportLists]--><span style=\"line-height: 200%\">\u00b7<span style=\"line-height: normal\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span>{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}{C}<!--[endif]--><span style=\"line-height: 200%\">Step: 3 Program the filled temporary buffer into the already erased flash page<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">After performing the above three steps the Boot-Loader can then make a jump using the statement <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p align=\"center\" class=\"MsoNormal\" style=\"margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><b><i><span style=\"line-height: 200%\">asm ( &#8220;jmp 0x0000&#8221; );<\/span><\/i><\/b><\/span><\/span><b><i><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/i><\/b><\/p>\n<p class=\"MsoNormal\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">to the application code section and let the newly programmed application to execute.<\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">&nbsp;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">Flash the Boot-Loader code to the BLS first any small sized application code to the EEPROM memory using the steps explained in the previous project on <\/span><\/span><\/span><span style=\"font-size:12.0pt;line-height:200%\"><span style=\"font-size: small\"><span style=\"font-family: Arial\">LED blinking from BLS of AVR<\/span><\/span><\/span><span style=\"font-size: small\"><span style=\"font-family: Arial\"><span style=\"line-height: 200%\">. Once the EEPROM programming has completed and when the controller resets the Boot-Loader will start executing. Once can observe that it is performing the initialization functions and is loading the application from the built-in EEPROM.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><img decoding=\"async\" alt=\"Burning BLS code into BLS of AVR circuit on breadboard\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Burning-BLS-code-into-BLS-of-AVR-circuit-on-breadboard.png\" style=\"margin-left: auto;margin-right: auto\" title=\"Burning BLS code into BLS of AVR circuit on breadboard\"><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em>Fig. 7: Burning BLS code into BLS of AVR circuit on breadboard<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><img decoding=\"async\" alt=\"How To Write a Simple Bootloader For AVR In C language\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/vlcsnap-2013-06-13-15h16m02s48.png\" style=\"margin-left: auto;margin-right: auto\" title=\"\"><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><img decoding=\"async\" alt=\"LCD Display initialized by BLS code in AVR setup on breadboard\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/LCD-Display-initialized-by-BLS-code-in-AVR-setup-on-breadboard.png\" style=\"margin-left: auto;margin-right: auto\" title=\"LCD Display initialized by BLS code in AVR setup on breadboard\"><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em>Fig. 9: LCD Display initialized by BLS code in AVR setup on breadboard<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><img decoding=\"async\" alt=\"How To Write a Simple Bootloader For AVR In C language\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/vlcsnap-2013-06-13-15h15m01s220_0.png\" style=\"margin-left: auto;margin-right: auto\" title=\"\"><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: center\"><span style=\"font-size:12px\"><span style=\"font-family:verdana,geneva,sans-serif\"><em>Fig. 10: USART initialized at 9600 baud rate by BLS of AVR setup on breadboard<\/em><\/span><\/span><\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\">&nbsp;<\/p>\n<p class=\"MsoNormalCxSpMiddle\" style=\"margin-bottom: 0.0001pt;line-height: 200%;text-align: justify\"><img decoding=\"async\" alt=\"How To Write a Simple Bootloader For AVR In C language\" src=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/vlcsnap-2013-06-13-15h12m59s214_0.png\" style=\"margin-left: auto;margin-right: auto\" title=\"\"><\/p>\n<div>\n<div>\n<div class=\"msocomtxt\" id=\"_com_5\"><!--[if !supportAnnotations]--><\/div>\n<p><!--[endif]--><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Boot-Loader is a code which executes when a microcontroller is powered ON or reset. It basically sets an environment for the application code to execute. It is the Boot-Loader  that sets the hardware and loads the application code from any storage medium or received through external communication and let the application to execute. Thus a Boot-Loader has to perform the following basic function :&nbsp;Initialize the controller peripherals,&nbsp;Initialize the devices in the board,&nbsp;Allow an option for the user to select from the available applications to load,&nbsp;Load the selected application,&nbsp;Let the application code to execute.&nbsp;Apart from the above mentioned functions some Boot-Loaders can perform many other functions and there are Boot-Loaders which don\u2019t perform all these functions like provide option to select the required application etc. The Boot-Loader codes in microcontrollers are actually very small and simple compared to the Boot-Loaders in advanced devices like PC. In most of the microcontroller the functionality of a Boot-Loader is limited only to set the initial clock and other settings for the microcontroller, load an application binary from the serial port etc.&nbsp;<\/p>\n","protected":false},"author":3,"featured_media":15858,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[4043,13],"tags":[218,457,1187],"class_list":{"2":"type-post","12":"entry","13":"has-post-thumbnail"},"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.2 (Yoast SEO v25.2) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)\" \/>\n<meta property=\"og:description\" content=\"The Boot-Loader is a code which executes when a microcontroller is powered ON or reset. It basically sets an environment for the application code to execute. It is the Boot-Loader that sets the hardware and loads the application code from any storage medium or received through external communication and let the application to execute. Thus a Boot-Loader has to perform the following basic function :&nbsp;Initialize the controller peripherals,&nbsp;Initialize the devices in the board,&nbsp;Allow an option for the user to select from the available applications to load,&nbsp;Load the selected application,&nbsp;Let the application code to execute.&nbsp;Apart from the above mentioned functions some Boot-Loaders can perform many other functions and there are Boot-Loaders which don\u2019t perform all these functions like provide option to select the required application etc. The Boot-Loader codes in microcontrollers are actually very small and simple compared to the Boot-Loaders in advanced devices like PC. In most of the microcontroller the functionality of a Boot-Loader is limited only to set the initial clock and other settings for the microcontroller, load an application binary from the serial port etc.&nbsp;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\" \/>\n<meta property=\"og:site_name\" content=\"Engineers Garage\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/engineersgarage\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"480\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ashutosh Bhatt\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:site\" content=\"@EngineersGarage\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashutosh Bhatt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\"},\"author\":{\"name\":\"Ashutosh Bhatt\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/4e6dc417fdf33f6ce27c9ce2f9fd08d3\"},\"headline\":\"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)\",\"datePublished\":\"2013-06-14T15:37:17+00:00\",\"dateModified\":\"2023-05-24T16:01:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\"},\"wordCount\":1164,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg\",\"keywords\":[\"avr\",\"bootloader\",\"c language\"],\"articleSection\":[\"AVR\",\"Electronic Projects\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\",\"url\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\",\"name\":\"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)\",\"isPartOf\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg\",\"datePublished\":\"2013-06-14T15:37:17+00:00\",\"dateModified\":\"2023-05-24T16:01:49+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg\",\"width\":640,\"height\":480,\"caption\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.engineersgarage.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.engineersgarage.com\/#website\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"name\":\"Engineers Garage\",\"description\":\"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News\",\"publisher\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.engineersgarage.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.engineersgarage.com\/#organization\",\"name\":\"Engineer's Garage - WTWH Media\",\"url\":\"https:\/\/www.engineersgarage.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"contentUrl\":\"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png\",\"width\":372,\"height\":52,\"caption\":\"Engineer's Garage - WTWH Media\"},\"image\":{\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/engineersgarage\",\"https:\/\/x.com\/EngineersGarage\",\"https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/4e6dc417fdf33f6ce27c9ce2f9fd08d3\",\"name\":\"Ashutosh Bhatt\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/97ae33d7fb6f22daeba201f00355919e158689239cd6f0b5f1d55f00e0851241?s=96&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/97ae33d7fb6f22daeba201f00355919e158689239cd6f0b5f1d55f00e0851241?s=96&r=g\",\"caption\":\"Ashutosh Bhatt\"},\"url\":\"https:\/\/www.engineersgarage.com\/author\/dmiyares\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/","og_locale":"en_US","og_type":"article","og_title":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)","og_description":"The Boot-Loader is a code which executes when a microcontroller is powered ON or reset. It basically sets an environment for the application code to execute. It is the Boot-Loader that sets the hardware and loads the application code from any storage medium or received through external communication and let the application to execute. Thus a Boot-Loader has to perform the following basic function :&nbsp;Initialize the controller peripherals,&nbsp;Initialize the devices in the board,&nbsp;Allow an option for the user to select from the available applications to load,&nbsp;Load the selected application,&nbsp;Let the application code to execute.&nbsp;Apart from the above mentioned functions some Boot-Loaders can perform many other functions and there are Boot-Loaders which don\u2019t perform all these functions like provide option to select the required application etc. The Boot-Loader codes in microcontrollers are actually very small and simple compared to the Boot-Loaders in advanced devices like PC. In most of the microcontroller the functionality of a Boot-Loader is limited only to set the initial clock and other settings for the microcontroller, load an application binary from the serial port etc.&nbsp;","og_url":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/","og_site_name":"Engineers Garage","article_publisher":"https:\/\/www.facebook.com\/engineersgarage","og_image":[{"width":640,"height":480,"url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","type":"image\/jpeg"}],"author":"Ashutosh Bhatt","twitter_card":"summary_large_image","twitter_creator":"@EngineersGarage","twitter_site":"@EngineersGarage","twitter_misc":{"Written by":"Ashutosh Bhatt","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#article","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/"},"author":{"name":"Ashutosh Bhatt","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/4e6dc417fdf33f6ce27c9ce2f9fd08d3"},"headline":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)","datePublished":"2013-06-14T15:37:17+00:00","dateModified":"2023-05-24T16:01:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/"},"wordCount":1164,"commentCount":0,"publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"image":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","keywords":["avr","bootloader","c language"],"articleSection":["AVR","Electronic Projects"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/","url":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/","name":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)","isPartOf":{"@id":"https:\/\/www.engineersgarage.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage"},"image":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage"},"thumbnailUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","datePublished":"2013-06-14T15:37:17+00:00","dateModified":"2023-05-24T16:01:49+00:00","breadcrumb":{"@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#primaryimage","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","width":640,"height":480,"caption":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.engineersgarage.com\/how-to-write-a-simple-bootloader-for-avr-in-c-language-part-35-46\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.engineersgarage.com\/"},{"@type":"ListItem","position":2,"name":"How To Write a Simple Bootloader For AVR In C language- (Part 35\/46)"}]},{"@type":"WebSite","@id":"https:\/\/www.engineersgarage.com\/#website","url":"https:\/\/www.engineersgarage.com\/","name":"Engineers Garage","description":"Electronic Projects, Electrical Engineering Resources, Makers Articles and Product News","publisher":{"@id":"https:\/\/www.engineersgarage.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.engineersgarage.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.engineersgarage.com\/#organization","name":"Engineer's Garage - WTWH Media","url":"https:\/\/www.engineersgarage.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","contentUrl":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/08\/EGlogo.png","width":372,"height":52,"caption":"Engineer's Garage - WTWH Media"},"image":{"@id":"https:\/\/www.engineersgarage.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/engineersgarage","https:\/\/x.com\/EngineersGarage","https:\/\/www.youtube.com\/channel\/UC0VITh11JSYk-UW7toLebUw"]},{"@type":"Person","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/4e6dc417fdf33f6ce27c9ce2f9fd08d3","name":"Ashutosh Bhatt","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.engineersgarage.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/97ae33d7fb6f22daeba201f00355919e158689239cd6f0b5f1d55f00e0851241?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/97ae33d7fb6f22daeba201f00355919e158689239cd6f0b5f1d55f00e0851241?s=96&r=g","caption":"Ashutosh Bhatt"},"url":"https:\/\/www.engineersgarage.com\/author\/dmiyares\/"}]}},"featured_image_src":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","featured_image_src_square":"https:\/\/www.engineersgarage.com\/wp-content\/uploads\/2019\/07\/Wrting-Simple-Boot-Loader-code-for-AVR-microcontroller-in-C-to-Initialize-peripherals-circuit-set-up-on-breadboard.jpg","author_info":{"display_name":"Ashutosh Bhatt","author_link":"https:\/\/www.engineersgarage.com\/author\/dmiyares\/"},"_links":{"self":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/10144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/comments?post=10144"}],"version-history":[{"count":0,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/posts\/10144\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media\/15858"}],"wp:attachment":[{"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/media?parent=10144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/categories?post=10144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.engineersgarage.com\/wp-json\/wp\/v2\/tags?post=10144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}