I want TX transmission of SPI communication.

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

I want TX transmission of SPI communication.

1,125 Views
Oido
Contributor I
I am revising by referring to the cookbook, example and data sheet of s32k.
Get SPLDIV2 clock at 40 MHZ and 0x5900 at 1 MHZ
I want to send it to a3922 gate driver.
PTD 0 1 2 3 is being used.
Which register should I check to see that the transfer is complete?
TDF and TCF are floated as 1.
However, there is no change in the value of the current ADC part of the gate driver, so something seems to be wrong.
 
 uint16_t tx_16bits = 0x5900;
 
void LPSPI1_init_master(void)
{
PCC->PCCn[PCC_LPSPI1_INDEX] = PCC_PCCn_PCS(6) | PCC_PCCn_CGC_MASK; // 클럭활성화, 1은 SOSCDIV2 6은 SPLL
LPSPI1->CR    = 0x00000000; 
LPSPI1->IER   = 0x00000000;  
LPSPI1->DER   = 0x00000000;  
LPSPI1->CFGR0 = 0x00000000;  
  
LPSPI1->CFGR1 = 0x02000001;  
   
LPSPI1->TCR   = 0x5000000F;
 
LPSPI1->CCR   = 0x04090808;
//LPSPI1->CCR = LPSPI_CCR_SCKPCS(19)|LPSPI_CCR_PCSSCK(19)|LPSPI_CCR_DBT(38)|LPSPI_CCR_SCKDIV(38);
LPSPI1->FCR   = 0x00000003;   
 
LPSPI1->CR    = 0x00000009; 
}
void LPSPI1_transmit_16bits (uint16_t send) {
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
                                
LPSPI1->TDR = send;             
LPSPI1->SR |= LPSPI_SR_TDF_MASK; 
}
 
int main(void)
{
SOSC_init_8MHz();
SPLL_init_160MHz();
NormalRUNmode_40MHz();
PCC->PCCn[PCC_PORTD_INDEX] = PCC_PCCn_CGC_MASK; //포트D에 클럭 출력
PORTD->PCR[0] |= PORT_PCR_MUX(3); //SCK
PORTD->PCR[1] |= PORT_PCR_MUX(3); //SDI
PORTD->PCR[2] |= PORT_PCR_MUX(3); //SDO
PORTD->PCR[3] |= PORT_PCR_MUX(3); //CS=STRn
LPSPI1_init_master();
LPSPI1_transmit_16bits(tx_16bits);
    while(1)
    {
    }
}

 

0 Kudos
Reply
6 Replies

1,103 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Oido,

Please check chapter 51 of the S32K-RM:

The TCF (Transfer complete flag) field in the Status Register indicates if all transfers have completed. "In master mode when the LPSPI returns to idle state with the transmit FIFO empty, the Transfer Complete Flag will set."

Best regards,
Julián.

0 Kudos
Reply

1,089 Views
Oido
Contributor I

Hi. Thank you for your reply
Did you see the picture I attached? The tcf is 1
Does this mean anything was sent??
I want to use config5 on the a3922 gate driver
I tried to send 0b 0101(W)001 1110101010(P), but there was no response. Even though this is not a product of nxp, can I know if the price I sent is correct??
I want to know if the value I sent has not been reached.. or if the wrong value has been reached.

Of course I've also seen the data sheet for the s32k, but I still don't understand most things due to my lack of development and English skills. I really need help

Screenshot_20240313_065553_Foxit PDF Editor.jpgSP.jpg

0 Kudos
Reply

1,081 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Oido,

The transfer complete flag should be an indicator that the data has been sent. You could confirm this with a logic analyser or oscilloscope for the SPI data line. Unfortunately, support for non-NXP devices is out of this community's scope. If the gate driver is not responding, I would suggest contacting the manufacturer for support.

You could also try the lpspi_transfer examples inside the S32K1 RTD package for an example utilizing the APIs.

Best regards,
Julián

0 Kudos
Reply

1,074 Views
Oido
Contributor I

Thank you for your answer, but I still don't understand. When I write the transfer function in the main, all TDF TCF changes to 1, but the oscilloscope doesn't see the waveform
If you put it in the WHILE statement, only TDF will be changed to 1. However, I can see the waveform on the SDI CS SCK three pins. I can't measure three at the same time, and I can only measure one at a time, so the comparison seems difficult.
I referred to the LPSPI_TRANSFER example, but it was difficult to refer to it because it was a different way than me.
Also, if you put LPSPI1_transmit_16 bits(tx_16 bits) in the while statement only

void LPSPI1_transmit_16bits (uint16_t send) {
while((LPSPI1->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0); <<<<<<<<<
LPSPI1->TDR = send; /* Transmit data */
LPSPI1->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */
LPSPI_SR_TCF_MASK)>>LPSPI_SR_TCF_SHIFT==0);
}

Wait there indefinitely.

 

0 Kudos
Reply

1,048 Views
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @Oido

The LPSPI_TRANSFER example uses the API functions instead of registers like the cookbook example, using the functions like LPSPI_DRV_MasterTransferBlocking to transfer data. Could you test if the example shows activity with the oscilloscope? 

Best regards,
Julián

0 Kudos
Reply

1,046 Views
Oido
Contributor I

Okay but I'm using s32k144w 48 pins and the example is based on s32k144w 64 pins so I think it will take a lot of time to check. Also, I've never used api before, so it seems like I have a lot to look for.

0 Kudos
Reply