How to use the LPSPI transfer complete flag ?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to use the LPSPI transfer complete flag ?

1,218件の閲覧回数
kalvin
Contributor I

How to generate an interrupt when LPSPI sends a frame of data (CS is negative), and what flags can be used.

E.g:
LPSPI0->IER |= LPSPI_IER_TCIE(1);
LPSPI_Interupt_Enable(LPSPI0,LPSPI0_IRQn,0xC);

void LPSPI0_IRQHandler(void)
{
LPSPI0->SR |= LPSPI_SR_TCF_MASK;
}
This will always be interrupted, is this setting wrong?

0 件の賞賛
返信
4 返答(返信)

1,202件の閲覧回数
davidtosenovjan
NXP TechSupport
NXP TechSupport

You should rather use FCF flag

davidtosenovjan_0-1664282755048.png

TCF is set whenever is transmit FIFO empty.

 

0 件の賞賛
返信

1,195件の閲覧回数
kalvin
Contributor I

//init

LPSPI0->IER |= LPSPI_IER_FCIE(1);//LPSPI_IER_TCIE

LPSPI_Interupt_Enable(LPSPI0,LPSPI0_IRQn,0xC);

//read & write

uint8_t LPSPI_ReadWriteByte(LPSPI_Type *Instance,uint8_t byte)
{
uint8_t recieve = 0;
while((Instance->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0);
/* Wait for Tx FIFO available */
Instance->TDR = byte; /* Transmit data */
Instance->SR |= LPSPI_SR_TDF_MASK; /* Clear TDF flag */

// while((Instance->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
/* Wait at least one RxFIFO entry */
recieve= Instance->RDR; /* Read received data */
Instance->SR |= LPSPI_SR_RDF_MASK; /* Clear RDF flag */
return recieve; /* Return received data */
}

void Spi_Transfer(LPSPI_Type *Instance,uint8_t *TxBuffer,uint8_t *RxBuffer,uint32_t length)
{
uint32_t i = 0;
Instance->TCR |= LPSPI_TCR_CONT(1)|LPSPI_TCR_CONTC(1);
for(i = 0;i<length;i++)
{
RxBuffer[i] = LPSPI_ReadWriteByte(Instance,TxBuffer[i]);
}
Instance->TCR &= ~LPSPI_TCR_CONTC_MASK;
Instance->SR |= LPSPI_SR_FCF_MASK;
}

//IRQ

void LPSPI0_IRQHandler(void)

{

LPSPI0->SR |= LPSPI_SR_FCF_MASK;

//LPSPI0->SR &= ~LPSPI_SR_FCF_MASK;

}

 

I can't transfer data according to the above settings, I don't know how to set it now.

0 件の賞賛
返信

1,192件の閲覧回数
kalvin
Contributor I

Hi @davidtosenovjan , Do you have a reading and writing method for the LPSPI register version? I think there is still a problem with my reading and writing?

0 件の賞賛
返信

1,183件の閲覧回数
davidtosenovjan
NXP TechSupport
NXP TechSupport

I would use RDF and TDF flags, either for interrupt or polling methods.

0 件の賞賛
返信