SPI communication between MM9Z1J638 and MC33879

cancel
Showing results for 
Search instead for 
Did you mean: 

SPI communication between MM9Z1J638 and MC33879

407 Views
buraksoner
Contributor II

Hello,

 

I'm using the MM9Z1J638-based 4-cell lithium ion battery management system reference design shown in the link below:

 

MM9Z1_638, 4-Cell Lithium Battery|NXP

 

In the example software provided for this, the following line is used for SPI communication between the MM9Z1J638 and MC33879.

u16SPIResult = SPITransfer16bit2(u16SPIData);

 

This function sends 2 SPI messages to MC33879 and reads the SPIDR twice, returning the received message in the second SPIDR read:

 

/*! \brief  Transmits a 16bit value via SPI and receives a 16 bit value.

    The transfer is performed twice to receive status feedback.

  @param[in]  u16Data    16bit data to be transmitted

  @param[out] u16        returns 16bit data received 

  \todo operation timeout is missing! Statusbits 

*/

u16 SPITransfer16bit2(u16 u16Data)  {

  while (!SPISR_SPTEF) DO_NOTHING;   //Wait for empty data register         

    SPIDR = u16Data;                     //transmit a 16-bit word (1)

    while (!SPISR_SPIF) DO_NOTHING;   //Wait for receiving data

    (void) SPIDR; //dummy read

 

  while (!SPISR_SPTEF) DO_NOTHING;   //Wait for empty data register         

    SPIDR = u16Data;                     //transmit a 16-bit word 

    while (!SPISR_SPIF) DO_NOTHING;   //Wait for receiving data

    return SPIDR; // contains status data from first write operation (1)

}

 

The comments above the function state that it does this to get status feedback from the MC33879. According to the datasheet of the MC33879 though, this would also be achieved with a single transmit (which could be triggered with the " SPITransfer16bit() " function in the example code). Quote from the MC33879 datasheet:

 

"On each SPI communication, a 16-bit command word is sent to the 33879 and a 16-bit status word is received from the 33879."

 

Is there a specific reason why this double transmit function is used? Although the MC33879 datasheet states it's possible, is it not possible to get a status feedback from the MC33879 with a single transmit?

 

Thanks!

Burak

Labels (1)
Tags (3)
0 Kudos
2 Replies

95 Views
Q_man
NXP Employee
NXP Employee

As stated in the MC33897 datasheet ("Fault Register, shown in Table 6, defines the previous state

status of the output driver.") the second read is required to get the latest status in case an output was changed.

0 Kudos

95 Views
iggi
NXP Employee
NXP Employee

Hi Burak,

As per my understandings, and there is written as the last comment of SPI transfer function (return SPIDR), the second transfer is performed so we can get the status data from the first operation.

If we would do only one transfer, we would get status data back (as stated in MC33897 datasheet), but this would not be related to this current transfer i.e. write. So, the second transfer is performed to get the most actual status, i would say.

Regards,

iggi

0 Kudos