Hello !
I have two different codes that read a 512 byte buffer from an SD card using SPI. The first one is mine and the second is taken from sdfatlib. They appear to be equivalent, however :
in the first one, the pause between SPI reads is 2.75 ?s :
for (uint16_t i = 0; i < 512; i++) {
SPDR = 0xFF;
while (!(SPSR & (1 << SPIF)));
buffer[i] = SPDR;
}
and in the second one, time drops to 1.75 ?s, which means 8 less clock cycles on my Arduino Pro 8 MHz. That is some difference !
SPDR = 0xFF;
for (uint16_t i = 0; i < 511; i++) {
while (!(SPSR & (1 << SPIF)));
buffer[i] = SPDR;
SPDR = 0xFF;
}
// wait for last byte
while (!(SPSR & (1 << SPIF)));
buffer[511] = SPDR;
Still, I can not explain the above difference, so I would really appreciate any help