Hello,
The SPIF flag is cleared by first reading SPI0SR (when the flag is set), and then reading SPI0DR. But I presume you are already doing this to ascertain the received byte value.
The SPTEF flag is automatically set and cleared, to indicate when further (return) data may be loaded to the send buffer. No specific action is required. If the interrupt occurs as a result of the SPIF flag becoming set, the send buffer will always be ready to accept a return byte, without the need to check the SPTEF flag. It is very desireable that the return byte be loaded to the buffer from within the SPI ISR.
I am still considering the possibility that your problem may be one of tiiming. Perhaps you should verify, using an oscilloscope, that the clock line remains idle for a period of 10 microseconds between the sending of each byte, and that the SS line also remains high for a similar period. This would give a period of about 18 microseconds between successive SPI interrupts at the slave MCU.
You did not mention the bus frequency you are using. For example, using a 30MHz bus, an interrupt would occur every 540 cycles. In practice, the SPI ISR execution should occupy a fraction of these cycles, and must definitely never exceed this number of cycles under worst case conditions. The return data would need to be loaded to the transmit buffer well within 300 cycles from the SPIF flag becoming set (not necessarily the commencement of the ISR code, which might be delayed).
This would be the case if the SPI is the only interrupt. If you have other interrupts, these will potentially delay the SPI interrupt by their execution cycles, and may possibly multiple interrogations for SPI return data. Of course, you may choose to allow the use of nested interrupts, but the additional complexity of their implementation and control will add furher cycles to the processing of each SPI interrupt. It is quite possible that, to allow for these additional delay considerations, you may need to increase the period between SPI transactions to well beyond 10 microseconds.
Perhaps you could try increasing the gap, and see whether this improves your current difficulty.
Regards,
Mac
Message Edited by bigmac on
2008-03-10 10:59 PM