User Tools

Site Tools


arduino:atmega328p_arduinos_and_custom_fuse_settings

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
arduino:atmega328p_arduinos_and_custom_fuse_settings [2020/01/04 01:06] – [What specs do I want?] mithatarduino:atmega328p_arduinos_and_custom_fuse_settings [2021/04/22 01:13] – [Where do I put new board specs?] mithat
Line 1: Line 1:
 ====== ATmega328P Arduinos and custom fuse settings ====== ====== ATmega328P Arduinos and custom fuse settings ======
- 
-<WRAP center round info 60%> 
-Work in progress. 
-</WRAP> 
  
 Programming your device with the code you want to execute, whether with a bootloader or directly with a programmer, is one layer of programming your device. Another layer is the so-called //fuses// inside an ATmega microcontroller. Programming your device with the code you want to execute, whether with a bootloader or directly with a programmer, is one layer of programming your device. Another layer is the so-called //fuses// inside an ATmega microcontroller.
Line 21: Line 17:
 ===== Four general questions ===== ===== Four general questions =====
  
-==== Where do I put new board specs? ====+==== 1. Where do I put new board specs? ====
  
 Specs for Arduino boards, including fuse bit settings, are found in various ''board.txt'' files, themselves found in various ''hardware'' folders. This can get a little confusing as there are number of these folders and files that you'll find on your computer. I'll try to go through the differences below. Specs for Arduino boards, including fuse bit settings, are found in various ''board.txt'' files, themselves found in various ''hardware'' folders. This can get a little confusing as there are number of these folders and files that you'll find on your computer. I'll try to go through the differences below.
Line 55: Line 51:
  
 So, until I'm advised this is a horrible idea, the way I recommended you add your own custom board descriptions is to create a folder called ''hardware'' in your Arduino sketches folder and add the needed files there. I walk through the details in the case study that follows. So, until I'm advised this is a horrible idea, the way I recommended you add your own custom board descriptions is to create a folder called ''hardware'' in your Arduino sketches folder and add the needed files there. I walk through the details in the case study that follows.
-==== How do I specify new board characteristics? ====+==== 2. How do I specify new board characteristics? ====
  
 There is a //lot// of arcane knowledge that applies to writing custom Arduino ''board.txt'' entries, and I haven't found a source that documents it thoroughly. So my best advice is to study the ''boards.txt'' found at <code>/path-where-you-installed-arduino/hardware/arduino/avr/</code> to get as familiar with the syntax. What interests us here are the entries for ''low_fuses'', ''high_fuses'', and ''extended_fuses'' (and to a certain extent ''unlock_bits'' and ''lock_bits''. There is a //lot// of arcane knowledge that applies to writing custom Arduino ''board.txt'' entries, and I haven't found a source that documents it thoroughly. So my best advice is to study the ''boards.txt'' found at <code>/path-where-you-installed-arduino/hardware/arduino/avr/</code> to get as familiar with the syntax. What interests us here are the entries for ''low_fuses'', ''high_fuses'', and ''extended_fuses'' (and to a certain extent ''unlock_bits'' and ''lock_bits''.
Line 62: Line 58:
  
  
-==== What specs do I want? ====+==== 3. What specs do I want? ====
  
 This article covers making a variant of an existing board where only the fuses have been changed. The relevant parameters in the ''boards.txt'' specs will have ''low_fuses'', ''high_fuses'', and ''extended_fuses'' in their names. The values associated with those parameters are hexadecimal. This article covers making a variant of an existing board where only the fuses have been changed. The relevant parameters in the ''boards.txt'' specs will have ''low_fuses'', ''high_fuses'', and ''extended_fuses'' in their names. The values associated with those parameters are hexadecimal.
Line 72: Line 68:
 There is one additional caveat here: You can only change fuses that are compatible with what the bootloader you plan to use will let you do. Again there isn't a lot of documentation here, so if you've done everything right but things still don't work, this might be the reason. The solution to this is to compile a custom bootloader, which is well beyond the scope of this piece. There is one additional caveat here: You can only change fuses that are compatible with what the bootloader you plan to use will let you do. Again there isn't a lot of documentation here, so if you've done everything right but things still don't work, this might be the reason. The solution to this is to compile a custom bootloader, which is well beyond the scope of this piece.
  
-==== How do I burn a bootloader? ====+==== 4. How do I burn a bootloader? ====
  
 This too is a pretty big topic, but the TL;DR is: hook up a programmer to your board, select the right board and programmer, then do a //Tools > Burn Bootloader//. This [[https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all|Sparkfun tutorial]] is a good reference if you need more hand-holding. This too is a pretty big topic, but the TL;DR is: hook up a programmer to your board, select the right board and programmer, then do a //Tools > Burn Bootloader//. This [[https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader/all|Sparkfun tutorial]] is a good reference if you need more hand-holding.
Line 127: Line 123:
 ===== Case study ===== ===== Case study =====
  
-In the section, I walk through the process of creating a custom version of a 3.3V/8MHz Pro Mini where the brown-out detection (BOD) threshold is changed from the stock nominal 2.7V to 1.8V.+In the section, I walk through the process of creating a custom version of a 3.3V/8MHz Pro Mini where the nominal brown-out detection (BOD) threshold is changed from the stock 2.7V to 1.8V.
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-Don't run programs uploaded by the bootloader at low voltages if you reduce the BOD threshold or turn off BOD entirely. See [[arduino:arduino_without_a_bootloader#cursed_is_the_bootloader|this]] for an explanation why.+If you reduce the BOD threshold or turn off BOD entirely, don't run programs uploaded by the bootloader at low voltages. See [[arduino:arduino_without_a_bootloader#cursed_is_the_bootloader|this]] for an explanation why.
 </WRAP> </WRAP>
  
Line 147: Line 143:
 | 0                  | BODLEVEL0 | | 0                  | BODLEVEL0 |
  
-^ BODLEVEL2, 1, 0  ^ Typ. voltage      ^+^ BODLEVEL2, 1, 0  ^ V<sub>BOT</sub>      ^
 | 111              | BOD disabled      | | 111              | BOD disabled      |
-| 110              | 1.8V              |+| 110              | 1.8V((The ATmega328P datasheet indicates this state is "reserved", but several other sources indicate it sets the V<sub>BOT</sub> to 1.8V, including Microchip's own [[https://microchipdeveloper.com/8avr:bod|Developer Help]].))              |
 | 101              | 2.7V              | | 101              | 2.7V              |
 | 100              | 4.3V              | | 100              | 4.3V              |
Line 157: Line 153:
 Now is a good time to mention that the ATmega328P fuses are //active low//, meaning that a 0 sets ("programs") a bit, and a 1 unsets ("unprograms") it. This can sometimes lead to hilarious misunderstandings, so be careful. Now is a good time to mention that the ATmega328P fuses are //active low//, meaning that a 0 sets ("programs") a bit, and a 1 unsets ("unprograms") it. This can sometimes lead to hilarious misunderstandings, so be careful.
  
-So, to set the brown-out threshold to 1.8V we want the last three bits of the extended fuse byte to be ''b110'' and the entire byte to be ''b11111110'' or ''0xFE''. [[https://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=FF&HIGH=DA&EXTENDED=FE&LOCKBIT=FF|Online fuse calculators]] agree, so it's probably right.+So, to set the brown-out threshold to 1.8V want the last three bits of the extended fuse byte to be ''b110'' and the entire byte to be ''b11111110'' or ''0xFE''. [[https://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p&LOW=FF&HIGH=DA&EXTENDED=FE&LOCKBIT=FF|Online fuse calculators]] agree, so it's probably right.
  
 ==== Preparing the new board files ==== ==== Preparing the new board files ====
  
-=== file structure ===+=== Folder structure ===
  
 Inside my Arduino sketches folder (''/home/<username>/Arduino'' in Debian), I created the following folder structure: Inside my Arduino sketches folder (''/home/<username>/Arduino'' in Debian), I created the following folder structure:
Line 169: Line 165:
 +-- hardware/ +-- hardware/
     +-- mfkcustom/     +-- mfkcustom/
-      +-- avr/ +        +-- avr/ 
-          +-- bootloaders/ +            +-- bootloaders/ 
-            +-- atmega/ +                +-- atmega/ 
-          +-- variants/+            +-- variants/
 </code> </code>
  
Line 228: Line 224:
 ==== Burn the bootloader and test ==== ==== Burn the bootloader and test ====
  
-Whether you plan to upload your sketches with a USB to serial converter (i.e., using the bootloader) or directly by using a programmer, you still need to burn the bootloader to set the fuses. So let's burn and test the bootloader.+Whether you plan to upload your sketches with a USB to serial converter (i.e., using the bootloader) or directly [[arduino:arduino_without_a_bootloader|using a programmer]], you still need to burn the bootloader to set the fuses. So let's burn and test it.
  
 === Burn it === === Burn it ===
Line 234: Line 230:
   * Create a new project consisting of a simple sketch (e.g. blink.)   * Create a new project consisting of a simple sketch (e.g. blink.)
   * Under //Tools > Board// you should see an entry for "Pro Mini 3.3V/8Mhz, 1.8V BOD, ATmega328P". Select it.   * Under //Tools > Board// you should see an entry for "Pro Mini 3.3V/8Mhz, 1.8V BOD, ATmega328P". Select it.
-  * As a sanity check, Verify/Compile the project. No errors are good.+  * As a sanity check, Verify/Compile the project. No errors is good.
   * Hook up a programmer to a 3.3V/8MHz Pro Mini and select the programmer you're using under //Tools >Programmer//.   * Hook up a programmer to a 3.3V/8MHz Pro Mini and select the programmer you're using under //Tools >Programmer//.
   * Plug the programmer into your computer   * Plug the programmer into your computer
Line 252: Line 248:
  
 <WRAP center round important 60%> <WRAP center round important 60%>
-Don't run programs uploaded by the bootloader at low voltages if you reduce the BOD threshold or turn off BOD entirely. See [[arduino:arduino_without_a_bootloader#cursed_is_the_bootloader|this]] for an explanation why.+If you reduce the BOD threshold or turn off BOD entirely, don't run programs uploaded by the bootloader at low voltages. To run a sketch at low voltage you should upload your sketch directly using a programmer. See [[arduino:arduino_without_a_bootloader#cursed_is_the_bootloader|this]] for an explanation why.
 </WRAP> </WRAP>
  
-To run a sketch at low voltage you should upload your sketch directly using a programmer. 
 ==== Upload with programmer and test ==== ==== Upload with programmer and test ====
  
-After burning the bootloader to set the fuses, hook up your programmer. Be sure you have set both the board and programmer to the correct values under //Tools//. Then upload your simple test sketch with //Sketch > Upload Using Programmer//. Your sketch should upload and start running (possibly only after you have disconnected the programmer)(possibly only after you have disconnected the programmer).+After burning the bootloader to set the fuses, [[https://mithatkonar.com/wiki/doku.php/arduino/arduino_without_a_bootloader#case_3pro_mini_33v8mhz_with_usbtinyisp|hook up your programmer]]. Be sure you have set both the board and programmer to the correct values under //Tools//. Then upload your simple test sketch with //Sketch > Upload Using Programmer//. Your sketch should upload and start running (possibly only after you have disconnected the programmer).
  
 Follow the instructions above to read the fuse settings. You should see: Follow the instructions above to read the fuse settings. You should see:
Line 273: Line 268:
 </code> </code>
  
-The extended fuse should still be ''0xFE''.+Confirm that the extended fuse is still ''0xFE''.
  
-You can now connect the Pro Mini to a variable supply to see whether it works as expected below 2.7V. It may not work all the way down to 1.8V though, but because you're not using a bootloader, the chances of corrupting program memory are very low.+You can now connect the Pro Mini to a variable supply to see whether it works as expected below 2.7V. It may not work all the way down to 1.8V though, but because you're not using a bootloader, you won't run the risk of corrupting the program memory.
arduino/atmega328p_arduinos_and_custom_fuse_settings.txt · Last modified: 2021/04/22 01:37 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki