0
votes

When will SPIF bit in SPSR will reset after transmission of data Suppose

void SPITransmit(uint8_t data)
{
    SPDR = data;
   while(!(SPSR & (1<<SPIF)));
 }

After transmission SPIF will set and how to reset this bit for reception.

1

1 Answers

1
votes

With SPI, you don't get to choose whether you are sending or transmitting, you do both at the same time. So there is no need to "reset SPIF for reception". I believe the received data is available in the SPDR register after your loop terminates, but you should read the datasheet for your particular AVR to make sure.

Here is a function you could use to transmit and receive at the same time:

uint8_t SPITransmit(uint8_t data)
{
  SPDR = data;
  while(!(SPSR & (1<<SPIF)));
  return SPDR;
}