AnsweredAssumed Answered

Writing to SPID register in SPI slave mode has no effect (MC9S08QG8)

Question asked by Claudi Martinez Hernandez on Mar 15, 2017
Latest reply on Mar 20, 2017 by Michael Fugere

I'm having serious problems with MC9S08QG8 device when working in SPI slave mode. Particularly I have no way to set the data to be transmitted to the master device because writing to SPID has no effect. I've isolated the problem to the minimum expression and all I can see is that, when the master starts a transfer, the contents are correctly moved to the slave's shift register, which can be successfully read by reading SPID. Further transfers show how the previous shifted word is successfully output by the slave to the master, so everything is working OK in hardware level.

However if I attempt to write to SPID (in the slave device) before any transfer starts, the shift register is never loaded and the slave outputs the last word that master sent.

 

I'm using Processor Expert to setup the SPI bean and, to make things simpler, I disabled interrupts and just preload SPID with a sample byte (=0xAA). However, when the very first transfer starts, the slave outputs always 0x00 (default value upon reset), thus ignoring the fact I wrote 0xAA to SPID. 

 

I have followed the datasheet guidelines and I can assert that SPIS is read and checked for SPIS[SPTEF] to be 1 immediately before writing SPID, but the problem is always there.

 

The init code generated by Processor Expert is:

    void SSI_Init(void)
    {
        SPIS;  //Read SPIS
        SPID;  //Read SPID
        setReg8(SPIC2, 0x00);
        setReg8(SPIC1, 0x00);
        SPIC1_SPE = 1; //Enable SPI
    }

 

The main() code (after PE initialization) is:

    //Read SPIS and check SPTEF is set. This always happens upon startup.
    if (SPIS_SPTEF) {
        //Output sample byte
        SPID = 0xAA;
    }
    //Main loop
    for(;;){}

I start the master transfer after the code enters the main loop, and as I told before, the slave outputs 0x00 instead of 0xAA. 

Outcomes