Arduino Uno R3 as a true ISP programmer for any AVR

Are you sure that the capacitors that you think are 22pF really are of that value? It wouldn't be the first time that someone connected capacitors of the wrong value to the crystal, and found that it works when those capacitors are removed.

You want serial debugging but you don't want to use the 328 serial port and you want to use BASCOM for programming. How do you imagine the target will send serial / debugging data?

What I want is a single wiring configuration between Arduino Uno R3 and target Atmega328p for both debugging and programming. It could be SPI, (Serial RX,TX) or something else.

You have something called "Debug Knock-Bang" that do not seem to require Serial RX,TX, only the SPI:

you should be able to upload the test sketch to a tiny processor and use Serial Monitor for debugging.
Knock-Bang uses MISO (and GND) for communications. You only need to connect the target (the tiny processor) and programmer (the Uno) as would normally do for programming. No extra connections are needed.

However, I do not know if I can use that Knock-Bang for debugging programs written in BASCOM for my target Atmega328p.

The code I have is written in various languages, Bascom, IAR C, etc..
QUESTION: Is there, a simple way to insert code lines in my programs that will instruct the target Atmega328p to send messages on the SPI to Arduino Uno R3 which, in its turn, will direct them to the Serial Monitor window?
Instead of SPI for programming and Serial TX for debugging I would prefer to use SPI for both operations.

dc42:
Are you sure that the capacitors that you think are 22pF really are of that value?

Yes. They are 22pF. They look like in the link (see below) having the number 22, without anything else additional, marked on them.
I also mounted them in a tight configuration like here:

without any supplemental wire between uC, Crystal, capacitors and ground, and the Crystal oscillates, this time. Cristal also works without them but I understand that this is normal, the two 22pF capacitors having the only role to start the oscillations in rare situations when the Crystal can not start alone.

What I want is a single wiring configuration between Arduino Uno R3 and target Atmega328p for both debugging and programming. It could be SPI, (Serial RX,TX) or something else.

Sure, this could work in theory. In the easiest to understand form, once your sketch is uploaded, you could run softwareSerial on the MOSI/MISO pins and switch the Uno/ArduinoISP into a serial relay (also using softwareSerial) after it's done programming.
But it doesn't do that now.

The capacitors are for matching or terminating the crystal properly they are "Loading" for the crystal and a frequent cause of the Arduino Clock being 'off'' by 10's to hundreds of KHz, one of them can be replaced with a trimmer cap to "Net" or adjust the oscillator frequency, Not really difficult. As I remember the netting cap should be on the output side of the oscillator port. an NP0 type of 10 to 50 pF trimmer cap should work... But NO changes should ever be needed unless you are trying to build a clock that requires extreme accuracy (Not recommended as thermal effects would offset any trimming you might accomplish). On the subject of high accuracy... well that's another topic and out of "scope" of this thread however it is a trivial task to do with an inexpensive part or two and a lot of electronics knowledge.

Bob

simplex:
What I want is a single wiring configuration between Arduino Uno R3 and target Atmega328p for both debugging and programming. It could be SPI,

No, it can't. SPI requires three wires for programming and two for communications.

(Serial RX,TX) or something else.

Nope. Two wires for programming.

To get "single wire" programming and debugging you are going to have to purchase a DebugWIRE programmer.

You have something called "Debug Knock-Bang" that do not seem to require Serial RX,TX, only the SPI:

No, it does not require nor use SPI. Knock-Bang requires a single wire connected to any two arbitrary pins. MISO is used by default because it is already connected to both sides and, theoretically, has minimal chance of causing conflicts.

However, I do not know if I can use that Knock-Bang for debugging programs written in BASCOM for my target Atmega328p.

You have the source code.

westfw:

What I want is a single wiring configuration between Arduino Uno R3 and target Atmega328p for both debugging and programming. It could be SPI, (Serial RX,TX) or something else.

Sure, this could work in theory. In the easiest to understand form, once your sketch is uploaded, you could run softwareSerial on the MOSI/MISO pins and switch the Uno/ArduinoISP into a serial relay (also using softwareSerial) after it's done programming.
But it doesn't do that now.

Using your idea, I believe that TinyISP with Serial Monitor detailed here:

can work without any modification if a BASCOM program that runs on target Atmega328p, and which was previously loaded using TinyISP, implements softwareSerial TX on MISO (pin 18).
There is a software Serial (UART) example at the end of this Using the UART BASCOM help page.

  • So, in my "Blink a led" code, I will have to insert Bascom software UART settings and also an instruction that will send on MISO (configured as TX) the debugging message "Led on".
  • Then I upload "Blink a led" code to the target Atmega328p and start the Serial Monitor using "!".
  • At this point I should receive the text "Led on" in the window of the Serial Monitor.

Likely I will have to insert an "Wait 30 sec" instruction in the beginning of "Blink a led" program to have enough time to start Serial Monitor before the first "Led on" text is sent and before I open MISO as TX.

As a question, if pin n of AVR 1 is connected to pin m of AVR 2 and both controllers transmit on pin n and m, respectively (this is and accidental collision of signals), can I damage the AVRs or no?

simplex:
Likely I will have to insert an "Wait 30 sec" instruction in the beginning of "Blink a led" program to have enough time to start Serial Monitor before the first "Led on" text is sent and before I open MISO as TX.

Nope. TinyISP has a command to hold the target in reset until the Monitor is started.

simplex:
As a question, if pin n of AVR 1 is connected to pin m of AVR 2 and both controllers transmit on pin n and m, respectively (this is and accidental collision of signals), can I damage the AVRs or no?

Yes. That can damage both processors. A 220 ohm (or higher) resistor in series solves the problem.

Most of the time, while trying to use avrdude with TinyISP loaded in Arduino Uno R3, I get the error: "avrdude: ser_open(): can't open device "\.\COM3": Access is denied."
I tried to reset Arduino Uno R3 but with no positive results. The error does nor disappear till I reload TinyISP. After that, I can use avrdude to load programs in the target Atmega328p but only a few times till the error appear again.
I also get errors like this with ArduinoISP but they disappear after resenting Arduino Uno R3.

c:\>avrdude -P COM3 -b 19200 -c avrisp -p m328p -v -u -n

avrdude: Version 5.10, compiled on Jun  4 2012 at 14:16:26
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Program Files\Atmel\AVR Tools\AVR Toolchain\bin\avrdude.conf"

         Using Port                    : COM3
         Using Programmer              : avrisp
         Overriding Baud Rate          : 19200
avrdude: ser_open(): can't open device "\\.\COM3": Access is denied.

Software Serial (UART) works with pin 18 (MISO) of target Atmega328p configured as TX
No more wiring changes, between programming and debugging with TinyISP, are needed

This is the test Bascom "Blink a led" program I used:

'Blink a LED

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 9600

Waitms 30000

Config Portd = Output

Dim I As Integer

'Open a TRANSMIT channel for output

Open "comb.4:9600,8,n,1" For Output As #1

Print #1 , "Serial output on"

Do
 For I = 1 To 10
  Portd = 255
  Waitms 1000
  Print #1 , "Led on"
  Portd = 0
  Waitms 1000
  If I = 10 Then Goto Endprog
 Next I

Loop

Endprog:

Print #1 , "Serial output off"
Close #1

End

This is what I got in Serial Monitor Window of Arduino 1.0.1:

--- Monitor starting ---
Serial output on
Led on
Led on
Led on
Led on
Led on
Led on
Led on
Led on
Led on
Led on
Serial output off

--- Monitor stopped ---

So the output is in concordance with what I should get in the Serial Monitor.

However, there are two small problems:

1 ) The "Blink a led" program starts immediately after being loaded by TinyISP in the target Atmega328p. Without the instruction "Waitms 30000" (wait 30 seconds) I miss all the messages outputted before I start Serial Monitor with "!".

2 ) I would like TinyISP to be able also to transmit messages (commands given by my) from Serial Monitor to target Atmega328p, not just relay text from target Atmega328p to the Serial Monitor.
I would like TinyISP to understand not just a software serial TX run on target Atmega328p MISO (pin 18) but also a software serial RX on MOSI (pin 17), or on a different, already connected, SPI pin.
I guess that adding an RX facility beside already existent TX is not a difficult task for the one who wrote TinyISP.

simplex:
"avrdude: ser_open(): can't open device "\.\COM3": Access is denied."

An application on your computer is probing serial ports. The usual culprit is PDA / mobile phone synchronizer.

simplex:
1 ) The "Blink a led" program starts immediately after being loaded by TinyISP in the target Atmega328p. Without the instruction "Waitms 30000" (wait 30 seconds) I miss all the messages outputted before I start Serial Monitor with "!".

2 ) I would like TinyISP to be able also to transmit messages (commands given by my) from Serial Monitor to target Atmega328p, not just relay text from target Atmega328p to the Serial Monitor.
I would like TinyISP to understand not just a software serial TX run on target Atmega328p MISO (pin 18) but also a software serial RX on MOSI (pin 17), or on a different, already connected, SPI pin.
I guess that adding an RX facility beside already existent TX is not a difficult task for the one who wrote TinyISP.

Line #52:

[quote author=Coding Badly link=topic=125248.msg961884#msg961884 date=1350582326]

simplex:
"avrdude: ser_open(): can't open device "\.\COM3": Access is denied."

An application on your computer is probing serial ports. The usual culprit is PDA / mobile phone synchronizer.[/quote]

It appears that the parasitic application that disturbs avrdude is Arduino 1.0.1 Serial Monitor itself.

If Serial Monitor runs, avrdude displays "avrdude: ser_open(): can't open device "\.\COM3": Access is denied." while trying to upload a program with TinyISP in my target Atmega328p. If I close the Serial Monitor Window, avrdude no longer outputs "can't open device" error and I can upload the hex code to the target Atmega328p. If I start Serial Monitor (without issuing any command like "!", "@", etc.) again avrdude is unable to program the target AVR controller.
So, I do not have to program the target Atmega328p while Serial Monitor runs in parallel with avrdude, on my PC.

[quote author=Coding Badly]
Wiring the Serial Relay...
• Digital pin 12 on the Uno is receive. Connect transmit from the target to pin 12 on the Uno. This pin is also used when programming the target (MISO).
• Digital pin 14 (A0) on the Uno is transmit. It can be left unconnected or it can be connected to receive on the target.[/quote]
Source: SoftwareSerial with ATTiny84 using ATtiny library - #28 by Coding_Badly - Microcontrollers - Arduino Forum

This is line #52 of TinyISP / TinyISP_RelaySoftSerial.h

52: static SerialRelay RelaySerial( 12, 14 );

You suggest that I should change 14 with 11, like this: "static SerialRelay RelaySerial( 12, 11 );" ?
I found Arduino Uno pin mapping here: http://arduino.cc/en/Hacking/PinMapping168
Of course, in my "Blink a led" program I will have to implement a software Serial RX, TX being already functional.

This is all I have to change?

I made the change "static SerialRelay RelaySerial( 12, 14 );" -> "static SerialRelay RelaySerial( 12, 11 );"

TinyISP works now as a full TX, RX relay between my target Atmega328p and Serial Monitor Window. No supplemental connections are needed any more. Programming and debugging is done on the same (SPI) wires.

This is the test code:

'Test Bascom code that transform target Atmega328p in a character
'receiver/transmitter

'Any character sent from Arduino 1.0.1 Serial Monitor comes
'back and is displayed by the same Monitor.
'Arduino Uno R3 board, running TinyISP programmer/debugger, works as a relay
'between target Atmega328p (the controller that runs this Bascom code) and
'Serial Monitor Window on the PC.
'Target Atmega328p Port B, Pin 4 (MISO) works as software TX while
'Port B, Pin 3 (MOSI) is software RX
'By using software TX, RX, the same wiring configuration (SPI) used for
'programming target Atmega328p is also utilized for debugging and/or
'bidirectional data comunication between the PC and target Atmega328p.

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 9600

Dim B As Byte
Waitms 100

'Open a TRANSMIT channel for output

Open "comb.4:9600,8,n,1" For Output As #1
Print #1 , "serial output"

'Now open a RECEIVE channel for input

Open "comb.3:9600,8,n,1" For Input As #2

'Since there is no relation between the input and output pin
'there is NO ECHO while keys are typed

Print #1 , "Press any alpha numerical key"

'With INKEY() we can check if there is data available
'To use it with the software UART you must provide the channel

Do

   'Store in byte

   B = Inkey(#2)

   'When the value > 0 we got something

   If B > 0 Then
      Print #1 , Chr(b)                                     'Print the character
   End If

Loop

Close #2                                                    'Close the channels
Close #1

End

And this is the output I get in the Serial Monitor when I send characters f g h to the target Atmega328p.

--- Monitor starting ---
f
g
h

--- Monitor stopped ---

It looks like Arduino Uno R3 can be used as a true programmer/debugger now!

Um. A serial connection does not make a "true debugger."

westfw:
Um. A serial connection does not make a "true debugger."

It does make a "better than nothing debugger." :smiley:

Hi 8)

Can I use Arduino as AVR Programmer :grin: Like USBASP or STK200/300 or ST500 or ... Just for Programm my AVR chip?! ::slight_smile:

Only want to Upload a HEX file to AVR chips NOT Bootloader!!! :sleeping:

Is possible? :grin: