Hello,
The most likely cause of this problem is a COP reset occurring while you are within a wait loop in your SPI communications function. Here I assume that you would be waiting for the SPRF flag to become set. It is possible for the normal register read operation of the debugger to clear the flag before your code can detect that the flag has become set, so that the wait loop would then never exit.
By stepping over the function, the debugger does not read the SPI registers within the wait loop, so the correct operation of the function occurs.
Regards,
Mac