S08-Incorrect method in SPI Driver

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

S08-Incorrect method in SPI Driver

跳至解决方案
750 次查看
pawankumar
Contributor III

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

标签 (1)
标记 (2)
1 解答
509 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello pawan,

I know your meaning .

After i checked the Data sheet , i think there is not the flag to show finish the data send .

While , for  the SPI is full duplex , so we can use the read flag (SPRF) , After the  SPRF to be set , then read teh SPIX_D, then togging the GPIO.

The detail information you can refer to here :

L-Series SPI GPIO CS/SS  . this doc is for kinetis L series chip, while the theory is the same , you can test it .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

在原帖中查看解决方案

4 回复数
509 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Pawan,

(1) About "Is there no flag indicating that all the 8 clock cycles are over?" , the bit of SPTEF of SPIS register is . You can refer to the Data Sheet of S08DZ60.

"

SPTEF is automatically set when a data byte transfers from the transmit buffer into the transmit shift register.

"

(2) Sorry i do not clearly know your demand , what problem does your code have ? Does it can not transform data ? or what ?

BR

Alice

0 项奖励
509 次查看
pawankumar
Contributor III

Hi Alice,

Thanks for the reply. Am sorry that I wasn't able to make it clear. Let me try to describe my issue in brief.

After I check for SPTEF flag, I transmit data to SPID register. Again, I wait till the SPTEF flag gets '1'.  Now, this event happens at the 2nd SPI clock cycle, not waiting till all the 8 clock cycles get completed. I am manually toggling the GPIO for Slave Select.

I want to implement a proper function for this without me introducing a random calculated delay till the 8 clock cycles get complete.

Your help would be useful to me.

Pawan.

0 项奖励
510 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello pawan,

I know your meaning .

After i checked the Data sheet , i think there is not the flag to show finish the data send .

While , for  the SPI is full duplex , so we can use the read flag (SPRF) , After the  SPRF to be set , then read teh SPIX_D, then togging the GPIO.

The detail information you can refer to here :

L-Series SPI GPIO CS/SS  . this doc is for kinetis L series chip, while the theory is the same , you can test it .

Hope it helps


Have a great day,
Alice

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

509 次查看
pawankumar
Contributor III

Hi Alice,

This work around seems interesting.

Just had a glimpse of the article. Am now going to read it fully and experiment on it.

Thanks for the Suggestion.

Update : Thank you so much Alice! This solution works perfectly for me... Keep helping me!!

Pawan

0 项奖励