Hello all,
I'm using S32K146 and trying to receive data while communicating with the slave.
But, there is a difference in what actually on the scope & what I receiving the data?
Initialization as follows.
/*!
* LPSPI0 Clocking:
* ===================================================
*/
PCC->PCCn[PCC_LPSPI0_INDEX] = 0; /* Disable clocks to modify PCS ( default) */
PCC->PCCn[PCC_LPSPI0_INDEX] = PCC_PCCn_PR_MASK /* (default) Peripheral is present. */
|PCC_PCCn_CGC_MASK /* Enable PCS=SPLL_DIV2 (40 MHz func'l clock) */
|PCC_PCCn_PCS(6);
/*!
* LPSPI0 Initialization:
* ===================================================
*/
LPSPI0->CR = 0x00000000; /* Disable module for configuration */
LPSPI0->IER = 0x00000000; /* Interrupts not used */
LPSPI0->DER = 0x00000000; /* DMA not used */
LPSPI0->CFGR0 = 0x00000000; /* Defaults: */
LPSPI0->CFGR1 = LPSPI_CFGR1_MASTER_MASK; /* Configurations: master mode */
LPSPI0->TCR = LPSPI_TCR_PRESCALE(2)
| LPSPI_TCR_PCS(0)
| LPSPI_TCR_CONT_MASK
| LPSPI_TCR_FRAMESZ(7) ;
LPSPI0->CCR = LPSPI_CCR_SCKPCS(4)
|LPSPI_CCR_PCSSCK(4)
|LPSPI_CCR_DBT(8)
|LPSPI_CCR_SCKDIV(4); /* Clock dividers based on prescaled func'l clk of 100 nsec */
LPSPI0->FCR = LPSPI_FCR_RXWATER(0) /* RXWATER=0: Rx flags set when Rx FIFO >0 */
| LPSPI_FCR_TXWATER(1);
LPSPI0->CR = LPSPI_CR_MEN_MASK
| LPSPI_CR_DBGEN_MASK; /* Enable module for operation */
My function includes transmitting 16 bits in 2 frames 8 bytes each with continuous transfer
int8_t master_slave_communication( address)
{
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0) {} \
LPSPI0->TDR = LPSPI_TDR_DATA(n)
while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
ret= LPSPI0->RDR;
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0) {} \
LPSPI0->TDR = LPSPI_TDR_DATA(n)
while((LPSPI0->SR & LPSPI_SR_RDF_MASK)>>LPSPI_SR_RDF_SHIFT==0);
ret= LPSPI0->RDR;
LPSPI0->TCR &= ~(LPSPI_TCR_CONTC_MASK) ;
while((LPSPI0->SR & LPSPI_SR_TDF_MASK)>>LPSPI_SR_TDF_SHIFT==0) {}
}
The Image on the scope which shows Clock and MISO signals
But the data I received is 0x5B.
Kindly suggest me where I went wrong,
Raju
Solved! Go to Solution.
Hi Victor,
Thanks for the response.
In fact, I found a mistake with CPHA. Now I'm able to see the results as expected.
Raju
Hello Raju,
Within the SDK for the S32K146 there's an example named "lpspi_transfer_s32k146". I recommend you check this example and use it as a guide to see how to configure and setup the LPSPI module.
Regards,
Victor
Hi Victor,
Thanks for the response.
In fact, I found a mistake with CPHA. Now I'm able to see the results as expected.
Raju