Sending and Receiving Data //Function to send and receive data for both master and slave
unsigned char spi_tranceiver (unsigned char data)
{
// Load data into the buffer
SPDR = data;
//Wait until transmission complete
while(!(SPSR & (1<<SPIF) ));
// Return received data
return(SPDR);
}
What part of it sets the pin (MOSI) high and low to transfer bit. All i see is the awaiting for the interrupt bit (SPIF).
Does AVR MCU automatically handles all routine regarding pusling pins just by setting SPE bit to 1 ?
"To send data, load the data into the SPI Data Register (SPDR), and then, wait until the SPIF flag is set. When the SPIF flag is set, the data to be transmitted is already transmitted and is replaced by the received data. So, simply return the value of the SPI Data Register (SPDR) to receive data."
Another line from the same post - i do not expect that mcu will start transmitting as soon as i put data in data register