Hello Jose, and welcome to the forum.
Within the code that you have posted, I cannot see where you are attempting to set SS2 low. Do you actually mean SS1 or SS2?
However, I do have a comment about your DAC_write() function. I notice that you are testing only the SPTEF flag, and have implemented a delay for the SPI transfer to complete.
Even though you have no interest in the MISO data, after each byte is sent it is still necessary to wait until the SPRF flag is set, and to then clear this flag by reading the SPID register. This approach will mean that the delay can be eliminated, since the transfer will already be complete when the flag becomes set. It will also prevent an overrun condition from occurring, and possible "latch up" of the SPI module.
The SPTEF flag is relatively unimportant, since it will always be set prior to each byte being sent.
When debugging the SPI code, it is possible that you may not be able to single step since the debugger itself may provide the conditions to clear the SPRF flag, resulting in the wait loop never exiting. Place a breakpoint after the wait loop for predictable operation.
Regards,
Mac
Message Edited by bigmac on 2010-01-20 03:07 PM