Change the pins used for SPI

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

Hello,

Is it possible to change which pins are used for SPI? I am programming my ATmega328p through ISP, and that takes up the SPI pins, but I also want to connect an SPI display to them, and I'm afraid that flashing the microcontroller using my programmer might also damage the display (since it's connected to the same pins).

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


See:

 

http://ww1.microchip.com/downloa...

 

in particular:

 

Nothing stops you using the SPI pins for ISP at the same time as long as the SPI use is isolated beyond resistors (and the SPI devices tristate their lines when not chip selected).

 

Having said that.. two other alternatives:

 

1) The UART in the 328 can also be a second SPI...

 

 

2) alternatively, SPI is actually SO simple that it's easy to "bit bang" the interface on any 3 IO pins you choose. You just need a for() loop to create 8 clock pulses and at the same time both shift out the bits of a byte on one IO pin and shift in the bits of a received byte coming in on another pin (ie MOSI out and MISO in). 

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

No the pins are fixed to the SPI, although in the M328 you can use the USART as a master SPI and those are on different pins.

However, SPI is a bus, so multiple devices can live on it at the same time, they usually have different SS pins.

There is an app note on sharing ISP pins with SPI devices as well, I'll see if I can find it and update this post.

Here they are: AVR042 or the newer microchip version AN_2519, which shows adding series resistors between ISP and SPI lines, I seen 1k's used for this.

 

Jim

Edit: added app note

Attachment(s): 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

you should be fine. Just add series resistors as Clawson and Ki0BK mentioned.

You will see flickering on the display and perhaps garbage being written on the display during programming, but after programming is done the processor is reset anyway and then also the display should be fully re-initialized ( nice check if you did that correct or some "default value has been changed by the programming)

 

I have a couple of designs with a display in the SPI bus and programming done through ISP. never had a problem (once I found out my init was not ok and I had missed a couple of registers )

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

meslomp wrote:

you should be fine. Just add series resistors as Clawson and Ki0BK mentioned.

You will see flickering on the display and perhaps garbage being written on the display during programming, but after programming is done the processor is reset anyway and then also the display should be fully re-initialized ( nice check if you did that correct or some "default value has been changed by the programming)

 

I have a couple of designs with a display in the SPI bus and programming done through ISP. never had a problem (once I found out my init was not ok and I had missed a couple of registers )

 

Na. As long as the display's SS line remains inactive it won't pay any attention to ISP.

The largest known prime number: 282589933-1

It's easy to stop breaking the 10th commandment! Break the 8th instead. 

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

Torby wrote:

 

Na. As long as the display's SS line remains inactive it won't pay any attention to ISP.

 

agree, but when in reset the SS line of the display will most likely be floating as it is an input, and the AVR will also have its line set to input and 2 inputs make a nice float(pun intended) and that can accidentally get high enough to pass one or 2 bytes.Specially if the CS line is in a tight bus with the ISP lines, been there done that as there was a lack of space on the board and witnessed funny things while reprogramming controllers. We are not sure how it happened, but a long long time ago we saw more or less a structured thing happening when we did reprogramming, the "garbage" on the display seemed to be parts of strings or some text strings. A colleague who watched it with me said he would check if it might not be not really random. and law and behold, he put a string in like a "hello world" IIRC it was a "Hello Marcel" and later "hello programmer" and that would pass by regularly when reprogramming, so it can happen and that is why it is a good test if you messed up a display during programming to see if your init routines work correctly.

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

meslomp wrote:
e AVR will also have its line set to input and 2 inputs make a nice float

That is why you should have either a pull down or pull upresistor on your CS line (depending on enable high or low) so it remains disabled when the micro is in reset.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
stack gold/silver https://www.onegold.com/join/713...

 

 

 

 

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

Thanks for all your answers! I think I'll settle with using USART to drive the display, it's quite simple to use and can be used as an SPI Master.