AnsweredAssumed Answered

MC9S12DG128 SPI Port

Question asked by Gordon Pocock on Apr 20, 2017
Latest reply on Apr 21, 2017 by Gordon Pocock

I am having trouble trying to get the SPI port working on an MC9S12DG128 (80 pin variant). Previously, I have used the MC9S12C128 processor (48 pin variant), and used the SPI port with no problems. Basically, I have tried to use the same initialization and operational code on both processors. Both processors are using an 8MHz oscillator, and the initialization code is as follows:

SPI0CR1 = 0x50;
SPI0CR2 = 0x00; // normal mode
SPI0BR  = 0x04; // 24MHz/32=750kHz


My SPI routines are:


void SPIOut(unsigned short usCode)
    PTM &= ~0x08;       // PM3=chip select=0 
    SendSPI(usCode>>8); // msbyte (command)
    SendSPI(usCode);    // lsbyte (data)

    PTM |= 0x08;        // PM3=chip select=1

void SendSPI(unsigned char ucCode)
    unsigned char ucDummy;
    while((SPI0SR & 0x20)==0){}; // wait SPTEF
    SPI0DR = ucCode;             // data out
    while((SPI0SR & 0x80)==0){}; // wait SPIF
    ucDummy = SPI0DR;            // clear SPIF


As you can see, I manually toggle the SS pin for each data transfer.

In terms of connections, I am using the following pins:

70   PM5/SCK0

71   PM4/MOSI0

72   PM3/SS0

73   PM2/MISO0


Is there some subtle difference between the two processors that I'm not aware of? Any help with this would be gratefully appreciated.