0

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.

Ganesh S
  • 21
  • 1
  • 4

1 Answers1

1

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;
}
David Grayson
  • 84,103
  • 24
  • 152
  • 189
  • rx vs tx is specific to the spi controller design, the AVRs might work this way (and from what I remember do) but that is not necessarily universal, nor required (the mosi can be fixed for a read period and not have to be driven by a shift register, likeise miso can be discarded in the logic). All depends on the design. – old_timer Nov 01 '17 at 21:56