avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Should this code work? 4.1.1


From: Gavin Jackson
Subject: RE: [avr-gcc-list] Should this code work? 4.1.1
Date: Mon, 5 Mar 2007 08:21:04 +1300

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]