SPI on MKV58F1M0VLQ24

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

SPI on MKV58F1M0VLQ24

跳至解决方案
483 次查看
john71
Senior Contributor I

On MK10FN1M0VLQ12 I did this way

 

uint32_t SPI_TransferByte(uint32_t spi_num, uint8_t tx_data, uint8_t *rx_data)
{
	uint32_t timeout;

	SPIx[spi_num]->PUSHR = SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((uint32_t)tx_data);

	timeout = 0;
	while (!( SPIx[spi_num]->SR & SPI_SR_TCF_MASK))
	{
		if (timeout++ > SPI_TIMEOUT)
		{
			 SPIx[spi_num]->SR = SPI_SR_TCF_MASK;
			return SPI_TIMEOUT_ERROR;
		}
	}

	timeout = 0;
	while (!(SPIx[spi_num]->SR & SPI_SR_RFDF_MASK))
	{
		if (timeout++ > SPI_TIMEOUT)
		{
			 SPIx[spi_num]->SR = SPI_SR_RFDF_MASK;
			return SPI_TIMEOUT_ERROR;
		}
	}

	*rx_data = (uint8_t)SPIx[spi_num]->POPR;

    SPIx[spi_num]->SR = SPI_SR_TCF_MASK | SPI_SR_RFDF_MASK;

	return 0;
}

 

And it work very good.

So I did the same on MKV58F1M0VLQ24

 

uint8_t SPI_TransferByte(SPI_Type *base, uint8_t tx_data)
{
	uint32_t timeout = 0;

 base->PUSHR = SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((uint32_t)tx_data);

    while ((base->SR & SPI_SR_TCF_MASK) == 0)
    {
    	if (timeout++ > 100000)
    	{
    		base->SR |= SPI_SR_TCF_MASK;
    	  	break;
    	}
    }
    base->SR |= SPI_SR_TCF_MASK;
    timeout = 0;

    while ((base->SR & SPI_SR_RFDF_MASK)==0)
    {
        if (timeout++ > 100000)
        {
        	base->SR |= SPI_SR_RFDF_MASK;
            break;
        }
    }
    base->SR |= SPI_SR_RFDF_MASK;

   return (uint8_t)(base->POPR);
}

 

And I stay in

while ((base->SR & SPI_SR_TCF_MASK) == 0)

the flag always low.

What  I did wrong?

0 项奖励
1 解答
467 次查看
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Before writing data to PUSHR you need to clear the MCR[HALT] field to start the transmission, also please check if the module is enabled, otherwise writing to PUSHR has no effect.

The code stays in "while ((base->SR & SPI_SR_TCF_MASK) == 0)" while the transfer is still in progress.

I suggest you refer to the SDK examples, there you can functions that will help you with this.

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar

在原帖中查看解决方案

1 回复
468 次查看
Omar_Anguiano
NXP TechSupport
NXP TechSupport

Hello

 

Before writing data to PUSHR you need to clear the MCR[HALT] field to start the transmission, also please check if the module is enabled, otherwise writing to PUSHR has no effect.

The code stays in "while ((base->SR & SPI_SR_TCF_MASK) == 0)" while the transfer is still in progress.

I suggest you refer to the SDK examples, there you can functions that will help you with this.

 

Let me know if this is helpful, if you have more questions do not hesitate to ask me.

Best regards,

Omar