Skip to main content
Graduate II
November 21, 2024
Solved

Is TXP Necessary for SPI Slave?

  • November 21, 2024
  • 2 replies
  • 834 views

I am having issues with my slave responding to my master. I am trying to lessen complexity by only using RXP on the slave, without TXP. The slave (Nucleo-H743ZI) responds one byte late.

On the CS interrupt I send 0 for the first byte and enable RXP.

*((__IO uint8_t *)&hspi1.Instance->TXDR) = 0;
__HAL_SPI_ENABLE_IT(&hspi1, SPI_IT_RXP);
__HAL_SPI_ENABLE(&hspi1);

I then receive a byte and set the next transmit byte. I use FPint so the master does not send data when it is low (used for later implementation).  

void spiISRSTM(SPI_HandleTypeDef *hspi) {

	//Receive if ready
	if (hspi->Instance->SR & SPI_FLAG_RXP) {
		HAL_GPIO_WritePin(nFPINT_GPIO_Port, nFPINT_Pin, GPIO_PIN_RESET);	
 	rxBuffer = (*(__IO uint8_t *)&hspi->Instance->RXDR);
 	(*(__IO uint8_t *)&hspi->Instance->TXDR) = 1;
 	HAL_GPIO_WritePin(nFPINT_GPIO_Port, nFPINT_Pin, GPIO_PIN_SET);

	}
	__HAL_SPI_CLEAR_UDRFLAG(hspi);
	__HAL_SPI_CLEAR_OVRFLAG(hspi);
	__HAL_SPI_CLEAR_EOTFLAG(hspi);
	__HAL_SPI_CLEAR_FREFLAG(hspi);

}

The MISO line for this setup is:

0011 1111

I would expect:

0111 1111

Any Ideas what is causing this?

    This topic has been closed for replies.
    Best answer by EthanMankins

    The issue was an underrun after the first byte. Disabling and reenabling spi after read and before transmit solved the issue.

    sr = hspi->Instance->SR;
    if ((sr & (SPI_FLAG_RXP | SPI_FLAG_TXC)) == (SPI_FLAG_RXP | SPI_FLAG_TXC)) {
    		HAL_GPIO_WritePin(nFPINT_GPIO_Port, nFPINT_Pin, GPIO_PIN_RESET);	//Lower nFPINT
    		rxBuffer = (*(__IO uint8_t *)&hspi->Instance->RXDR);
    		__HAL_SPI_DISABLE(&hspi1);
    		__HAL_SPI_ENABLE(&hspi1);
    		pPacketSlave->ProcessSPI();
    		(*(__IO uint8_t *)&hspi->Instance->TXDR) = txBuffer;
    	}

    2 replies

    Technical Moderator
    November 22, 2024

    Hello @EthanMankins 

    Could you try activating DXP interrupt and checking on DXP flag instead of RXP? 

     

    Graduate II
    November 22, 2024

    Hi @Saket_Om 

    I have tried this and it does not make difference to the timing.

    EthanMankinsAuthorAnswer
    Graduate II
    November 25, 2024

    The issue was an underrun after the first byte. Disabling and reenabling spi after read and before transmit solved the issue.

    sr = hspi->Instance->SR;
    if ((sr & (SPI_FLAG_RXP | SPI_FLAG_TXC)) == (SPI_FLAG_RXP | SPI_FLAG_TXC)) {
    		HAL_GPIO_WritePin(nFPINT_GPIO_Port, nFPINT_Pin, GPIO_PIN_RESET);	//Lower nFPINT
    		rxBuffer = (*(__IO uint8_t *)&hspi->Instance->RXDR);
    		__HAL_SPI_DISABLE(&hspi1);
    		__HAL_SPI_ENABLE(&hspi1);
    		pPacketSlave->ProcessSPI();
    		(*(__IO uint8_t *)&hspi->Instance->TXDR) = txBuffer;
    	}