Hello,
I am working on an SPI driver for the MPC5674F microcontroller, which runs at 264 MHz, and I need to calculate the timeout delay for a polling-based SPI transaction. The SPI transfer completion is monitored using the Transfer Complete Flag (TCF), with a timeout based on iteration count.
Code Snippet:
#define SPI_MAX_WAIT_ITERATIONS 100
// Wait until the transfer is complete.
// The TCF bit indicates that all bits in a frame have been shifted out.
while (p_spi_config->port->SR.B.TCF == 0)
{
if (iteration_counter++ > SPI_MAX_WAIT_ITERATIONS)
{
// If this point is reached, the SPI transfer did not complete
// within the expected iterations.
spi_status = eSPI_TIMEOUT;
iteration_exceeded = true; // Set flag to break `for` loop
break; // exit from while loop
}
}
Assuming iteration consists of:
Total per iteration ≈ 5 clock cycles
IF SPI_MAX_WAIT_ITERATIONS = 100, total cycles before timeout:
Total Cycles = 100×5 = 500
Total Time = 500×3.79 ns = 1.89 microseconds
Any insights from the community would be greatly appreciated!
Thanks in advance!
Narendra C
MPC5674F , #POWERPC ARCHITECTURE
Solved! Go to Solution.
Hi,
1) it will be more and not such straightforward you outlined. You should rather see how code is compiled and based on assembler code you can guess more, with help of instruction set states in Core manual. However another setting on MCU, like I/D caches, memory wait states, crossbar setting/latency, comes into role.
But you can use some internal timer or simply toggle some pin to measure specific code execution time.
2) Depends on actual SPI transfer/bitrate setting
3) there is TXFIFO underflow and RXFIFO overflow indication. As transfer attributes are set prior to communication, must be same on Master/Slave, and SPI is synchronous communication with serial clock no such errors are expected.
BR, Petr
Hi,
1) it will be more and not such straightforward you outlined. You should rather see how code is compiled and based on assembler code you can guess more, with help of instruction set states in Core manual. However another setting on MCU, like I/D caches, memory wait states, crossbar setting/latency, comes into role.
But you can use some internal timer or simply toggle some pin to measure specific code execution time.
2) Depends on actual SPI transfer/bitrate setting
3) there is TXFIFO underflow and RXFIFO overflow indication. As transfer attributes are set prior to communication, must be same on Master/Slave, and SPI is synchronous communication with serial clock no such errors are expected.
BR, Petr