MC9S12DG256 SPI with multiple slaves

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

MC9S12DG256 SPI with multiple slaves

跳至解决方案
1,296 次查看
ruiji
Contributor I

MC9S12DG256 SPI with two slave devices: DAC TLC5618 and ADC AD7888.

They are both connected to SPI0, but they require different SPI configurations (for TLC5618 CPHA=0, for AD7888 CPHA=1).

I found in the MC9S12DG256 datasheet that "In master mode, a change of CPHA will abort a transmission in progress and force the SPI system into idle state".

How should I implement SPI communication with these two devices in my application, or should I use different SPI ports (e.g SPI0 for DAC and SPI1 for ADC)?

 

A related question:

I developed a small application to test SPI with TLC5618:

 

main()

{

  EnableInterrupt;

  SET_PLL();

  SPI_init();

  for(;;)

  {

    SPI_send();

  }

}

 

It works correctly. If I put SPI_init() into the loop:

 

main()

{

  EnableInterrupt;

  SET_PLL();

  for(;;)

  {

    SPI_init();

    SPI_send();

  }

}

 

It does't work.

标签 (1)
标记 (2)
0 项奖励
回复
1 解答
1,021 次查看
iggi
NXP Employee
NXP Employee

Hi Rui Ji,

I agree with Daniel. There are 3x SPI on DG256. The SPI0 is on Port S (PS4-PS7) and can be routed to Port M. The SPI1 and SPI2 are on Port H (PH0-PH7) and can also be routed to Port P.

You should definitely use two different SPI ports in this case (if there are unused pins on Port H or Port P).

Regards,

iggi

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,021 次查看
ruiji
Contributor I

Thank you for your answers.

I am new in my company. I did not participate in the PCB design. Last month, they gave me the board and wanted me to make it work.

The DAC and ADC were both connected to SPI0, and the other two SPI ports were not used.

I asked them why, they sayed that they just did not pay attention to the CPHA configuration.:smileyconfused:

So can we say the PCB was not correctly designed?

Now I create two tasks in my program, AnalogToDigital ( ) and DigitalToAnalog ( ), and use a mutex to protect SPI access (I'm using uC/OS II).

CPHA is configured before I start the transmission.

void AnalogToDigital ( )

{

   OSMutexPend();

   SPI0_CR1|=0x04;

   CS=0;

   ......

   CS=1;

   OSMutexPost();

}

void DigitalToAnalog ( )

{

   OSMutexPend();

   SPI0_CR1&=~0x04;

   CS=0;

   ......

   CS=1;

   OSMutexPost();

}

It seems to be working, but I'm worried about frequent setting/clearing to the register.

0 项奖励
回复
1,022 次查看
iggi
NXP Employee
NXP Employee

Hi Rui Ji,

I agree with Daniel. There are 3x SPI on DG256. The SPI0 is on Port S (PS4-PS7) and can be routed to Port M. The SPI1 and SPI2 are on Port H (PH0-PH7) and can also be routed to Port P.

You should definitely use two different SPI ports in this case (if there are unused pins on Port H or Port P).

Regards,

iggi

0 项奖励
回复
1,021 次查看
Lundin
Senior Contributor IV

Just don't change CPHA in the middle of a data transmission and you'll be fine. The sensible solution is of course to use different SPI ports, I think you've got 3 of them on DG256?