Hello,
The problem would appear to be with the putchar_spi() function.
void putchar_spi(int cx) {
int temp;
while(!(SPISR & 0b00100000)); /* wait until write is permissible */
SPIDR = cx; /* output the byte to the SPI */
while(!(SPISR & 0b10100000)); /* wait until write operation is complete */
temp=SPIDR; // clear the spif flag.
}
In the second while loop, you are waiting until either SPTEF or SPIF becomes set. However, the write operation will not be complete until SPIF becomes set, whereas SPTEF will become set again a very short while after SPDR is written. So the function would be prematurely exiting.
The second while loop should test only the SPIF flag.
Regards,
Mac