RT1011 2 bit transfer LPSPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

RT1011 2 bit transfer LPSPI

Jump to solution
695 Views
Daniel14
Contributor III

Hi,

How to implement 2-bit transfer LPSPI on RT1011 platform.

RT1011 is set as SPI master to receive ADC data through 2-bit transfer SPI.

Only "0" s are received using the following code.

But LPSPI  1-bit transfer run well on my board ,when I change LPSPI_TCR_WIDTH(1); to LPSPI_TCR_WIDTH(0);I can get the right data.

what is the problem? thanks a lot. 

 

//SPI initialization

void SPI_Init(void) {

lpspi_master_config_t masterConfig;

masterConfig.baudRate = 20000000;
masterConfig.bitsPerFrame = 128;

masterConfig.cpol = kLPSPI_ClockPolarityActiveLow;
masterConfig.cpha = kLPSPI_ClockPhaseFirstEdge;
masterConfig.direction = kLPSPI_MsbFirst;

masterConfig.pcsActiveHighOrLow = kLPSPI_PcsActiveLow;

masterConfig.pinCfg = kLPSPI_SdiInSdoOut;
masterConfig.dataOutConfig = kLpspiDataOutRetained;

LPSPI_MasterInit(LPSPI1, &masterConfig, ADC_LPSPI_CLOCK_FREQ);

LPSPI_DisableInterrupts(LPSPI1, kLPSPI_AllInterruptEnable);
LPSPI_SetMasterSlaveMode(LPSPI1, kLPSPI_Master);

LPSPI1->TCR =(LPSPI1->TCR &
~(LPSPI_TCR_CONT_MASK | LPSPI_TCR_CONTC_MASK | LPSPI_TCR_RXMSK_MASK | LPSPI_TCR_PCS_MASK | LPSPI_TCR_WIDTH_MASK)) |
LPSPI_TCR_CONT(0) | LPSPI_TCR_CONTC(0) | LPSPI_TCR_RXMSK(0) | LPSPI_TCR_TXMSK(1) | LPSPI_TCR_PCS(0)| LPSPI_TCR_WIDTH(1);

LPSPI1->CFGR1 |= LPSPI_CFGR1_OUTCFG_MASK;
LPSPI1->CR |= LPSPI_CR_MEN_MASK; /* Module is enabled */

}

//SPI read

void  SPI_Read(void){

int data[4];
LPSPI_FlushFifo(LPSPI1,true,true);
// Write 0xFF for providing clock for read
LPSPI_WriteData(LPSPI1,0xFFFFFFFF);
LPSPI_WriteData(LPSPI1,0xFFFFFFFF);
LPSPI_WriteData(LPSPI1,0xFFFFFFFF);
LPSPI_WriteData(LPSPI1,0xFFFFFFFF);
// Wait until Tx clock have been completed
while(LPSPI_GetTxFifoCount(LPSPI1));
// Wait until Rx get data
while(LPSPI_GetRxFifoCount(ADC_LPSPI_MASTER_BASEADDR)!=4);
data[0]=LPSPI_ReadData(LPSPI1);
data[1]=LPSPI_ReadData(LPSPI1);
data[2]=LPSPI_ReadData(LPSPI1);
data[3]=LPSPI_ReadData(LPSPI1);
}

0 Kudos
1 Solution
649 Views
Daniel14
Contributor III

I just fixed the issue. Close it. Thanks 

View solution in original post

0 Kudos
3 Replies
650 Views
Daniel14
Contributor III

I just fixed the issue. Close it. Thanks 

0 Kudos
663 Views
Daniel14
Contributor III

Is there any demo code of 2-bit LPSPI transfer can be offed? I have been stuck here for a long time. Thanks 

0 Kudos
687 Views
Daniel14
Contributor III

I monitor the SPI signals through logic analysis, all the waveforms are right, but I can not get the right data.

0 Kudos