Can I reuse ISP pins for other tasks?(Target: Atmega164p)

Go To Last Post
33 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My teacher said that I should dedicate the pins only for the purpose of ISP and that I should not use it for other purposes. My guess is that the AVR should be able to distinguish between between the programming mode and the normal running mode (because of the reset pin). Please advice me further as I am falling short of pins and any extra pin would be useful.

Also tell me if there are any precautions that are necessary if the dual use of the pins is possible.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sgsawant wrote:
Can I reuse ISP pins for other tasks?(Target: Atmega164p)

You can...

You will need to connect the MOSI, MISO & SCK lines directly to the ISP header. Then to use the MOSI, MISO & SCK pins for other functions, they will need to be connected to that other function by way of a 4.7K (or something similar) isolation resistors. This provides isolation so that when the ISP is being used, the MOSI, MISO & SCK lines won't be in contention with that alternate function.

The only requirement here is that you will need to be sure that the alternate function dosn't wiggle the SCK line when attempting to perform ISP on the target device.

A case in point... I've driven an HD44780 based LCD where DB5, DB6 & DB7 of the LCD were driven by the same pins that the MOSI, MISO & SCK ISP functions shared. I simply inserted a 4.7K Ohm resistor between the AVR pins and the LCD pins, while the same MOSI, MISO & SCK pins were connected directly from the AVR pins to the ISP header.

With out these isolation resistors, I was not able to use the ISP. But with these isolation resistors, everything worked perfectly.

sgsawant wrote:
My teacher said that I should dedicate the pins only for the purpose of ISP and that I should not use it for other purposes. My guess is that the AVR should be able to distinguish between between the programming mode and the normal running mode (because of the reset pin). Please advice me further as I am falling short of pins and any extra pin would be useful.

There are time that in order to meet the required design goal, you must use the ISP lined for alternate functions - it's that simple!

Also tell me if there are any precautions that are necessary if the dual use of the pins is possible.

Ask your teacher if he/she has ever actually attempted such a thing for his/her own personal knowledge, or if he/she just read that nonsense out of one of his/her books.

Better yet, ask your teacher if he/she has ever actually sat down at one of the lab benches and learned for himself/herself if what he/she says isn't possible (or practical), to find out if it really possible with an AVR.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
any precautions that are necessary if the dual use of the pins is possible.
Yes, you MUST make sure that nothing interferes with the programmer. The data sheet usually advises to put a 1K resistor minimum in series with anything that may use the ISP pins.

So the ISP connector goes to the SPI pins directly and anything else using the pins has a resistor in series. There are other ways like making sure that any chip that may DRIVE any ISP pins is maintained in the reset mode during programming via a pull up or pulldown resistor in the chip select pin of the chip.

Notice how R41 is pulling the SS pin high so that the ADC is kept in reset mode during programming.

Attachment(s): 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm never have any trouble with programming when the pins used for ISP are directly connected to an HD44780 based LCD with direction signal connected to GND. Often I'm using these pins to connecting an keyboard. I don't press any key while programming, of course. :wink:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awit wrote:
I'm never have any trouble with programming when the pins used for ISP are directly connected to an HD44780 based LCD with direction signal connected to GND. Often I'm using these pins to connecting an keyboard. I don't press any key while programming, of course. :wink:

But what if you are using the LCD busy signal, using 4-bit mode, and the LCD DB7:DB4 data lines, and RS, R/W & E control lines are all driven by the same I/O port? In this case the LCD R/W control line will not be connected to GND, it'll be connected to an I/O pin and will float high during ISP causing the busy (DB7) & DB6:DB4 data lines to enter contention with the MOSI, MISO & SCK pins.

So using the LCD busy signal function is a clear case of needing isolation resistors between the ISP lines and the LCD data and/or control lines. Of course, exactly which LCD lines need isolation strictly depends on which controller you are using, and how the LCD is wired to the AVR.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The data sheet usually advises to put a 1K resistor minimum in series with anything that may use the ISP pins.

Could you point to where this information might usually be found in the datasheet?

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

The data sheet usually advises to put a 1K resistor minimum in series with anything that may use the ISP pins.

Could you point to where this information might usually be found in the datasheet?

Lee


Lee, check out AVR application note-910, page 3, document 0943-AVR-05/02

While figure 3 does show the proper circuit configuration, the document doesn't specifically call out a particular resistance value. I've had good luck using 4.7K Ohm resistors.

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can you multiplex other pins or use bigger microcontroller?

May I note that in case other functions interfere with ISP, plugging in and out the ISP plug gets tedious real fast.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

May I note that in case other functions interfere with ISP, plugging in and out the ISP plug gets tedious real fast.

I haven't had problems like that. I just leave the AVRISP MkII plugged in and powered up (i.e. connected to the PC also). I'm using 1K resistors, btw.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Lee, check out AVR application note-910, page 3, document 0943-AVR-05/02


-- I was asking js where it could "usually" be found in AVR datasheets. I'll wager a cold one that it not only will not be "usually" found, but it will "rarely" or "never" be found.

-- While AVR910 is indeed described as "This Application Note shows how to design the system to support in-system programming." when read it is almost entirely devoted to building your own ISP.

Quote:
While figure 3 does show the proper circuit configuration,...

I would not go as far as calling it a proper configuration.

-- Perhaps the series resistors actually cause harm, as when switching signal levels?
-- Not all AVRs use the SPI subsystem for ISP. I'd think we have seen many more cases of Mega128 interference than SPI.
-- If you indeed do have an SPI device out there, it is a simple matter to keep it deselected when the AVR is in reset. By its nature an SPI will cause any problems if that is done.
-- It ignores what is probably the bulk of applications--there is no SPI device attached.

In my experience delaying with scores of production AVR apps, all with ISP: If you take a bit of forethought when doing system design and pin allocation, ISP usually doesn't cause a problem with the app, nor does the app interfere with ISP. This choice is tough, sometimes, especially on pin-challenged AVRs such as Tiny25. Slowing down ISP will often do the trick when a quick poke with the 'scope indicates malformed ISP signals.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I must be wrong, I wonder where this guy got the info from then, probably does not know what he is talking about either. :wink:

Quote:
Aahh, I missed that. The problem isn't going to be the >>AVR<< in doing ISP on the USART0 lines, but typically from your line driver (e.g., MAX232, MAX485) which is going to drive the AVR's RXD0 line all the time when powered. So, yes, a 1k series resistor there allows the ISP to drive the signal.

Lee

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

microcarl wrote:
awit wrote:
I'm never have any trouble with programming when the pins used for ISP are directly connected to an HD44780 based LCD with direction signal connected to GND. [...]

But what if you are using the LCD busy signal, using 4-bit mode, and the LCD DB7:DB4 data lines, and RS, R/W & E control lines are all driven by the same I/O port? In this case the LCD R/W control line will not be connected to GND, it'll be connected to an I/O pin and will float high during ISP causing the busy (DB7) & DB6:DB4 data lines to enter contention with the MOSI, MISO & SCK pins.

So using the LCD busy signal function is a clear case of needing isolation resistors between the ISP lines and the LCD data and/or control lines. Of course, exactly which LCD lines need isolation strictly depends on which controller you are using, and how the LCD is wired to the AVR.


Microcarl, in general case I'm fully agree with You. But in my applications I avoid, when possible, using the ISP pins as inputs from any device. And I newer use LCD busy flag. In case when all lines of LCD must be driven by the same I/O port used for ISP and R/W line may be connected to pin not used by ISP, it is enough use resistor connected between this line and GND for force low state of this line when microcontroler output is in High-Z state, I suppose. And in this solution only one resistor is used, not three.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I must be wrong, I wonder where this guy got the info from then, probably does not know what he is talking about either.

Careful; I'm in Surly Curmudgeon mode tonight.

I'll make a 'Bob' Grand Pronouncement: There is no AVR datasheet that has information such as what you suggested it "usually" has. Period. It don't have it. It ain't ever been there.

>>If<< you choose to hang a device on the ISP line that always drives, even when the AVR is in reset, then ISP ain't gonna work right.

Any disagreements so far?

One of the most common situations of the previous is ISP on Mega128 family that uses USART0 pins for ISP signals, and it would be usual to have a transceiver on those signals. Yes in that case a series resistor will isolate it in most cases.

Is that in the datasheet? No.
Is that SPI? No.
Is that as in AVR910? No.

If you care to, you can add resistors and any other components on any or all I/O lines of your AVR design. Is it necessary to add series resistors to a real SPI device that is using the same Vcc level? Certainly not, if it is deselected when the AVR is in reset. If you think about it you would often want that anyway, such as with a DAC or a comm device.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
JS wrote:

I must be wrong, I wonder where this guy got the info from then, probably does not know what he is talking about either.

Careful; I'm in Surly Curmudgeon mode tonight.

And so we should be fearing for our lives?

Along with JS, I have read something about using series resistors (and their values) when using SCK, MOSI, MISO and RESET for both SPI & ISP. But for the life of me, I can't seem to put my eye-balls on that statement.

In fact, there was a specific caution about the ISP lines from the alternate device not being allowed to change state during the ISP operation - SCK, in particular.

But just because you're in a "Surly Curmudgeon mode tonight. ", that's not going to intimidate me into being bullied into backing down from what I know to be true and that I know works, and what I've seen & read - simply because you declare that your Dr. Jekyll side is on the loose for the Halloween festivities.. :roll:

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have to concede that the 1K figure is not shown in the CURRENT data sheets but I have seen it and that's the value I use when I need to isolate MISO from a peripheral.

I also use it in series with JTAG pins for leds.

Perhaps it is these hints that our foggy minds recalls.

Quote:
Pull-up resistors
If any pull-up resistor is needed on the MISO/MOSI/SCK lines, it should not be stronger (i.e. smaller value) than 820 ohm.

MOSI/MISO/SCK
If the MOSI, MISO or SCK line are used as general I/Os in the application, it is recommended to use series resistors between the load and the AVR as shown in Figure 5. The AVRISP lines should be connected directly to the AVR pins, without any series resistors.

The figure below shows which JTAG lines should be connected to the target AVR to ensure correct operation. To avoid drive contention on the lines it is recommended that series resistors are placed between the JTAG lines and any external circuitry. The value of the resistor should be chosen so that the external circuitry and the AVR do not exceed their maximum ratings (i.e. sink or source too much current).

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

js--where did those quotes come from? I can't find it.

AVR910 comes fairly close:

Quote:
To avoid driver contention, a series
resistor should be placed on each of the three dedicated lines if there is a possibility that external circuitry could be driving these lines.

Now, other than that the reference is to the SPI signals that are not used for ISP on all models, that is indeed sound advice and is what js and microcarl are trying to pound into me.

But as a blanket statement it has flaws. I've pointed out several times that if you have true SPI device(s) then use the resistors on device selects to keep them de-selected. Much better in my opinion and experience.

For other devices one has to use the little grey cells. Got a DIP switch block attached? Better be open during ISP, or resistor value selection may become critical. Active-low LEDs usually work OK, with the series current-limiting resistor. ;) Something with capacitance is more problematic--Tiny25 family has AREF pin sharing MOSI for ISP. Gotta use a small value cap and slow ISP waaayyyy down.

Output devices often ISP fine, but can be scary--if the app lines are driving relay drivers or other switching circuitry, it could be downright dangerous.

Here is my summary: To OP--yes, ISP pins can be re-used for other tasks. But one has to think about what functions make sense on shared circuitry.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Re-using ISP pins is described in AVR042, chapter 4 "Connecting ISP lines". The series resistors are shown, but figuring out the resistor values seems to be left as an exercise for the reader.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you have enough I/O pins for your other functions, then using the programming pins for dedicated programming function is the easiest thing to do. But, very often, you will need to use the programming pins for I/O functions as well.

As others have described, unless you have jumpers to isolate the pins, resistors are the best choice. A picture is worth a thousand words, so see diagram.

Normally, I use two resistors for each line. A 10:1 ratio is chosen so that the ISP programmer can drive ISP inputs to at least 90% VCC even if the on board device is driving this line low. In the diagram, a 1K:100 ohm resistor network is shown. Most programmers can drive this load. Although, the STK500's might have trouble. In this case a 4.7K:470 network would work better. You can even leave off the lower resistance value if you feel comfortable. But I like to have it onboard for extra protection in case of light ESD, misplugging, etc.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think that this thread has established that reusing
ISP pins is not only possible, but ordinary.
The OP now knows how to do it.
He is not done yet.
He also needs to avoid a knock-down-drag-out with the teacher.
The OP should come to the meeting with a copy of AVR042.
If the teacher's direction does not have a rational basis,
the Author of the Data Sheets is likely to be the only source good enough.

Also, I'd like to suggest the use of PNG or GIF
instead of JPEG for drawings.
JPEG is designed for continuous-tone images.
The attachments were derived from gahelton's isp_connections_189.jpg .

Attachment(s): 

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
js--where did those quotes come from? I can't find it.
AVRISP & AVRISP mk2 (Hardware Description) and JTAG Mk2 (Connecting to the target through the JTAG Interface) help files.

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

microcarl wrote:

Better yet, ask your teacher if he/she has ever actually sat down at one of the lab benches and learned for himself/herself if what he/she says isn't possible (or practical), to find out if it really possible with an AVR.

Or perhaps his teacher told his students not to use those pins because his teacher wants his students to finish the project this year? You do that by giving clear directions, and assigning projects of sufficient but not unnecessary complexity.

BTW, if you've already got a pin header, those pins are particularly good for jumpers or test points...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

melbourne wrote:
microcarl wrote:

Better yet, ask your teacher if he/she has ever actually sat down at one of the lab benches and learned for himself/herself if what he/she says isn't possible (or practical), to find out if it really possible with an AVR.

Or perhaps his teacher told his students not to use those pins because his teacher wants his students to finish the project this year? You do that by giving clear directions, and assigning projects of sufficient but not unnecessary complexity.

Those might be reasons, but I think the time issue is overstated.
Note that the teacher said that the OP should dedicate ISP pins.
The teacher might have counted pins and determined that ISP pins did not need reusing.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have an application that will interface with an AD9951 DDS chip. It will use the SPI interface. In this case the AD9951 is a 1.8v part with a 3.3v IO interface. If I want to READ the output of the AD9951 I'll have to add a voltage converter or the 3.3v output might not be seen as a logic one by the AVR. On write, the AD9951 can handle the 5v output, but I've seen a voltage divider inserted between the CPU and the AD9951 to reduce the logic 1 voltage level. In any case a 4.7k ohm series resistor will certainly work and solves my problem of having the SPI pins available for ISP programming as well. The voltage divider method would consist of a 3.3k resistor in series with a 5.6k to reduce the logic 1 voltage to the AD9951. I would assume that a resistor of 9K across the SPI pins to ground would not be a problem for the programmer. (I plan on using the Mega32 part.)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ah! A fellow thread hijacker. :roll: Go hijack this thread instead.:
https://www.avrfreaks.net/index.p...

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

emuler wrote:
Ah! A fellow thread hijacker. :roll: Go hijack this thread instead.:
https://www.avrfreaks.net/index.p...

Not really. My point was that the same resistors that would perform the level conversion ALSO isolate the port pins so that you can still connect the ISP programmer without problems from connecting your I/O.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Level translation using resistors leaves a lot to be desired when speed is an issue. The resistor in conjunction with the input capacitance forms an RC filter leading to slow rise and fall times which cause problems. :( If it works for you, fine. Just pointing out that it didn't work for me.

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

emuler wrote:
Level translation using resistors leaves a lot to be desired when speed is an issue. The resistor in conjunction with the input capacitance forms an RC filter leading to slow rise and fall times which cause problems. :( If it works for you, fine. Just pointing out that it didn't work for me.
Did you try a small resistor and some diodes?

The other time I even thought about level translation,
my boss and I decided to avoid it.
We had a USBKey edited to run at 5 volts.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Did you try a small resistor and some diodes?

Yes. I ended up putting 47pF capacitors across all the series resistors just to speed things up. :P

If you think education is expensive, try ignorance.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi

Could anybody give an example of how one should share the MOSI, MISO & SCK ports between the ISP Connector and a Micro SD Card. The micro SD Card is driven by a 74HC4050 Hex Converter (interfacing 3.3 to 5 volts).

I have searched but there doesn't seem to be any common method.

This link shows some examples:
http://www.radiolocman.com/shem/...

The bottom schematic shows direct connection but it crossed my mind that he may simply be removing the SD card while using the ISP connection. (but I a have the hex inverter as I am using a Micro SDCard)

Or can they both be hard wired and long as the SD Card CS is held low?

Or do I need to place resistors in line with SD Card connections on the processor side of the hex converter? If so what size?

Thanks & Regards

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can normally put many SPI devices on the same SPI bus. You just make sure that each /CS has an external pull-up resistor. Whenever /CS is high, all the device pins are in 3-state.

Since some bright spark chose to put the 4050 in the way, you cannot 3-state a 4050. So the MISO lines would fight. You should be able to share SCK, MOSI ok.

Next time, either use a Hex Buffer that has a /CE or /CS pin, or run everything at 3.3V.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David

Thanks for the response.

So if I change the hex buffer a Hex Buffer that has a /CE or /CS pin and a pull up resistor all will be COOL?

Actually it wasn't this Bright Spark but SparkFun who chose the 4050, you were close... ;)

I purchased their breakout board for testing and used their circuit.

Thanks Again...

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

David

I have seen a number examples of people using voltage divider resistors to handle the different logic levels on the SS,MOSI & SCK signals. One uses a BS250 to pull SS (5volt side) HIGH on RESET. The circuit can be seen here http://www.roland-riegel.de/sd-reader/sd-reader_circuit_latest.zip near the top of the page under the title "The Circuit".

Would you have any comments on this approach?

Thanks & Regards

Dave

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For a final solution, voltage dividers are fine. You know which pins are input and which are output.

For any general dev board, you may swap modes many times. With an all 3.3V system, everything works fine.

With a mixed system, the buffers have to 'change ends'.

Life is much easier if you just choose all 3.3V parts.
Most MCUs will run at full speed even at 3.3V. It is far simpler to use the cheaper A part than to use a V part + level-shifter.

David.