Hey Everyone!
this is my first post on these forums and my first ever attempt to program a bare micro controller IC. Since i do not have an AVR programmer and it is impossible for me to acquire one where i live , my only choice is to use an Arduino Uno as ISP. I have tried several ways such as using Optiloader's bootloader and also using the example available in Arduino IDE called Arduino as ISP. In both cases uploading the bootloader seems to be successful but i can't upload my blinker program. I get the following error while trying to follow this tutorial:
avrdude: stk500_getsync(): not in sync: resp=0x00
it does 10 attempts(takes a long time) and fails.
so I thought , why would i use a bootloader? let's try uploading hex files directly from avrdude and for that purpose i followed this tutorial.
This is what i type in the cmd:
avrdude -c arduino -b 19200 -p m8 -P COM5 -U flash:w:ATmega8-test.hex
and this is the response:
avrdude: AVR device initialized and ready to accept instructionsReading | ################################################## | 100% 0.04s
avrdude: Device signature = 0x1e9307 (probably m8)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "ATmega8-test.hex"
avrdude: input file ATmega8-test.hex auto detected as Intel Hex
avrdude: writing flash (360 bytes):Writing | ################################################## | 100% 0.74s
avrdude: 360 bytes of flash written
avrdude: verifying flash memory against ATmega8-test.hex:
avrdude: load data flash data from input file ATmega8-test.hex:
avrdude: input file ATmega8-test.hex auto detected as Intel Hex
avrdude: input file ATmega8-test.hex contains 360 bytes
avrdude: reading on-chip flash data:Reading | ################################################## | 100% 0.48s
avrdude: verifying ...
avrdude: 360 bytes of flash verifiedavrdude: safemode: Fuses OK (E:FF, H:C5, L:BF)
avrdude done. Thank you.
it seems like the upload was successful right? but here is the simple code i'm uploading:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
void main()
{
// Turn on the clock for port D
DDRD |= (1 << PD5);
while(1)
{
// switch pin 5 of port D
PORTD ^= (1 << PD5);
//wait for half a second
_delay_ms(500) ;
}
}
i have written this code in Atmel studio(called microchip studio these days) , compiled it and am trying to upload the hex file in the Bin folder of the project to my ATmega8a.
according to the official datasheet of ATmega8A, PD5 is the 11th pin on the micro and has no default function and seems to be a GPIO. next i connect an LED in such a way that the - side goes to the common ground(powered by an Arduino uno 5v without an additional regulator) and the positive side goes through a resistor to PD5 but the LED does not blink which means my program is not uploaded successfully? what am i doing wrong?
oh and before i forget here are the connections:
pin1--> through a 9.5k resistor to VCC
pin1--> also connected through a different connection to pin 10 of Arduino
pin 7 --> 5v from arduino
pin 8 --> Arduino GND
(there is a 0.1 Uf capacitor between GND and VCC pins next to pins 7 and 8)
pin 9 -->16 Mhz crystal
pin10 --> 16 Mhz crystal
(there are two 20pico farad capacitors between each leg of the crystal and GND)
pin 17 --> Arduino pin 11
pin 18 --> Arduino pin 12
pin 19 --> Arduino pin 13
pin 20 --> +5
pin 22 --> GND
I tried removing the 9.5 k resistor to VCC and restarting the IC by disconecting Arduino 5 volts and reconnecting it to no avail(thought maybe this would change the boot mode to flash)
i also tried connecting the positive leg of the LED to every single pin of the micro controller thinking maybe PD5 is not the 11th pin , the LED would only turn on when connected to pins 1 , 7 and 20 obviously because they are connected directly to VCC.