Missing byte in SPI RX using KEAZ128, MC33664TL and MC33771

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

Missing byte in SPI RX using KEAZ128, MC33664TL and MC33771

Jump to solution
3,625 Views
joaofracarolli
Contributor I

Hello,

I’m using the Kinetis KEAZ128 with the MC33664TL transceiver to communicate with a MC33771 battery cell controller.

The transceiver uses 2 SPI: one as a Master device (microcontroller to transceiver) and the other as a Slave device (transceiver to microcontroller). It transforms the information received via SPI into a format using a differential transformer pulse format, as stated in the datasheet:

img1.png

The diagram below shows the communication between the devices:

img2.png

If a bit “1” is sent through SPI, it is translated into a positive phase sine pulse. If the bit is “0”, the pulse has negative phase:

img3.png

These pulses are sent to the MC33771 via a twisted line pair. The messages from the MC33771 uses the same TPL to get to the transceiver, where they are converted to the SPI format and sent to the microcontroller.

The following picture was taken using an oscilloscope measuring the SPI0 (slave) pins. Here, we can see the the data being transmitted and received from the MC33771. Because the command and the response share the same line, the command from SPI1 (master) is echoed to SPI0 (slave). The command and response frames have 40 bits each.

img4.png

I’m sending the command READ to the MC33771, asking to read a register called SYS_CFG2. This command is composed by the frame 00 01 04 11 E8, in hexadecimal.

According to the MC33771 datasheet, when sending this frame, it is expected to receive a response composed by the frame 24 30 04 11 8F. Looking closely, that is exactly what the device is sending to the microcontroller:

scope_5.png

In my code, I’m using the processor expert generated functions to send and receive for both SPIs. The received frame is stored in a global variable called “response”, which is an array of 5 bytes (40 bits). I am using the onBlockReceived() interrupt to set a flag when 5 bytes are received by the microcontroller. I also defined a (primitive) timeout checking to avoid blocking my program when 5 bytes are not received. The chip_select() function is used to drive the CS pin to low state. I'll need more than one CS pin, so I use the "bank" parameter to choose which CS I will use.

int mc33771_command(uint8 *cmd, int bank){

            LDD_TError spierr;

       clear_buffer();

       block_sent_flag = 0;

       block_rcvd_flag = 0;             

       chip_select(bank);

             // Sending the command

       spierr = SPIMaster_SendBlock(spi_tx, cmd, FRAMESIZE);

            while(!SPIMaster_GetBlockSentStatus(spi_tx)){

          SPIMaster_Main(spi_tx);

       }

           // Monitoring the RX line ...

      spierr = SPISlave_ReceiveBlock(spi_rx, response, RESPSIZE);

        chip_select(CLEAR);       

           return get_spi_response(5000);

   }

int get_spi_response(uint16 timeout){

       uint16 timer = 0;

      // Waiting for reception to complete or the timeout

       while((!block_rcvd_flag) && (timer < timeout) ){

        Delay_Waitus(10);

        timer += 10;

    }

       // Checking if a timeout occurred

       if(timer >= timeout){

       SPISlave_CancelBlockReception(spi_rx);

       SPIMaster_CancelBlockTransmission(spi_tx);

             return SPI_TIMEOUT;

       }

       return SPI_OK;

}

The problem is, when I debug my program using Code Warrior, I see that the response variable is always missing the last byte, and the 4th byte has a strange behaviour. Sometimes it has the expected value, and sometimes it assumes the value expected for the 5th byte. The change in the value of the 4th bytes seems to occur randomly.

img6.png

This behavior is not exclusive to the KEAZ128 controller. I used the KL25Z and had the same issue.

Does anyone have any idea what’s happening?

Thanks! (Sorry for this very long text :smileyhappy:)

Labels (1)
Tags (3)
1 Solution
1,418 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Joao:

This behavior sounds like an overrun condition. See the next paragraph from the manual:

pastedImage_4.png

If this is what is happening some things you can try to fix it are:

- Increase the KEA core clock frequency.

- Use a lower SPI baudrate.

- Use a higher optimization level from the compiler. In particular optimizing for speed would help.

Your scope shows that all bytes of the response are transferred, but maybe the MCU eventually loses 1 byte. Try adding a global variable in the interrupt routine to count how many times it is triggered.

I hope this helps.


Best regards,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

4 Replies
1,418 Views
gracebaldonasa
Contributor I

Hi,

I am using MPC5748G and have exactly the same problem as the one describe in this question.

All the codes are generated using Processor Experts so I did not do any clock configuration. When I checked the clock interface, core clock is configured @ 160Mhz and SPI is using F40 which is fixed @ 40Mhz.

- increasing core clock is no longer an option

- decreasing baud rate is also not an option since I need to complete the SPI communication at certain time and based on the test I have done so far, I can achieved it @ 20Mhz.

- I will try to see this if this can help me

Any other potential solution?

Thanks,

0 Kudos
Reply
1,418 Views
崔亚飞
Contributor II

Can you share some information or routines about MC33771 ? Thank you!!!

0 Kudos
Reply
1,419 Views
Jorge_Gonzalez
NXP Employee
NXP Employee

Hello Joao:

This behavior sounds like an overrun condition. See the next paragraph from the manual:

pastedImage_4.png

If this is what is happening some things you can try to fix it are:

- Increase the KEA core clock frequency.

- Use a lower SPI baudrate.

- Use a higher optimization level from the compiler. In particular optimizing for speed would help.

Your scope shows that all bytes of the response are transferred, but maybe the MCU eventually loses 1 byte. Try adding a global variable in the interrupt routine to count how many times it is triggered.

I hope this helps.


Best regards,
Jorge Gonzalez

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,418 Views
joaofracarolli
Contributor I

Hello Jorge,

I increased the core clock frequency and it worked! :smileyhappy:

WIN.png

Thank you very much