Ciao,
La libreria (che non ho scritto io, non conosco al momento i dettagli di SPI) scrive solamente per inviare i comandi e non legge mai dal device.
Ha questa funzione che scrive due word da 8 bit di seguito:
/*************************************************************************
Function: SPI_write16()
Purpose: send a 16bit word to the AD9833
Input: unsigned short data = 16bits
Comment: uses 8bit filter and two consecutive writes while fsync stays low
**************************************************************************/
void SPI_write16 (unsigned int data) // send a 16bit word and use fsync
{
unsigned char MSdata = ((data>>8) & 0x00FF); //filter out MS
unsigned char LSdata = (data & 0x00FF); //filter out LS
PORTB &= ~_BV(PB0); // Fsync Low --> begin frame
SPDR = MSdata; // send First 8 MS of data
while (!(SPSR & (1<<SPIF))); // while busy
SPDR = LSdata; // send Last 8 LS of data
while (!(SPSR & (1<<SPIF))); // while busy
PORTB |= _BV(PB0); // Fsync High --> End of frame
}
Quindi mi suggerisci di inserire l'istruzione:
SPDR;
Dopo ogni while (non ho ben capito cosa fa, serve quindi per leggere il registro ed evitare hazard conditions?)
Ciao e grazie