Git Product home page Git Product logo

Comments (8)

nickgammon avatar nickgammon commented on June 2, 2024

I'm not sure I understand the question. There is no fuse that specifies what speed the processor is running at.

However there is a function in the code writeFuse which can be used to program a fuse.

from arduino_sketches.

kapil-iitk avatar kapil-iitk commented on June 2, 2024

Thank you for your reply, and sorry for the confusion. I am using a microcontroller having factory installed fuse. I wanted to program the microcontroller along with fuse. I was thinking about this function (writeFuse) as it was there. However, I am not sure how to use it and where to use it to change the fuse setting. Can you please share this? I would appreciate it if you could share or indicate which line and where they have to be placed if I have to write fuse bit to the microcontroller. (major confusion is with the program is the presence of two functions i.e. writeFuse and updateFuses. Also how to pass the value to particular low and high fuse byte.)

Thank you.

Regards

from arduino_sketches.

nickgammon avatar nickgammon commented on June 2, 2024

Which fuse are you planning to change, and what value are you planning to write to it?

updateFuses calculates where the bootloader starts and sets the correct fuse to the correct value so that it boots correctly.

updateFuses calls writeFuse.

from arduino_sketches.

kapil-iitk avatar kapil-iitk commented on June 2, 2024

Dear,

Thank you for your reply regarding updateFuses. For the new atmega8 microcontroller fuse setting is HFuse 0xD9 LFuse 0xE1 (This we have operating at internal 1 MHz). After uploading the program to the microcontroller, I wanted to change the default fuse setting to HFuse 0xD9 and LFuse 0xEF (so I could use an external crystal 12 MHz).

Based on my understanding, in code (https://github.com/nickgammon/arduino_sketches/blob/master/Atmega_Hex_Uploader_Fixed_Filename/Atmega_Hex_Uploader_Fixed_Filename.ino) after "bool ok = writeFlashContents ();" (Line no. 1470), I have to include the following lines,

writeFuse (fuses [highFuse], 0xD9);
writeFuse (fuses [lowFuse], 0xEF);

Is this correct?

from arduino_sketches.

nickgammon avatar nickgammon commented on June 2, 2024

No. If you look at the declaration for writeFuse you will see:

void writeFuse (const byte newValue, const byte instruction)

Clearly the new value (the thing you want to write) is the first argument, not the second one.

And, the instructions are declared here:

// which program instruction writes which fuse
const byte fuseCommands [4] = { writeLowFuseByte, writeHighFuseByte, writeExtendedFuseByte, writeLockByte };

So your code would look like this:

writeFuse (0xD9, writeHighFuseByte);
writeFuse (0xEF, writeLowFuseByte);

I also would not do it where you suggested, that function might return if you had not selected a file, and then you are still writing the fuses. I suggest at line 1370, change:

  // now fix up fuses so we can boot    
  if (errors == 0)
    updateFuses (true);

to:

  // now fix up fuses so we can boot    
  if (errors == 0)
    {
    // updateFuses (true);  // OMITTED BECAUSE OF TWO LINES BELOW
    writeFuse (0xD9, writeHighFuseByte);
    writeFuse (0xEF, writeLowFuseByte);
    }

from arduino_sketches.

kapil-iitk avatar kapil-iitk commented on June 2, 2024

Thank you very much for your response and help. I will test it with some modifications.

from arduino_sketches.

kapil-iitk avatar kapil-iitk commented on June 2, 2024

Dear Nick,

Thank you for your support. While exploring your code, I thought that by slight modification, your program could do it for all kinds of (AVR!) microcontrollers (writing fuse bit). I modified the code and included two (generic functions). Can you please comment on the flowing modifications,

The following functions are included after line no. 1253 in original code.

 // Function for string (from the text file placed inside SD card) to hex
byte StrToHex(char str[])
{
  return (byte) (str <= '9') ? str - '0' : str - '7';
}

// Function to check if file exist
boolean fileExists(const char* name) {
  return sd.exists(name);
}


// within void setup ()  after line number 1370 of the original code
 if (errors == 0)
    {
      if(fileExists(fileName_fuse)){

        // Modified for kapil
        // fileName_fuse is a file named "fuse.txt"
        // contain single line "DEFF0500"
        // HFuseLFuseEFuesLock
       
        File NewFile;
        String read_line;
        char hexValue[10];
        byte Fuse_Byte_file[4];
        int pp=0;
   
        NewFile = sd.open(fileName_fuse);
        if (NewFile){
          while(NewFile.available()){
          read_line = NewFile.readStringUntil('\n');
          break;
          }
        }
        NewFile.close();      
        read_line.toCharArray(hexValue,10);
       
        for(int f_line=0; f_line<4; f_line++){
          Fuse_Byte_file[f_line] = (16 * StrToHex(hexValue[pp])) + StrToHex(hexValue[pp+1]);
          //Serial.println(Fuse_Byte_file[f_line], HEX);
          //Serial.println("\n"); // it displays perfectly
          pp=pp+2;
        }      
        // For USBASP following fusebit are used for atmega8    HFUSE=0xc9  LFUSE=0xef
        //ATmega8 HFUSE=0xD9  LFUSE=0xE1  Factory Default Settings for ATmega8.
        //H fuse: Reset Disabled  : Unprogrammed (Reset pin is enabled)
        //Watchdog        : Off
        //SPI Programming : Enabled
        //CKOPT           : Unprogrammed
        //EEPROM Preserve : Unprogrammed (EEPROM not preserved)
        //BOOT size       : 1024 words
        //Reset Vector    : User flash code
        //L fuse: Brown-out level : 2.7V
        //Brown-out detect: Disabled
        //Startup timing  : Default
        //Clock Source    : Internal, 1MHz
        //ATmega8 HFUSE=0xD9  LFUSE=0xEF ; External Crystal upto 16MHz. Rest of the options : Default.
        writeFuse (Fuse_Byte_file[0], writeHighFuseByte); // For arduino Uno HFUSE: 0XDE
        writeFuse (Fuse_Byte_file[1], writeLowFuseByte); // For arduino Uno LFUSE: 0xFF
        writeFuse (Fuse_Byte_file[2], writeExtendedFuseByte); // For arduino Uno EFUSE: 0x05
        //writeFuse (Fuse_Byte_file[3], writeLockByte); //Caution!! use carefully
      }
      else
        updateFuses (true);
    }

Can you please comment on this modification (else I have to make AVR fuse doctor as well :-) ) before I actually implement it.

from arduino_sketches.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.