Half Word Sending Issue in SPI Code

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

Half Word Sending Issue in SPI Code

4,022 Views
Dilip1441
Contributor I

Hi,

I'm Using LPSPI_s32k144 Example SPI Code, For Sending Data over the SPI the Below API is used in the code at-->LPSPI1_transmit_16bits(tx_16bits);/* Transmit half word (16 bits) on LPSPI1 */

 

Issue: What ever the Data/Value sending over the Above API or above Code(Ex Tx Data 0x08), Half of the Data only received on the Slave End(Ex Rx Data 0x04). 

Ex:

tx_16bits = 0x08;

LPSPI1_transmit_16bits(tx_16bits);

Received value at the Slave side: 0x04

Similarly Tx Data-FFD0

               Rx Data-7E80

 

Please give the Clarification on this issue, Why i'm getting this half of the Data/Value?

 

0 Kudos
21 Replies

3,984 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi Dilip1441,

How did you configure the CPHA and CPOL of slave device? Here you can refer to the signal captured by external logic analyze.

S32K144_Project_LPSPI CPHA1 CPOL0.png


Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

3,981 Views
Dilip1441
Contributor I

Hi,
Thanks for the Reply.

Actually Here the Master is S32K144 and Slave is Arduino uno,

Please fine the attachment for Arduino Uno Slave Code.

 

Issue:

 

Sending Value from Master(S32k144) 0x06

Receiving Value on Slave(Arduino Uno) 0x03

0 Kudos

3,978 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Oh. Sorry. I don't know how the use Arduino uno. Would you please check the setting of Clock polarity and phase of your slave are same as S32K144?

1920px-SPI_timing_diagram2.svg.png

0 Kudos

3,966 Views
Dilip1441
Contributor I
Hi,
The Clock polarity and phase of Arduino uno is same as s32k144
but still i'm facing the issue.
Tx value 0x06
Rx value 0x03

Please help me on this issue
0 Kudos

3,964 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

May I ask if you have other slaves, such as a logic analyzer, to check the data sent by the S32K and upload pictures.
In addition, please try to use a logic analyzer to communicate with your slave Arduino uno to see if the data is sent and received normally.

0 Kudos

3,894 Views
Dilip1441
Contributor I

Hi, Now i'm using lspi_transfer_s32k144(SDK) Example Code, Using that code i'm trying to communicate LTC6813(ADC Board), Before Data Writing to the ADC Over the SPI, I need to Wakeup the ADC by CS Pin after that need to Write the Data.

But Unable to control the CS Pin Separately, Please check the below code, and PFA For the Required Wakeup Signal From Master-S32K144(Attached Screen shot signals are generated from Arduino Uno)

PINS_DRV_SetPinsDirection(PTB,(1 << 5));
PINS_DRV_SetPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_ClearPins(PTB,(1 << 5));
OSIF_TimeDelay(500);

while(1)
{
LPSPI_DRV_MasterTransferBlocking(LPSPICOM1, tx, rx, 2, SPI_TIMEOUT);
OSIF_TimeDelay(5000);
}

 

Question:

How to control the CS Pin Manually/General Purpose Output as well as CS Pin in SPI

 

Please guide me and do the Needful.

 

 

 

Thanks in Advance.

I'm Attaching the Screenshot 

0 Kudos

3,885 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

When you configure PTB5 as LPSPI0_PCS0, ALT4 is selected for the MUX. If you want to use it as GPIO output, you may need to change the MUX to ALT1(PTB5). When you want to use it as CS pin, then you need to change MUX back to ALT4 again.

Please have a try. Hope it helps.

PTB5 ALT4 LPSPI0_PCS0.png

0 Kudos

3,880 Views
Dilip1441
Contributor I
Hi, Thanks for the Reply.

Is it possible to control the CS Pin Manually using below functions for specific pulse generation(For changing my slave from Sleep mode to Wakeup mode) before sending data over SPI.

PINS_DRV_SetPins(PTB,(1 << 5));
PINS_DRV_ClearPins(PTB,(1 << 5));


If it is possible please share the required steps
0 Kudos

3,877 Views
Dilip1441
Contributor I

One more Query,

After Sending the Complete data over the SPI Only the CS Pin State need to change like below attached Format.

but in our example code if i'm sending 2 bytes of data using below code

uint8_t tx[2] = {0x25, 0x30};

LPSPI_DRV_MasterTransferBlocking(LPSPICOM1, tx, rx, 2, SPI_TIMEOUT); 

 

The CS Pin state is changing(one time low to high) after sending every 1 byte

 

but i want after completion of complete data sending only the CS Pin State need to change

0 Kudos

3,873 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Did you enabled PCS continuous?

PCS continuous.png

0 Kudos

3,871 Views
Dilip1441
Contributor I
I didn't enabled PCS continuous-is it required?
0 Kudos

3,867 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

According to your previous description, you should choose Continuous mode:

AN5320 Continuous mode.png

0 Kudos

3,879 Views
Dilip1441
Contributor I
If you want to use it as GPIO output, you may need to change the MUX to ALT1(PTB5). When you want to use it as CS pin, then you need to change MUX back to ALT4 again.

Is there any API or Register for above changes So that over the code i'll control Single Pin as GPIO as well CS Pin as per my requirement
0 Kudos

3,874 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Have you tried the PINS_DRV_SetMuxModeSel mentioned in my last reply?

PINS_DRV_SetMuxModeSel(PTB,5U,PORT_MUX_AS_GPIO);
PINS_DRV_SetPinsDirection(PTB,(1 << 5));
PINS_DRV_SetPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_ClearPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_SetMuxModeSel(PTB,5U,PORT_MUX_ALT4);
0 Kudos

3,866 Views
Dilip1441
Contributor I

Hi,

Thanks for the Reply.

Added below code in my project and enabled PCS Continuous.

PINS_DRV_SetMuxModeSel(PTB,5U,PORT_MUX_AS_GPIO);
PINS_DRV_SetPinsDirection(PTB,(1 << 5));
PINS_DRV_SetPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_ClearPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_SetMuxModeSel(PTB,5U,PORT_MUX_ALT4);

while(1)
{
LPSPI_DRV_MasterTransferBlocking(LPSPICOM1, tx, rx, 2, SPI_TIMEOUT);
OSIF_TimeDelay(5000);
}

 

PFA For the Captured Wave Forms.

1.PCS Continuous is Working fine.

2.PTB-5 is not Working as we expected as per above code

 

Can you please guide me the Required Steps for this Requirement.

 

Thanks in Advance.

0 Kudos

3,853 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Sorry. PINS_DRV_SetMuxModeSel should use PORT_Type
Please have a try:

PINS_DRV_SetMuxModeSel(PORTB,5U,PORT_MUX_AS_GPIO);
PINS_DRV_SetPinsDirection(PTB,(1 << 5));
PINS_DRV_SetPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_ClearPins(PTB,(1 << 5));
OSIF_TimeDelay(500);
PINS_DRV_SetMuxModeSel(PORTB,5U,PORT_MUX_ALT4);

I did not debug it, so not sure whether your code works. 
About the PINS_DRV_SetMuxModeSel, please check if the MUX value of PORTB_PCR[5] is change during debug.

0 Kudos

2,505 Views
saman001
Contributor I

Hi Ronin,

I am facing the same issues now.

could you please let me know if you have solution for it.

my problem is that the CS seems not working at all with the lpspi_drv_mastertransferblocking function. 

Kind regards

saman.poushpas@gmail.com

0 Kudos

3,850 Views
Dilip1441
Contributor I

Hi,

Thanks for the Reply.

Modified the Code as per your Guidance thanks for your support.

PTB-5 is working fine as we expected(GPIO and CS).

But one unknown observation is there before expected Result may be that is due to Pin Mode Changings.

Can you please check the attached Screenshots once and please guide me to overcome that unknown state changes.

Before attaching our code also(Using Direct Example code without any changes) also i observed that state change in SCK pin.

0 Kudos

3,847 Views
Dilip1441
Contributor I
How to overcome that unknown state changes in CS pin also in SCK pin.
0 Kudos

3,792 Views
Dilip1441
Contributor I
Hi, Can you please check the above Query and Please suggest me to overcome that issue.
0 Kudos