Hello,
There is an additional requirement, that an overrun condition must not occur, or further byte transfers will fail. Therefore the SPRF flag must be cleared three times, each prior to the completion of transfer of the next byte. This would apply even if you have no interest in the return data.
Some untested code -
while (!SPIS_SPTEF);
SPID = adres;
while (!SPIS_SPTEF);
SPID = data1; // Second byte queued to buffer
while (!SPIS_SPRF); // Wait for completion of first byte
(void)SPID; // Clear flag to prevent overrun
while (!SPIS_SPTEF);
SPID = data1; // Third byte queued to buffer
while (!SPIS_SPRF); // Wait for completion of second byte
(void)SPID; // Clear flag to prevent overrun
while (!SPIS_SPRF); // Wait for completion of third byte
(void)SPID; // Clear flag
Interrupts should be disabled prior to starting this process, otherwise it is possible for an overrun to occur while an unrelated interrupt is serviced, especially with a fast SPI clock.
Regards,
Mac