MK64 DSPI with external PGA and ADC

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

MK64 DSPI with external PGA and ADC

1,501 次查看
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

标记 (1)
0 项奖励
7 回复数

1,492 次查看
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

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 项奖励

1,488 次查看
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 项奖励

1,469 次查看
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

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 项奖励

1,467 次查看
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 项奖励

1,445 次查看
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

Hello,

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

Best regards,
Pavel

0 项奖励

1,442 次查看
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 项奖励

1,400 次查看
Pavel_Hernandez
NXP TechSupport
NXP TechSupport

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 项奖励