This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Communication between TMS320C5535 and SPI based ADC (TLC3544)

Other Parts Discussed in Thread: TLC3544, TMS320C5535, ADS1220

Hi,

I want to communicate C5535 (eZdsp evaluation kit) with SPI based ADC (TLC3544), the configuration made for this is as below:

1. SPI_Write (A000h)

2. SPI_Write (A304h)- Internal reference used, mode zero, conversion clock= SCLK/4

3. SPI_Write (3000h)

The DSP is supposed to read the digital value from the channel 3. But this is not happening. One more question is how we will get to know the conversion has been completed without INT. The configuration is made as per the datasheet. The code is attached. Chip Select 2 is being used.

#include "csl_spi.h"
#include "csl_general.h"
#include <stdio.h>

#define CSL_TEST_FAILED (1)
#define CSL_TEST_PASSED (0)

#define CSL_SPI_BUF_LEN (1)
#define SPI_CLK_DIV (100) - SPI CLOCK is 1MHz
#define SPI_FRAME_LENGTH (1)

Uint16 spiWriteBuff[3]={0,0,0};
Uint16 spiReadBuff[1];

/
void main(void)
{
Int16 status;

printf("CSL SPI Test\n\n");

Int16 status = CSL_TEST_FAILED;
Int16 result;
CSL_SpiHandle hSpi;
SPI_Config hwConfig;
volatile Uint32 looper;
volatile Uint16 value = 0;
volatile Uint16 delay;

spiWriteBuff[0]=0xA000;

spiWriteBuff[1]=0xA304;

result = SPI_init();

// I have set to PPMODE as MODE1 - All modes are there CSO to CS3

if(CSL_SOK != result)
{
status = CSL_TEST_FAILED;
return (status);
}
else
{
printf ("SPI Instance Initialize successfully\n");
}

hSpi = SPI_open(SPI_CS_NUM_2, SPI_POLLING_MODE);

if(NULL == hSpi)
{
return (CSL_TEST_FAILED);
}
else
{
printf ("SPI Instance Opened successfully\n");
}

/** Set the hardware configuration */
hwConfig.spiClkDiv = SPI_CLK_DIV;
hwConfig.wLen = SPI_WORD_LENGTH_16;
hwConfig.frLen = SPI_FRAME_LENGTH;
hwConfig.wcEnable = SPI_WORD_IRQ_DISABLE;
hwConfig.fcEnable = SPI_FRAME_IRQ_DISABLE;
hwConfig.csNum = SPI_CS_NUM_2;
hwConfig.dataDelay = SPI_DATA_DLY_2;
hwConfig.csPol = SPI_CSP_ACTIVE_LOW;
hwConfig.clkPol = SPI_CLKP_LOW_AT_IDLE;
hwConfig.clkPh = SPI_CLK_PH_FALL_EDGE;

result = SPI_config(hSpi, &hwConfig);

if(CSL_SOK != result)
{
return (CSL_TEST_FAILED);
}
else
{
printf ("SPI Instance Configured successfully\n");
}

result= SPI_write(hSpi,spiWriteBuff,3);

if(CSL_SOK != result)
{
printf ("write failed");
}
else
{
printf ("write success\n");
}

while(1)

{

CSL_FINS(CSL_SPI_REGS->SPICMD2,SPI_SPICMD2_CSNUM,0x02);

CSL_FINS(CSL_SPI_REGS->SPICMD1,SPI_SPICMD1_FLEN,0x0);

/* Write Enable command */
CSL_FINS(CSL_SPI_REGS->SPIDR2,SPI_SPIDR2_DATA,0x3000);
CSL_FINS(CSL_SPI_REGS->SPIDR1,SPI_SPIDR1_DATA,0x0000);

/* set start CMD - Write */
CSL_FINS(CSL_SPI_REGS->SPICMD2,SPI_SPICMD2_CMD,0x02);

do { /* Check for Word Complete status */
value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_CC);
}while((value & 0x01) == 0x0);

do { /* Check for busy status */
value=CSL_FEXT(CSL_SPI_REGS->SPISTAT1,SPI_SPISTAT1_BSY);
}while((value & 0x01) == 0x01);

result=SPI_read(hSpi,spiReadBuff,CSL_SPI_BUF_LEN )

if(CSL_SOK != result)
{
printf ("read failed");
}
else
{
printf ("read success\n");
}

}

I have doubt whether we are making any configuration wrong.

}

The 

  • Hi,

    To check whether your SPI is working correctly you can enable the loopback and check transmit and receiving happens correctly.

    There exists a loopback CSL example CSL_SPI_InternalLB which you could use/refer and later modify this to interface with your external SPI device.

    Here are few of my suggestions, when interfacing with external device use the same buffers defined in the example,

    Uint16 spiWriteBuff[CSL_SPI_BUF_LEN];

    Uint16 spiReadBuff[CSL_SPI_BUF_LEN];

    Fill the write buffer with appropriate values that is required to configure external ADC device. Similarly the read buffer is used to read the converted ADC values.

    Use the data transaction CSL function to do write/read transfers –

    SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); - For Write

    SPI_dataTransaction(hSpi ,spiReadBuff, CSL_SPI_BUF_LEN, SPI_READ); - For Read

    Also look at the other signals with respect to external ADC device and drive these signals correctly otherwise your SPI write / Read will not happen as expected.

    Hope this helps.

    Regards

    Vasanth

  • Hi,

    Sorry to revive an old thread but I am trying to build off of the example you mention in your post. The problem is I'm not entirely sure how to test the communications. I am using the CSL_SPI_InternalLB example with an ADS1220 adc and the TMS320C5535 ezDSP, similar to OP. The ADC is connected for a unipolar configuration and I am using CS1. My pin connections from the expansion connector to the ADC are SPI_CS1 ->CS, SPI_CLK->SCLK, SPI_TX->DIN, and SPI_RX->DOUT/DRDY. Running the example the console prints the success messages for "SPI Instance Write Successfully" and "SPI Instance Read Successfully". However the buffers do not match and when stepping through the code with the debugger it seems as though nothing is actually being written to the pointer location from the write buffer because the read buffer keeps pulling zero from that same pointer. Is there an error I made in the testing setup or something additional that needs to be done for the ADC? This is my first experience with an external ADC so I am not 100% sure if that is set up correctly as well. Thank you in advance.

    Best Regards,

    Ulbert