AnsweredAssumed Answered

SPI bus Slave Select on HCS08QE

Question asked by renee straney on Mar 3, 2011
Latest reply on Mar 4, 2011 by renee straney

Hi,

When I execute my code Slave select isn't going low at the correct time.

 

When I run the code below I see the proper values transmitted out MOSI (And the clock is correct) but SS_n is NOT encapsulating the data, it is shifted forward in time to about the 2nd clock and then falling.    In other words SS_n drops after the first 2 bits are transmitted.

Yet the datasheet shows that if the SPI i/f is set up as master that SS_n should drop 1/2 tSPSCLK before the first clock edge.

 

Does anyone know what the datasheet is referring to when it says DDS7=1?  I am referring to the figure on page 23 of the "MC9S08QE8 Series Data Sheet, Rev. 7". 

 

I searched both the reference manual and the datasheet for DDS and found nothing close other than PTDDS which is Port D's drive strength register. 

 

If you notice I have a couple places where I have commented out code:

    //PTBD_PTBD5 = 0;

    //PTBD_PTBD5 = 1;

 

If I change SPIC2 from 0x12 to 0x02 (In SPI_Init) and uncomment these two lines in the "SPI_Send_byte" function then SS_n works.   -BUT- I shouldn't have to do this since there is dedicated hardware in the chip to handle it for us.   (And I believe it would run slower than the dedicated hardware  - once I find what I am doing incorrectly.)  All this is doing is making SS_n GPIO and I am bit banging it.

 

I am assuming that SS_n is driven high and low (i.e. I don't need a pulldown on that line)?

 

 

#include <hidef.h> /* for EnableInterrupts macro */
#include "derivative.h" /* include peripheral declarations */

#ifdef __cplusplus
extern "C"
#endif

/****************************************
**
**        Subroutines Definition
**
****************************************/

void SPI_Init(void);
void SPI_Send_byte(unsigned char data);
#define SPI_SS    PTBD_PTBD5      // Slave Select
#define _SPI_SS   PTBDD_PTBDD5    

void main(void) {
    
    SPI_Init();

    for( ; ; )
    {
        SPI_Send_byte(0xF1);
     SPI_Send_byte(0x72);
    } // end for
    
}



void SPI_Init(void)
{
   
   SPI_SS = 1;
  _SPI_SS= 1;
 
        SPIC1 = 0x00;
        SPIC2 = 0x12;
        SPIBR = 0x00;
        (void)(SPIS==0U);
        SPIC1 = 0x52;
}
 

 void SPI_Send_byte(unsigned char u8Data)
{
    int dummy;
    while(!SPIS_SPTEF);
    dummy = SPIS;
    //PTBD_PTBD5 = 0;
    SPID=u8Data;
    while(!SPIS_SPRF);
    dummy = SPID;
    //PTBD_PTBD5 = 1;
}

 

Renee

Outcomes