Hello Everyone
I am playing around with SPI on LPCXpresso802 board. Everything seems OK but there is an unclear code that I try to understand but I could not configure out.
It is in example: lpcxpresso802_spi_interrupt_master.
As the Data transfer Length is setup with 8 bits width, so RXDAT and TXDAT will be handle each single byte. but why does it need casting type (uint16_t) as below?
I have connected to external SPI chip (AS3933), if no casting type, then read command sometime did not get right value.
Here is the origial interrupt code
void SPI_MASTER_IRQHandler(void)
{
/* Check if data is ready in RX register. */
if ((SPI_GetStatusFlags(EXAMPLE_SPI_MASTER) & kSPI_RxReadyFlag))
{
rxBuffer[BUFFER_SIZE - rxIndex] = SPI_ReadData(EXAMPLE_SPI_MASTER);
rxIndex--;
}
/* Write data to TX regsiter if TX register is ready. */
if ((SPI_GetStatusFlags(EXAMPLE_SPI_MASTER) & kSPI_TxReadyFlag) && (txIndex != 0U))
{
/* If this is the last byte to send. */
if (1U == txIndex)
{
/* Add end of transfer configuration. */
SPI_WriteConfigFlags(EXAMPLE_SPI_MASTER, kSPI_EndOfTransfer);
SPI_WriteData(EXAMPLE_SPI_MASTER, txBuffer[BUFFER_SIZE - txIndex]);
}
else
{
SPI_WriteData(EXAMPLE_SPI_MASTER, (uint16_t)(txBuffer[BUFFER_SIZE - txIndex]));
}
txIndex--;
}
/* If no data to be transferred, disable the interrupt. */
if ((txIndex == 0U) && (rxIndex == 0U))
{
slaveFinished = true;
SPI_DisableInterrupts(EXAMPLE_SPI_MASTER, kSPI_RxReadyInterruptEnable);
}
__DSB();
}
Thank you.