Hi,
I have trouble with SPI communication with two different SPI devices. The problem is that one slave needs normal clock phase and the other one needs delayed clock phase, so I need to change clock phase dynamically during program run.
If I change clock phase during run from NORMAL to DELAYED , the phase correctly changes to delayed (analyzed on logic analyzator), but when I am trying to change it back to normal phase, then the clock phase remains delayed.
In conclusion:
SLAVE1(normal clk phase), SLAVE2(delayed clk phase)
Program flow:
0. Initial SPI setup:
void HAL_setupSpiA(HAL_Handle handle)
{
HAL_Obj *obj = (HAL_Obj *)handle;
SPI_reset(obj->spiAHandle);
SPI_setMode(obj->spiAHandle,SPI_Mode_Master);
SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
SPI_enableTx(obj->spiAHandle);
SPI_enableTxFifoEnh(obj->spiAHandle);
SPI_enableTxFifo(obj->spiAHandle);
//SPI_setTxDelay(obj->spiAHandle,0x0018);
SPI_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Normal);
SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x000d)); //cca 1,5MHZ
SPI_setCharLength(obj->spiAHandle,SPI_CharLength_16_Bits);
SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
SPI_enable(obj->spiAHandle);
}
1. Communication with slave1 OK
2. Change clock phase to delayed ( SPI_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Delayed) )
- phase is correctly changed to delayed
-Communication with SLAVE2 OK
3. Change clock phase back to normal (SPI_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Normal) )
- phase is not changed and remains delayed.
- Communication with SLAVE1 Failed
Does anyone have any idea how to solve this issue ?
Thanks for any tip.
Regards,
Tom.