Uploading to ATMEGA168

Hello

Please forgive what is probably a rather basic question.

I have a project which contains a bare ATMEGA168-20PU chip. It is soldered onto a PCB and there are headers on the board for DTR, RX0, TXI, 5V, GND, GND

I have the code for this which compiles OK on the Arduino IDE 1.8.9

The question is how to get the code onto the chip. I have a FDTI module which I have used successfully to upload onto a Arduino pro mini. The module's pinouts are DTR, RX, TX, VCC, CTS. GND and there is a jumper to switch between 3.3V and 5V

However, trying to use this module to upload to the chip gives me nothing apart from the uninformative error message "problem uploading to board".

There are lots of ways I could be going wrong but I haven't been able to find any tutorial which explains in simple terms what to do. Under the "tools menu" I can choose "programmer", but I don't know which of the many options to choose. Nor do I know what board to select, since these all refer to various Arduino versions rather than the bare ATMEGA chip. Do I need to upload a bootloader first?

Would it be possible to use a UNO as ISP instead (instead of the FDTI module), and if so how would I do this?

Any pointers would be much appreciated.

You trying to upload via serial line but it requires a bootloader. The bootloader have to be programmed via ISP and of course, ISP can be used also for normal program.

Arduino as ISP (also UNO) is possible to use. Here on web is a guide.

https://www.arduino.cc/en/tutorial/arduinoISP

FTDI can be used also for ISP programming like here:

https://forum.arduino.cc/index.php?topic=636965.msg4315517#msg4315517

see mainly the responses #1, #5 from the member @tf68. Little bit advanced method.
Personally, I'd never tried it. However, it should work as you can see.

OK thanks. I'm familiar with using the Arduino as ISP (with a UNO) with other chips such as the ATTINY84/5 but they don't require bootloaders.

If I can identify the MISO/MOSI/SCK/RESET pins on the ATMEGA168 I presume I should be able to do the same thing to upload the bootloader? But which board should I choose from the menu?

ISP pins are the same as for 328P - the UNO board. See the datasheeet or lots of it on Google.
Board could be "Arduino Duemilanove or Diecimila w/ ATmega168" and programmer "Arduino as ISP".

Thanks - I managed to upload a blink sketch, using the Nano 168 board setting. But it runs very slowly ... and I can't upload the bootloader. I suspect there is something wrong with clock settings.

Also HW.

Running slowly is a symptom of not having burned bootloader yo set the fuses to use the intended clock speed/source.

Virgin avrs are set to run at 1 MHz, and y po u need to do burn bootloader with the desired clock speed and source selected to set the fuses to use that clock source. If you havent burned bootloader, and are using a virgin chip, if you upload sketch compiled for 8MHz, all timing will be off by a factor of 8.

Yes that's what I thought. I can't seem to burn the bootloader from the Arduino IDE - only the sketch itself. Not sure where to go with this.

robertjenkins:
Yes that's what I thought. I can't seem to burn the bootloader from the Arduino IDE - only the sketch itself. Not sure where to go with this.

Posting the error you get would be a good start. And the schematic of your hardware configuration.

If it is just fuse setting, it can be do separately from CMD. It is just avrdude command similar one in full log, it is there.

I don't get an error message. It just says "uploading bootloader" but then nothing more happens. No flashing lights on the UNO.

I have the uno and ATMEGA connected with 6 jumpers like this:

UNO ATMEGA
5v === 5v (pin 7)

gnd --- gnd (pin 8)

d10 --- reset (pin 1)

d11 --- d11 (pin 17)

d12 --- d12 (pin 18)

d13 --- d13 (pin 19)

I'm using the "arduino nano with ATMEGA168" as the chosen board and the UNO programmed with the "use as ISP" sketch

You did upload the Arduino as ISP sketch to the Uno first?

robertjenkins:
I'm familiar with using the Arduino as ISP (with a UNO) with other chips such as the ATTINY84/5 but they don't require bootloaders.

...but maybe he forgot. Missing ISP sketch, it makes a sense anyway.

Also, if it is on breadboard, you have to have minimal circuit for ATmega like for reset, oscillator, all power pins must be connected and they should be decoupled.

DrAzzy:
You did upload the Arduino as ISP sketch to the Uno first?

Yes - didn't I say so? I think I did. That's how I've been able to upload the blink sketch to the ATMEGA.

Budvar10:
Also, if it is on breadboard, you have to have minimal circuit for ATmega like for reset, oscillator, all power pins must be connected and they should be decoupled.

No it's not on a breadboard, it's on a PCB. The power pins are connected (to power from the UNO, according to the table two or three messages back). The circuit contains an oscillator and decouplers. Have tried to upload a schematic.

You have no log?
When it starts uploading, UNO's Tx should blink 3x. Does it? It is a prompt and since this moment it's waiting for a response from target.

You was able to upload blink sketch. It is same process. BTW, are you still able to upload a sketch?

Yes, there is some brief flashing from the UNO Rx and Tx LEDs.
Here is the log.
(It still has no trouble uploading the sketch, this is what happens when I try to burn the bootloader)

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino Nano, ATmega168"

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avrdude -CC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf -v -patmega168 -carduino -PCOM4 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xF8:m -Uhfuse:w:0xdd:m -Ulfuse:w:0xff:m

avrdude: Version 6.3-20171130
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch

System wide configuration file is "C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf"

Using Port : COM4
Using Programmer : arduino
Overriding Baud Rate : 19200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x23
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x23

avrdude done. Thank you.

Error while burning bootloader.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf -v -patmega168 -carduino -PCOM4 -b19200 -e -Ulock:w:0x3F:m -Uefuse:w:0xF8:m -Uhfuse:w:0xdd:m -Ulfuse:w:0xff:m

You have to connect 10uF capacitor between RESET and GND on the programmer UNO, or use -cstk500v1. Newer Arduino SW it already has with stk500v1.

Thanks. I tried this ... no luck ... tried it with a different UNO and this time it worked, which is a result, thank you.

One more problem though: it seems to be running half speed, in that I can only read the serial output at 4800 even though the sketch specifies Serial.begin(9600);

There is an 8MHz crystal on the board, if that's relevant.

It can be if you have the sketch compiled for 16MHz. What is your setting?

Post a photo from your setup and log. It must work.