hi kerryzhou
I try to interface afe4490 with k53 controller.when i try to read from the slave register am getting as zero value.could you send me the spi configurations or source code for spi transfer.
Thanks in advance
hi ,
I checked it out and data is trasnmitting when chip select gets low.but not proper datas are transmitting.Its transmitting someothr data other than what i have given.but transmission is happening.
Thank You.
Hello Kanimozhi Raju,
Please attach your SPI wave when you do the communication.
It is useful to my analysis.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
hi kerryzhou
I have attached the spi waveform.First i use 4mhz datas are not visible for me.then i have changed clock and enable cont sck and then i have used.D0-SCK,D1-MOSI,D2-MISO,D3-CS...I have sent you the waveform of mosi sck and cs.The data what i have try to write is not written.It would be great if its resolved.Thank you.
Hello Kanimozhi Raju,
I have test the SPI in the KSDK sample code, it can send out the data what you want.
I find your main code is:
void main (void)
{
printf("\n SPI Interface with afe \n");
spi_init();
while(1)
{
spi_write(0x00,0x000000);
spi_write(0x20,0x000004);
spi_write(0x00,0x000001);
spi_read(0x20);
}
}
So, I have wrote this code in the KSDK
int main(void)
{
BOARD_InitPins();
BOARD_BootClockRUN();
BOARD_InitDebugConsole();
uint32_t srcClock_Hz;
uint32_t errorCount;
uint32_t i;
dspi_master_config_t masterConfig;
dspi_slave_config_t slaveConfig;
dspi_transfer_t masterXfer;
/* Master config */
masterConfig.whichCtar = kDSPI_Ctar0;
masterConfig.ctarConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.ctarConfig.bitsPerFrame = 8U;
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;
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;
srcClock_Hz = DSPI_MASTER_CLK_FREQ;
DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, srcClock_Hz);
/* Set up the transfer data */
for (i = 0U; i < TRANSFER_SIZE; i++)
{
masterTxData[i] = i % 256U;
masterRxData[i] = 0U;
}
masterTxData[0] = 0X00;
masterTxData[1] = 0X00;
masterTxData[2] = 0X00;
masterTxData[3] = 0X00;
/* Start master transfer */
masterXfer.txData = masterTxData;
masterXfer.rxData = masterRxData;
masterXfer.dataSize = 4;
masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;
DSPI_MasterTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &masterXfer);
masterTxData[0] = 0X20;
masterTxData[1] = 0X00;
masterTxData[2] = 0X00;
masterTxData[3] = 0X04;
/* Start master transfer */
masterXfer.txData = masterTxData;
masterXfer.rxData = masterRxData;
masterXfer.dataSize = 4;
masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;
DSPI_MasterTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &masterXfer);
masterTxData[0] = 0X00;
masterTxData[1] = 0X00;
masterTxData[2] = 0X00;
masterTxData[3] = 0X01;
/* Start master transfer */
masterXfer.txData = masterTxData;
masterXfer.rxData = masterRxData;
masterXfer.dataSize = 4;
masterXfer.configFlags = kDSPI_MasterCtar0 | EXAMPLE_DSPI_MASTER_PCS_FOR_TRANSFER | kDSPI_MasterPcsContinuous;
DSPI_MasterTransferBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &masterXfer);
while (1)
{
}
}
The test spi wave is:
Because I didn't add the slave, then the MISO wire have no data, but the MOSI data is correct.
More details, please refer to my attached project which is based on KSDK2.2.
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Unless your SPI device is 'very unusual' (and it is NOT) remove SCKE from line 74. Optimizing the timing so CS just hits 'exactly 32 clocks' from within a continuous stream is 'more trouble than you need'.
You have no PCS value in lines 292 and 353. The Chip-select pattern MUST remain thru the whole four bytes (A/D3/D2/D1). I would expect you only need PCS0 (per line 60), so '1' for all PCS fields (lines 260/271/281/292/313/326/339/353). This code also still has '|=' for all SR writes, please replace with just '=' !!!
AFE4490:
Hello Kanimozhi Raju,
About the SPI sample code for K53, you can refer to our KSDK sample code.
Please download the code from this link:
https://mcuxpresso.nxp.com/en/builder
Choose the processor as K53, then generate the code and download it.
You can find the SPI project in folder:SDK_2.2_MK53DN512xxx10\boards\twrk60d100m\driver_examples\dspi
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
hi kerryzhou,
I have attached my spi configuration and function.Could you say what i have made wrong.I am sending 8bit address and reading back 24bit data form the slave register.
Thanks in advance.
Hello Kanimozhi Raju,
Did you check the SPI wave with logic analyzer or oscilloscope?
Whether the MCU get the SPI data from the SPI bus?
Please check this at first, and attached the according SPI wave.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------