Another thing you may want to take a look at is the SPIF
flag on page 174 of the datasheet. It states that:

When a serial transfer is complete, the SPIF flag is set.
An interrupt is generated if SPIF in SPCR is set and global
interrupts are enabled... SPIF is cleared by hardware when
executing the corresponding interrupt handling vector.
Alternatively, the SPIF flag bit is cleared by first reading
the SPI status register with SPIF set, then accessing the SPI
data register.

>From what the datasheet says, your SPIF bit is never cleared
so you'll be overwriting the SPI data register contents before
they've been transmitted.

void SPI_MasterTransmit(char cData)
{
   /* Start transmission */
   SPDR = cData;

   /* Wait for transmission complete */
   while(!(SPSR & (1<<SPIF)))
     ;
}

Cheers

Gavin


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Reply via email to