SPI on MKV58F1M0VLQ24

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

SPI on MKV58F1M0VLQ24

ソリューションへジャンプ
628件の閲覧回数
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 解決策
612件の閲覧回数
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 返信
613件の閲覧回数
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