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 ?
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 ceasmasterConfig.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);
}
I just solved it.
Got to work this morning, ran my code and it worked...
Hi Bogdan,
I'm glad that you could solve your issue.
Best Regards,
Alexis Andalon