AnsweredAssumed Answered

S08-Incorrect method in SPI Driver

Question asked by pawan kumar on Jul 30, 2015
Latest reply on Aug 3, 2015 by pawan kumar

Dear Friends,

 

Since 4 weeks, I have been exploring with MC9S08DZ60. I have two queries. I will be specific to the SPI related question here.

 

I have configured the SPI in Master mode, with Mode fault indication disabled. I am trying to use the Slave Select bit as a GPIO in order to control the pin Manually.

 

Here's a shabby code which works well to transmit data to the slave. Please find my question below the code snippet.

 

void SPISendChar (unsigned char data)

{

    while (!SPIS_SPTEF);  /* wait until transmit buffer is empty*/   

    SPID = data;  /* Transmit counter*/   

    while(!SPIS_SPTEF);

}

 

void dacfeed(char value)

{

  led1=1;

  led2=0;

  ss=0x01;

  SPISendChar(0x0F);

  delaysmall(50);

  SPISendChar(value);       //To Toggle the SS pin after the Data Transmit is over, I need to wait for delaysmall(50);

  delaysmall(50);

  ss=0x00;

  delaysmall(1);

  ss=0x01;

  led2=1;

  led1=0;

  delaysmall(10);

}

 

void delaysmall(int time)

{

  int a;

  for(a=0;a<time;a++);

}

 

The flag SPIS_SPTEF goes high immediately (within 2 SPI Clock cycles) . I could observe this through an oscilloscope. So, I need to purposefully introduce a delay with trial and error to make the protocol work suitably for a Slave DAC device. Is there no flag indicating that all the 8 clock cycles are over? Or is there any novel method to write this driver code?

 

My feeling is that there is some flag indication because the Automatic Slave select works beautifully well.

 

I would sincerely thank any help provided as I have been struggling a lot throughout this phase.

 


Thank You.
Pawan

Outcomes