MC9S12DG128 SPI Port

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

MC9S12DG128 SPI Port

726 次查看
gordonp
Contributor III

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.

2 回复数

570 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi,

Have you routed SPI0 to the M port?

MODRR = 0x10;   // SPI0 routed to port M[2..5]

Both MCUs have different modules: S12DG (S12SPIV2/D), S12C(SPIV3), although the register description is the same.

I have attached an example for S12DT(S12SPIV2/D), it should help.

Regards,

Daniel

570 次查看
gordonp
Contributor III

Hi Daniel

Thanks very much for your help. I thought it might be something simple like this!

Regards

Gordon

0 项奖励
回复