MK64 DSPI with external PGA and ADC

cancel
Showing results for 
Search instead for 
Did you mean: 

MK64 DSPI with external PGA and ADC

537 Views
fshah30
Contributor II

Hi, I want to use the DSPI to work with PGA (Gain Amplifier) and external ADC. Kindly help me to setup the source code that work well with this scenario. I can send the data to PGA and control the gain of the input signal, I don't understand how can I receive the data from ADC? 

ADC # AD7940BRMZ

PGA # MCP6S26-I/ST

See the attached schematic for understanding. Thank you

Tags (1)
0 Kudos
7 Replies

528 Views
Pavel_Hernandez
NXP Employee
NXP Employee

Hello,

I review your image but I don't understand the diagram, there are lines without a name, Could you provide me more information about your connection?. I found this application note [MPC5121e Serial Peripheral Interface (SPI) (nxp.com)] is not for the same MPC, but maybe will help you. Are you trying to do this?

Pavel_Hernandez_0-1654118268848.png

Best regards,
Pavel

0 Kudos

524 Views
fshah30
Contributor II

Hi, Please find the attached SCH for your review. 

There are TWO parts

1- send the data to Gain Amplifier chip which is working fine, I can see gain increase and decrease in oscilloscope

2-  Read data from ADC chip which is not working.

See the attached code for your review. Please let me know where I am doing wrong? Thank you

0 Kudos

505 Views
Pavel_Hernandez
NXP Employee
NXP Employee

Hello,

I review the schematic and I understand the next.

You are using the k64 to send commands of SPI to the MCP, this works fine, but when you configure the MCP to the ADC should answer back to the K64?, tell me if I'm wrong.

But I do not see the problems are in the K64, if your problem is about the ADC you need to contact the vendor for getting more details. I suggest reviewing the frequency that can be supported by the ADC, I reviewed the datasheet of the ADC, and check if you are using the CS correct this starts the frame.

Best regards,
Pavel

0 Kudos

503 Views
fshah30
Contributor II

Hi, 

Thank you for the reply.

I can see the ADC is working now and give me the readings. Please can you provide code to store 30K samples from the same ADC. I attached my code for your review. Thanks

/*
*Brief Master Read Task Start
*/

static void master_read_task(void *pvParameters)
{

uint32_t i = 0;
status_t status;

// /* Transfer structure for half-duplex. */
// dspi_half_duplex_transfer_t xfer = {0};


dspi_transfer_t masterXfer;
dspi_master_config_t masterConfig;

PRINTF("SPI master board will transmit data to slave board first, then receive data from slave board.\r\n");

PRINTF("Besides, Master will transfer data by interrupt way, and slave will use interrupt way.");
PRINTF("\r\nMaster start to tansfer...\r\n");

/* Master config */
masterConfig.whichCtar = kDSPI_Ctar1;
masterConfig.ctarConfig.baudRate = TRANSFER_BAUDRATE;
masterConfig.ctarConfig.bitsPerFrame = 16U;
masterConfig.ctarConfig.cpol = kDSPI_ClockPolarityActiveHigh;
masterConfig.ctarConfig.cpha = kDSPI_ClockPhaseFirstEdge;
masterConfig.ctarConfig.direction = kDSPI_MsbFirst;
masterConfig.ctarConfig.pcsToSckDelayInNanoSec = 500;//was 2000
masterConfig.ctarConfig.lastSckToPcsDelayInNanoSec = 500;//was 2000
masterConfig.ctarConfig.betweenTransferDelayInNanoSec = 1000;//was 1000


masterConfig.whichPcs = kDSPI_Pcs1;
masterConfig.pcsActiveHighOrLow = kDSPI_PcsActiveLow;

masterConfig.enableContinuousSCK = false;
masterConfig.enableRxFifoOverWrite = false;
masterConfig.enableModifiedTimingFormat = false;
masterConfig.samplePoint = kDSPI_SckToSin0Clock;


DSPI_MasterInit(EXAMPLE_DSPI_MASTER_BASEADDR, &masterConfig, DSPI_MASTER_CLK_FREQ);

/* Init Buffer*/
for (i = 0; i < TRANSFER_SIZE; i++)
{
txData[i] = i + 1;
}

/*Start master receive*/
masterXfer.txData = masterSendBuffer;
masterXfer.rxData = masterReceiveBuffer;
masterXfer.dataSize = TRANSFER_SIZE;
masterXfer.configFlags = kDSPI_MasterCtar1/**/ | kDSPI_MasterPcs1 | kDSPI_MasterActiveAfterTransfer;


DSPI_MasterTransferCreateHandle(EXAMPLE_DSPI_MASTER_BASEADDR, &handle, DSPI_MasterInterruptCallback, NULL);

status = DSPI_MasterTransferNonBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &handle, &masterXfer);
// status = DSPI_MasterHalfDuplexTransferNonBlocking(EXAMPLE_DSPI_MASTER_BASEADDR, &handle, &xfer);
// DSPI_MasterHalfDuplexTransferNonBlocking(SPI_Type *base, dspi_master_handle_t *handle, dspi_half_duplex_transfer_t *xfer)

while (!masterFinished)
{
}

if (status == kStatus_Success)
{
PRINTF("\n\nDSPI data successfully received. \r\n\r\n");
for (i = 0; i<TRANSFER_SIZE; i++)
{
PRINTF("Received Data %d \n",masterReceiveBuffer[i]);
}
}
else
{
PRINTF("DSPI received data error. \r\n\r\n");
}

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

vTaskSuspend(NULL);
}

0 Kudos

481 Views
Pavel_Hernandez
NXP Employee
NXP Employee

Hello,

Unfortunately, I do not have a code that works with your application.

Best regards,
Pavel

0 Kudos

478 Views
fshah30
Contributor II

Hi,

Please check my code, what I want to understand is that if I need to receive 30K ADC samples it requires 30KBytes of Transfer data? This is Synchronous communication means it will doesn't work until TX?

Thanks,

Fahad

0 Kudos

436 Views
Pavel_Hernandez
NXP Employee
NXP Employee

Hello, Could you tell me what is the example you are using? I need to review the code to answer your question.

Best regards,
Pavel

0 Kudos