Reuse of standalone atmega8 chips for small projects ( flash is 8kb vs 32kb of atmega328 standard for arduino ). In order to program these chip using arduino and its libraries there is no need to flash a bootloader if you use an external usbasp programmer connected to miso,mosi,sck,reset of target atmega.
- usbasp programmer
- atmega8 chip
- breadbord
- dupont cables
to test
- 1 led
- 1k resistor
thanks to this project its easy to enable arduino to talk to atmega8 processor even at 8Mhz internal rc oscillator speed, to install just go to File/Preferences
and in Additional Boards Manager URLS
insert the json file https://raw.githubusercontent.com/carlosefr/atmega/master/package_carlosefr_atmega_index.json
.
now you'll see in tools boards ATmega Microcontrollers that include also 8/168/328 models
avrdude -c usbasp -p m8 -B 10.0 -U lfuse:w:0xa4:m -U hfuse:w:0xcd:m
- references
- avr fuse calculator
- for other models and/or different clock sources see boards.txt
Follows table of 8Mhz internal for various models
model | low fuse | high fuse | extended fuse |
---|---|---|---|
m8 | 0xa4 | 0xcd | |
m8 (*bod disabled) | 0x64 | 0xcd | |
m168/168p | 0xe2 | 0xdd | 0xf9 |
m328/328p | 0xe2 | 0xdb | 0xff |
(*) to disable Brown-out Detection on atmega8 need to set by fuse, while atmega328 support set at runtime
if inadvertently set a 16mhz clock usbasp could not connect atmega without proper crystal anymore, to recover you need to connect a crystal this way:
- XTAL1 -> crystal end1 -> capacitor 22pF to GND
- XTAL2 -> crystal end2 -> capacitor 22pF to GND
then issue a restore of fuse to use eg. 8mhz internal if want to go without requiring a crystal.
-
Tools
- Board/ATmega8
- Processor/ATmega8
- Programmer/USBasp
-
File/Examples/Basics/Led
-
Sketch/Upload
- refer to official datasheet for an overview of pinout for atmega8
- connect GND,VCC,RESET,SCK,MISO,MOSI from usbasp to atmega
- if want to use 16Mhz you need external crystal plus capacitors and use different fuses ( low:0xdf )
- LED_BUILTIN for atmega8 is PB5
refer to this for atmega8 arduino pin mapping
- connect a USB to TTL UART converter ( GND, RX-to-TX, TX-to-RX )
- setup speed if needed through Serial.begin(speed) in setup() then use Serial.println(x) as usual ( I tested it actually works even at 112500baud )
- it works even with 8mhz internal rc at 3.3v
- use https://github.com/olikraus/u8g2/ ( Sketch/Include/Manage libraries then filter for u8g2 )
- connect oled i2c display ( GND, VCC, SDA, SCL ) and uncomment
U8G2_SSD1306_128X64_NONAME_F_SW_I2C
constructor from theu8g2/FullBuffer/HelloWorld
sample
- just connect a push button between reset and gnd to restart program