I'm trying to interface a ATmega128 to a MMC (MultiMediaCard) via the SPI port direct. Not through any additional external hardware or through a serial interface.
I can initalize the SPI port and write/transmit out the SPI port. I monitor it with a scope. The clock SCK is active during transmit and the SS line goes low to enable the receiving device. I send a reset command (40-00-00-00-00-95h) to the MMC card to place the card in SPI mode, and follow that up with a several status commands (41-00-00-00-00-xxh). Sometimes I get a reply, which I monitor with the scope, but it is reading the data back in that I'm finding difficult.
I read the SPDR port which should be reading in the most recent value out of the serial shift register. The value I'm expecting back is the status of the last command in R1 format, a single 8 bit byte containing possible error codes rom the MMC for the last command received.
To properly read do I wait for a SPIF flag (SPSR bit 7)? If the SPDR port is a bidrectional port used for both read and write data, is the SPIF flag used to inidicate a complete transmission and a complete reception?
Also to complete a 8bit transfer from the Atmega128 to a Slave SPI device it is necessary to have SS low and SCK active for a set number of cycles after trnsmision to allow for the recieving device to read it into it's register and generate a response. How do I keep clock active from ATmega128, (the Master), with sending a command?
Thanks for anyones help