Hello bigmac
Firstly thank you for your prompt reply. I really appreciate it.
" Since you are not waiting for the SPRF flag to become set before raising the SS signal at PTCD2, SPI communications will be prematurely aborted at the slave. After the flag becomes set, you will then need to clear the flag. In the process of doing this, you may as well return the received byte value (via MISO), to provide a more general SPI function. "
Based on your suggestion atated above, I modified the code as
void SPISendChar(unsigned char data)
{
while (!SPIS_SPTEF && PTCD_PTCD3); /* Wait until transmit buffer is empty */
PTCD_PTCD2 = 0; /* Select slave */
read = SPIS; /* read SPIS whe SPTEF = 1 to initiate a transfer */
SPID = data; /* Start to send data */
while (!SPIS_SPRF) /* wait till the byte is recieved */
(void)(SPIS == 0); // clear flag
PTCD_PTCD2 = 1; /* Un-select slave */
}
If I do this I think I am getting stuck in a infinite loop as the SPRF flag is reset on the instruction "While(!SPIS_SPF)" (Refer the attachment No:1).
So I tried to add a delay after writing to the SPID so that the data transfer is not prematurely aboted. It goes like this
void SPISendChar(unsigned char data)
{
while (!SPIS_SPTEF && PTCD_PTCD3); /* Wait until transmit buffer is empty */
PTCD_PTCD2 = 0; /* Select slave */
read = SPIS; /* read SPIS whe SPTEF = 1 to initiate a transfer */
SPID = data; /* Start to send data */
for (tmp=0;tmp<50;tmp++); /* wait till the byte is recieved */
(void)(SPIS == 0); // clear flag
PTCD_PTCD2 = 1; /* Un-select slave */
}
Then I see that I am not stuck in a loop, but as usual there is no clock and no data on the MOSI pin (Refer the attachment No:2).
Any more suggestions please..
Regards
Kvkk