I am using ATMEGA128 to communicate with another device. For this I am using SPI with ATMEGA128 as slave. I use SS, SCK and MOSI pins. The problem I am facing is that when I have to download program, I have to disconnect SPI pins. The ATMEGA128 module I am using uses TXD0, RXD0, SCK(PB1) pins to download program. Why am I facing this problem ? Is it because SPI and downloading circuit uses same SCK pins ? Is there any way to avoid disconnecting SPI pins ?
Is it because SPI and downloading circuit uses same SCK pins ?
Yes, you have to prevent any other device from driving the SPI lines during programming.
Is there any way to avoid disconnecting SPI pins ?
Yes. 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.
See my answer here.