K66 Spi recieve problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

K66 Spi recieve problem

1,277件の閲覧回数
bogdan_adrian91
Contributor II

Hello, I am trying to configure an spi connection between k66 and an spi flash. The oscilloscope capture looks fine :I have read a register value, changed it and read it back. All good here. My problem is in reading the rxdata which I am not able to store in my buffer. I have printed out several situations and it seems that in my recieve buffer I get OxFF for a number of bytes equal to the number of bytes I read ( tr.rxDataSize ). Any idea how can I store the correct recieve data ?

I have used the example in the sdk.
I would expect to have the value 16 (from the scope) stored in rxdata[0] ,rxdata[1],rxdata[2],rxdata[3] but instead I get 0xFF. I have attached 2 print screens
 

Thank you

#include "fsl_debug_console.h"
#include "fsl_dspi_edma.h"
#include "fsl_dmamux.h"
#include "fsl_dspi.h"
#include "board.h"

#include "pin_mux.h"
#include "clock_config.h"
/*******************************************************************************
* Definitions
******************************************************************************/
#define EXAMPLE_DSPI_MASTER_BASEADDR SPI0
#define EXAMPLE_DSPI_MASTER_DMA_MUX_BASEADDR DMAMUX
#define EXAMPLE_DSPI_MASTER_DMA_BASEADDR DMA0
#define EXAMPLE_DSPI_MASTER_DMA_RX_REQUEST_SOURCE kDmaRequestMux0SPI0Rx
#define EXAMPLE_DSPI_MASTER_DMA_TX_REQUEST_SOURCE kDmaRequestMux0SPI0Tx
#define DSPI_MASTER_CLK_SRC DSPI0_CLK_SRC
#define DSPI_MASTER_CLK_FREQ CLOCK_GetFreq(DSPI0_CLK_SRC)
#define EXAMPLE_DSPI_MASTER_PCS_FOR_INIT kDSPI_Pcs0
#define EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER kDSPI_MasterPcs0

#define TRANSFER_BAUDRATE 500000U
#define BUFFER_SIZE 64


static uint8_t txdata[BUFFER_SIZE];
static uint8_t rxdata[BUFFER_SIZE];


int main(void)
{


uint32_t srcFreq = 0;

/* Transfer structure for half-duplex. */
dspi_master_config_t masterConfig;

BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();


// Master config
masterConfig.whichCtar = kDSPI_Ctar0;
masterConfig.ctarConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.ctarConfig.bitsPerFrame = 8;
masterConfig.ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
masterConfig.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
masterConfig.ctarConfig.direction = kDSPI_MsbFirst;
masterConfig.ctarConfig.pcsToSckDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.lastSckToPcsDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE;
masterConfig.ctarConfig.betweenTransferDelayInNanoSec = 1000000000U / TRANSFER_BAUDRATE; // pot astepta 1 perioada de ceas

masterConfig.whichPcs = EXAMPLE_DSPI_MASTER_PCS_FOR_INIT;
masterConfig.pcsActiveHighOrLow = kDSPI_PcsActiveLow;

masterConfig.enableContinuousSCK = false;
masterConfig.enableRxFifoOverWrite = false;
masterConfig.enableModifiedTimingFormat = false;
masterConfig.samplePoint = kDSPI_SckToSin0Clock;
srcFreq = DSPI_MASTER_CLK_FREQ;
DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, srcFreq);


int i;
for (i = 0; i < BUFFER_SIZE; i++) //fill up buffers with 1
{
txdata[i] = 1;
rxdata[i] = 1;
}

// get feature
txdata[0]=0x0F;
txdata[1]=0xB0;

dspi_half_duplex_transfer_t tr;
tr.txData =txdata;
tr.rxData =rxdata;

tr.txDataSize=2; // send 2 bytes
tr.rxDataSize=4; //recieve 2 bytes
tr.configFlags=kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous ;
tr.isPcsAssertInTransfer=true;
tr.isTransmitFirst=true;


PRINTF("\n Before SPI transmission \n");
for(int i=0;i<10;i++){
printf("\t rxdata[%d]=%X",i,rxdata[i]);
}

while (1)
{
DSPI_MasterHalfDuplexTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &tr);


printf("\n After SPI transmission \n");
for(int k=0;k<10;k++){
printf("\t rxdata[%d]=%X",k,rxdata[k]);
}


printf("\n After SPI transmission \n");

for(int j=0;j<10;j++){
printf("\t tr.rxdata[%d]=%X",j,tr.rxData[j]);
}

}


/* Stop the transfer. */
DSPI_Deinit(EXAMPLE_DSPI_MASTER_BASEADDR);
}

0 件の賞賛
返信
2 返答(返信)

1,143件の閲覧回数
bogdan_adrian91
Contributor II

I just solved it.

Got to work this morning, ran my code and it worked...

0 件の賞賛
返信

1,143件の閲覧回数
Alexis_A
NXP TechSupport
NXP TechSupport

Hi Bogdan,

I'm glad that you could solve your issue.

Best Regards,

Alexis Andalon

0 件の賞賛
返信