Part Number: TMS320C6678
Hi,
I am trying to read data from an external FPGA which is interfaced with a ADC. I am using evmc66x_spi.c (Processor SDK 5.2) for calling SPI routines. I have pasted my main code below. I have initialized the SPI core (for CS1 ). In this code I am trying to read 16 bit data from FPGA (initialized as Slave). I am using infinite for loop so that I can continuously receive data from FPGA. When I run the code, the status flag in the FPGA get high but the C6678 does not read any values in the buffer and when I pause the code anytime, it is stuck at this while loop (line 42 in below code) in spi_xfer() function in evmc66x_spi.c file.
spi_xfer
(
uint32_t nbytes,
uint8_t* data_out,
uint8_t* data_in,
Bool terminate
)
{
uint32_t i, buf_reg;
uint8_t* tx_ptr = data_out;
uint8_t* rx_ptr = data_in;
/* Clear out any pending read data */
SPI_SPIBUF;
for (i = 0; i < nbytes; i++)
{
/* Wait untill TX buffer is not full */
while( SPI_SPIBUF & CSL_SPI_SPIBUF_TXFULL_MASK );
/* Set the TX data to SPIDAT1 */
data1_reg_val &= ~0xFFFF;
if(tx_ptr)
{
data1_reg_val |= *tx_ptr & 0xFF;
tx_ptr++;
}
/* Write to SPIDAT1 */
if((i == (nbytes -1)) && (terminate))
{
/* Release the CS at the end of the transfer when terminate flag is TRUE */
SPI_SPIDAT1 = data1_reg_val & ~(CSL_SPI_SPIDAT1_CSHOLD_ENABLE << CSL_SPI_SPIDAT1_CSHOLD_SHIFT);
} else
{
SPI_SPIDAT1 = data1_reg_val;
}
/* Read SPIBUF, wait untill the RX buffer is not empty */
while ( SPI_SPIBUF & ( CSL_SPI_SPIBUF_RXEMPTY_MASK ) );
/* Read one byte data */
buf_reg = SPI_SPIBUF;
if(rx_ptr)
{
*rx_ptr = buf_reg & 0xFF;
rx_ptr++;
}
}
return SPI_EOK;
}
The main code:
uint32_t status;
uint32_t status1;
uint8_t *in1 = 0;
uint8_t *in2 = 0;
int i;
spi_claim(1,1000000);
for(i=0;i>-1;i++)
{
status = spi_xfer(nbytes,NULL,in1,FALSE);
status1 = spi_xfer(nbytes,NULL,in2,TRUE);
rxBuf[i%100] = (int)in1 + ((int)in2)*256;
}
spi_release();
Can anyone please help me find any mistake in the code?
Regards,
