MC9S12DG256 SPI with multiple slaves

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MC9S12DG256 SPI with multiple slaves

Jump to solution
955 Views
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.

Labels (1)
Tags (2)
0 Kudos
1 Solution
680 Views
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

View solution in original post

0 Kudos
3 Replies
680 Views
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 Kudos
681 Views
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 Kudos
680 Views
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?