3,275 bytes added,
19:20, 23 January 2017 The AVR device programmer requires four connections to the target: RESET, MOSI, MISO, SCK. See [[#20-Pin_Connector]] for details of AVR programming pin connections.
==== Accessing the Programming ====
To access the AVR Programmer, select the "CW-Lite AVR Programmer" from the pull-down Tools menu:
[[File:avrprog_menu.png|image]]
Which should give you the AVR Programmer Window.
==== Clock Source Selection ====
Note to use the AVR programmer you may require a valid clock source for the AVR. It is suggested to select one of the setup scripts (such as <code>ChipWhisperer-Lite: AES Simple-Serial on ATMega328P</code>) which will generate a 7.37 MHz clock.
Check if the device is found by pressing the "Check Signature" button. The status window will show the detected device based on the signature.
[[File:avrprog_sigok.png|image]]
If this fails, double-check connections, and ensure the clock source to the AVR is suitable. Note some errors will appear as part of the main window log:
[[File:avrprog_fail.png|image]]
The default SPI data rate for the programmer is too fast for devices which are running slower than 2 MHz. If programming a device with a clock source slower than 2 MHz, you will need to enable the "Slow Clock Mode". In "Slow Clock Mode" the entire SAM3U and FPGA clock is changed from 96 MHz to 12 MHz. Note the default fuse bytes for a virgin ATMega328P result in a 1 MHz clock, so you will need to use "slow clock mode" to program the correct fuse bytes, after which point you will not need to use "slow clock mode".
<blockquote>'''note'''
The 'slow clock mode' is used to provide a slower SPI clock than would otherwise be possible. When switching into 'slow clock mode' it will cause all DCM blocks in the FPGA to become unlocked. You will need to reset the DCM blocks, or simply restart the CW-Capture software and run the setup script.
</blockquote>
==== Programming the Fuses ====
By default the AVR programmer allows you to modify the LOW fuse byte only, as this byte controls the clock source selection. To change the value of the fuse byte:
# Press the "Read Fuses" button, and the values should be populated
# Specify the new low fuse value
# Hit "Write Fuses"
See [http://eleccelerator.com/fusecalc/fusecalc.php?chip=atmega328p an Online Fuse Calculator] to better understand what the values mean.
<blockquote>'''tip'''
; If programming a virgin ATMega328P device, the default low-fuse value of <code>62</code> results in the internal
: 8 MHz oscillator being divided down to 1 MHz. Any external clock is ignored.
The low fuse byte must be changed to <code>D0</code> to use the external clock provided by the ChipWhisperer toolchain.
</blockquote>
==== Programming the Flash ====
Programming the flash is accomplished by selecting the new .hex file in the "Find" menu, and pressing the "Erase/Program/Verify FLASH" button. The "Status" line will show the following information:
* File programmed into device
* Time file was last modified (very useful to confirm you are using changed file when doing development)
* Status of verification, and number of bytes programmed/verified
[[File:avrprog_progok.png|image]]