Greetings! Here is my init function:
void HAL_setupSpiA(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
SPI_reset(obj->spiAHandle);
SPI_setMode(obj->spiAHandle,SPI_Mode_Master);
SPI_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Delayed);
SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
SPI_enableTx(obj->spiAHandle);
SPI_disableTxFifoEnh(obj->spiAHandle);
SPI_setTxDelay(obj->spiAHandle,0x0000);
SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x07D0));
SPI_setCharLength(obj->spiAHandle,SPI_CharLength_8_Bits);
SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
SPI_enable(obj->spiAHandle);
return;
} // end of HAL_setupSpiA() function
And here is my transfer function:
unsigned int spi_xfer(unsigned char data)
{
SPI_write8(halHandle->spiAHandle, data);
while(SPI_getTxFifoStatus(halHandle->spiAHandle)!=SPI_FifoStatus_Empty);
while(SPI_getRxFifoStatus(halHandle->spiAHandle)!=SPI_FifoStatus_Empty);
unsigned int result=0;
result = SPI_read(halHandle->spiAHandle);
SPI_resetRxFifo(halHandle->spiAHandle);
return result;
}
My problem is that this code demands time between the transfers in order to send data properly. Like it doesn`t clear the output buffer. I have to add a small delay before every spi_xfer call. It omits some of the data. I think i am not performing this routine correctly. SPI_XFER has to send 8 bit data and return the received data. And somehow it is not ready every time to transmit a new byte...
Any suggestions?
Thanks!
