This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
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.
Hi, I just resolved this issue. The problem was in function SPI_setClkPhase(SPI_Handle spiHandle,const SPI_ClkPhase_e clkPhase). This function by default only contains line spi->SPICTL |= clkPhase , so it can set register bits from 0 to 1 but it can't do this vice versa. So add spi->SPICTL &= (~SPI_SPICTL_CLK_PHASE_BITS) line before, solved the problem.
Regards,
Hi Tom,
Good to know your problem was solved. Good catch on the SPI_setClkPhase() function.