How to Download Program to MCU

Discussion in 'Embedded Systems and Microcontrollers' started by sailmike, Feb 18, 2015.

  1. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    I'm building a controller for a toaster oven for reflow soldering following the directions at this site: http://www.instructables.com/id/Hack-a-Toaster-Oven-for-Reflow-Soldering/#step0
    Since, I'm hearing impaired, I don't know what was said in the video on how to download the required software to the MCU. I have an Arduino UNO and cable I can use for downloading the software. Also, I downloaded and installed Atmel's AVR Studio. The writer of that Instructable provided a link to some tutorials. I downloaded the bootloader and other software that the writer included with that Instructable. I'm not sure what to do now. Do I need to download the bootloader first, then the control software? What are the steps?

    The hardware is all done and just waiting for the software.

    Thanks a lot,
    Mike
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,367
    You have to learn the difference between an Atmel ATmega328 and an Arduino Uno.

    Arduino is a platform that uses the Atmel ATmega328 chip (MCU). In order to run Arduino software the MCU is preprogrammed with a bootloader that allows you to download the Arduino code via the USB cable.

    You cannot use the USB cable and the Arduino board to program the MCU with its own code. To do that you need a programmer that is compatible with AVR Studio. You cannot use the Arduino bootloader to do this. The MCU has its own bootloader already on the chip that uses the SPI pins. You need a programmer that interfaces to the SPI pins.
     
  3. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    One of the tutorials provided in that Instructable said I could use the Arduino UNO as a programmer. I just had to download "ArduinoISP.pde" to the UNO, but the software for the oven controller included a bootloader. I wonder if that bootloader is specific to the software included for the oven controller? You can see in the photo that the oven controller includes the 6 pin connector and I have the cable for this. Oven Controller.JPG Oven Controller.JPG
     
  4. Robartes

    Member

    Oct 1, 2014
    57
    13
    That six pin header is the ICSP header - In Circuit Serial Programming. You can use an AVR programmer (there are many types) to program the AVR MCU on the oven controller, without that AVR needing a boot loader.

    Now, one of the programmers you can use to program the AVR through ICSP is an Arduino running the ArduinoISP code. That code programs the Arduino to act as an ICSP AVR programmer. You just connect some output pins of the Arduino to the ICSP header (the ArduinoISP documentation should tell you which), and you can program the oven controller's MCU through the Arduino.

    And finally, to muddy the waters even more, I see that the oven controller board has a USB connector. That could mean that the MCU on the oven controller has its own boot loader which can download code through the USB connector. If that is the case, you do not need an Arduino to act as ICSP programmer, but -- if the boot loader in question is the Arduino one -- you can use the Arduino IDE directly.

    So - many possibilities. The docs of the oven controller should be able to tell you which of the above apply (quite possibly all of them).
     
  5. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    The instructable mentioned a bootloader so I'm guessing I need to download that first. Alright, I've got "ArduinoISP.pde" downloaded to the Arduino UNO. Do I need to plug in the oven controller before downloading anything? What is the next step?

    Is there a way to see if there's a bootloader already on the MCU? Does there have to be a specific kind of bootloader for this control software to work correctly?
     
  6. Robartes

    Member

    Oct 1, 2014
    57
    13
    The boot loader used in the project is the LUFA boot loader. The first step would indeed be to download this boot loader onto the AVR (the second step is to download the code itself through the USB).

    However, before doing that, you could check whether the boot loader is already present using the following trick: connect the USB port of the oven controller to your computer, then power on the oven controller while holding the 'HWB' button. If the LUFA boot loader is already on the chip, the board should now show up as an USB device on your computer.

    That said, I don't really see a need for the boot loader in the project, apart from downloading the code through USB instead of ISP. As far as I can see (and take this with a grain of sand), you could download the application code directly (using ISP), so that's another option to try.
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,395
    1,607
    While you may never need the bootloader to load code you may still need it.

    I never used this family of micros but on others I have used the bootloader needs to be there asit is the first code to run and it's typical function is to just jump to the application code. Without that code filling the start vector address the main application code may never get to run.

    Hey, it's worth a try but if you load the code and get a brick try loading the bootloader and then let the bootloader load the app code (once).
     
  8. Robartes

    Member

    Oct 1, 2014
    57
    13
    As usual with these things, the answer is 'it depends' :). In this case, it depends on the setting of the 'Boot Reset Vector' fuse. By default, it is unset and the AVR starts executing application code. If the 'Boot Reset Vector' is set, the AVR jumps to the boot loader section at startup instead.

    Edit: corrected a mistake - I had the boot mechanism wrong
     
    Last edited: Feb 20, 2015
  9. sirch2

    Well-Known Member

    Jan 21, 2013
    1,008
    351
    As the Instructable indicates, you CAN use your Arduino Uno as a programmer and you do not need a boot loader on the target chip! As you seem to have done you load the ArduinoISP sketch to your Uno and then connect up the Uno to the 6 pin header - see http://arduino.cc/en/Tutorial/ArduinoISP You need the pin-out for that header, you then load whatever sketch you need to write to the circuit board, tell the IDE you are using the ArduinoISP and load the code.
     
  10. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    It looks like I need to enter information about the target MCU, but I don't know how to do that because I don't know what the author of the Instructable is saying in his video. Also it looks like he mentions something about the fuse, so I probably need to upload the bootloader first.
     
  11. Robartes

    Member

    Oct 1, 2014
    57
    13
    OK - let's take this one step at a time. Where did you get the board & the microcontroller on it? Is the microcontroller a stock one or did you get it from the Instructable author? This will help us determine what the chances are the microcontroller already has a boot loader on it.
     
  12. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    I had the board made from a PCB maker. The Instructable author provided the Eagle files for the PCB. The MCU came from companies like Mouser and Digikey.
     
  13. Robartes

    Member

    Oct 1, 2014
    57
    13
    OK - so it's a stock MCU. We now need to program it, either with the boot loader + application, or with just the application. Do you have only the Arduino running ArduinoISP or do you have another programmer as well? And, if it's just the Arduino, which Arduino board is it?
     
  14. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    I have the Arduino UNO.
     
  15. Robartes

    Member

    Oct 1, 2014
    57
    13
    So just the Arduino, then. Then you're out of luck I'm afraid. The oven controller runs at 3.3V, the Uno at 5V. You will need to invest in either a logic level shifter, or a dedicated AVR programmer that can program 3.3V boards. I use a cheap USBasp version (example here) which you can switch between 5V and 3.3V with a jumper, but there are many options available.
     
  16. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    The Atmega32u4 can operate between 2.7V and 5.5V.. The 5V is supplied by an Apple power supply. Also, I'm supposed to plug in a micro USB B to the oven controller. The Arduino UNO has a socket for 3.3V and 5V.
     
  17. Robartes

    Member

    Oct 1, 2014
    57
    13
    Correct, but the one on the oven controller board is operated at 3.3V. If you were to program it with the Arduino, even if you don't power the Atmega from the ICSP header, you would still have 5V signals showing up on the RESET', MOSI and SCK lines. The ATMega32 datasheet states that the maximum voltage on any pin except RESET is Vcc + 0.5V. On top of that, the Arduino would see a voltage high of 3.3V on the MISO line which for CMOS does not translate to logic high.

    If you look closely at the board and schematic, you will see that there is an LM1117 voltage regulator (IC1) that regulates this 5V down to 3.3V. The only place 5V is used is on the USB interface pins of the ATmega32u.

    The 3.3V on the Uno is there as a sort of bonus to power 3.3V circuits. The output pins of the Arduino, which would be connected to the programming pins of your target microcontroller as noted above, are still at 5V.
     
  18. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    Ah yes I see that all the VCC pins are connected to 3.3V. Pin 2 of the ICSP header is also connected 3.3V. There is 3.3V across a 10k resistor to the RESET pin on the MCU. In the Instructable he shows both the ICSP header and micro USB used for programming. Why? Can't the Arduino UNO be programmed to send signals at 3.3V?
     
    Last edited: Feb 21, 2015
  19. Robartes

    Member

    Oct 1, 2014
    57
    13
    The Instructables author uses a USBTinyISP to do the boot loader programming, which can be (and is) be switched to 3.3V. The bit where he shows a close up of the programmer and hovers around the jumper pins is where he mentions that the programmer is set to 3.3V. Later on, when the boot loader is on the MCU, he programs the actual application firmware through the USB.

    You can probably get the Uno to output 3.3V signals, but it's going to be way more trouble than just getting a 3.3V capable programmer, and you would still have the issue that the return signal (MISO) from the microcontroller is in the 'twilight zone' of CMOS logic levels.
     
  20. sailmike

    Thread Starter Member

    Nov 11, 2013
    143
    3
    Alright, getting the USBTinyISP. I may get a dedicated programmer sometime down the road, but the USBTinyISP will do for now. Thanks for your help Robartes.
     
Loading...