2021-07-04 02:21 AM
I have done some debugging on SPI interrupt problem. So, I have a function that SPI_SendDataIT which means SPI send data with interrupt. the interrupt will be triggered if TXE flag is SET. But we have to enable the TXEIE first.
But, what happen is, after my code execute at line of:
pSPIHandle->pSPIx->CR2 |= (1 << SPI_CR2_TXEIE);
the TXEIE is not even SET. and I already check the register bit number is already correct. Im using stm32f302r8. What causes this problem?
One more, In my program, before I do the TXEIE become SET, I enable the SPI clock peripheral first, the TXE become SET.
So meaning the TXE already SET before making the TXEIE become SET.
can someone help me on this issue? Here I attached the picture:
2.The TXEIE is not SET eventhough inside the program I already make it SET
2021-07-04 05:51 AM
JW
2021-07-04 06:29 AM
You're not setting TXEIE. To set TXEIE:
SPIx->CR2 |= SPI_CR2_TXEIE;
2021-07-04 06:35 AM
Indeed...
2021-07-04 06:26 PM
This did not work. do you have any examples on this type of code that I can refer to?
2021-07-04 06:30 PM
2021-07-04 06:33 PM
2021-07-04 06:38 PM
uint8_t SPI_SendDataIT(SPI_Handle_t *pSPIHandle, uint8_t *pTxBuffer, uint32_t Len)
{
uint8_t state = pSPIHandle->TxState;
if(state != SPI_BUSY_IN_TX)
{
pSPIHandle->pTxBuffer = pTxBuffer;
pSPIHandle->TxLen = Len;
pSPIHandle->TxState = SPI_BUSY_IN_TX;
pSPIHandle->pSPIx->CR2 |= SPI_CR2_TXEIE;
}
return state;
}
Original code: pSPIHandle->pSPIx->CR2 |= (1 << SPI_CR2_TXEIE);
modified as your suggestion: pSPIHandle->pSPIx->CR2 |= SPI_CR2_TXEIE;
Is this correct?