Specifically, at the moment, I am trying to make the WaveHC lib work properly with the SD card on USART0, but I am having trouble figuring out which registers and bits correspond to one another.
Here's the code I'm currently stuck on:
inline void spiSend(uint8_t b)
{
SPDR = b; // Writing to the register initiates data transmission.
while(!(SPSR & (1 << SPIF))); // Checks SPIF bit in SPSR. When a serial transfer is complete, the SPIF Flag is set.
}
inline uint8_t spiRec(void)
{
spiSend(0XFF); // Transmit 0xFF. I guess this tells the SPI card to send a byte?
return SPDR; // Read byte returned.
}
And here's some notes I copied from the datasheet:
SPDR - Pg 173:
The SPI Data Register is a read/write register used for data transfer between the Register File
and the SPI Shift Register. Writing to the register initiates data transmission. Reading the register
causes the Shift Register Receive buffer to be read.
SPSR contains: (Pg 172)
• Bit 7 – SPIF: SPI Interrupt Flag
When a serial transfer is complete, the SPIF Flag is set. An interrupt is generated if SPIE in
SPCR is set and global interrupts are enabled. If SS is an input and is driven low when the SPI is
in Master mode, this will also set the SPIF Flag. SPIF is cleared by hardware when executing the
corresponding interrupt handling vector. Alternatively, the SPIF bit is cleared by first reading the
SPI Status Register with SPIF set, then accessing the SPI Data Register (SPDR).
The datasheet is here:
And I found this document on using the USART in SPI mode, but it doesn't give a 1:1 mapping for registers:
http://www.atmel.com/Images/doc2577.pdf