bfehrenbach

SPI simulation MC9S08AW32

Discussion created by bfehrenbach on Nov 4, 2009
Latest reply on Nov 5, 2009 by bfehrenbach

I am trying to use the SPI port to send bits to a serial in, parallel out LED driver.  I want to send 4 bytes, stored in a long: "current_status".  SPI data coming back is ignored.  My timer heartbeat clears a counter and enables the transmitter buffer empty interrupt of the SPI every 10 ms.  

 

The SPI interrupt service routine:

 

__interrupt void isrVspi1(void)

{   

    uint8 temp;

 

    temp = SPI1S;      // Clear interrupt request

    SPI1D = current_status.u_8[update_counter];    // Send next byte

    update_counter++;    

    if(update_counter >=3)

        {

            SPI1C1_SPTIE = 0;      // Disable SPI interrupts

        }

}

 

The first time that the timer enables this interrupt after power up, the ISR executes and immediately upon exit it is called again as expected.  The first pass loads the first byte which is immediately transferred to the SPI shift register and the input buffer is available for the second byte.  During execution of the second pass, the SPTEF flag in SPI1S is cleared as expected but NEVER GETS SET AGAIN so no further interrupts occur.  

 

SPI setup:

 

    SPI1C1 = 0x50;    /* SPI XMIT buff empty interrupt not enabled (yet),

                        Master, clk idles low, phase: 0 mode, MS bit first */

    SPI1C2 = 0;       /* (Default)  SS not used, xmit/rcv lines separate */

    SPI1BR = 0x73;     /* Baud rate prescaler = 8, divider = 16.  20MHZ/128 = 156.25 K baud */

 

Note: This has all been done using the simulator.  I am waiting on hardware.

 

Is there a problem with the simulator or is this PEBCAK?

Outcomes