Hi,
I am trying to establish communication with the external ADC, ADS1220, and I am using the CSL_spi_internalLB example coupled with trying to implement the psuedo code recommended in the adc's datasheet. I have two main questions. The pseudo code recommends to assert the CS to high and low at different points in the code and I am not sure how to do that in the DSP. Is that the same idea as the spi_Open function? Additionally, I'm unsure of how to check for when DRDY transitions to low, or send the 24 sclk rising edges to read out conversion data on DOUT/DRDY.
Below is my code that is attempting to interface and communicate with the ADC. It currently just shows that in the read buffer old configurations that I wrote to the write buffer. Any advice is appreciated and it would also be nice to know if I am moving in the write path as far as the code goes or going in the wrong direction. Thank you in advance.
Best Regards,
Ulbert
#include "csl_spi.h" #include "csl_general.h" #include "cslr_spi_001.h" #include "corazon.h" #include "ezdsp5535.h" #include <stdio.h> #define CSL_TEST_FAILED (1) #define CSL_TEST_PASSED (0) #define CSL_SPI_BUF_LEN (1)//(64) #define SPI_CLK_DIV (24) #define SPI_FRAME_LENGTH (1) Uint16 spiWriteBuff[CSL_SPI_BUF_LEN]; Uint16 spiReadBuff[CSL_SPI_BUF_LEN]; Int16 spi_sample(void) { Int16 status = CSL_TEST_PASSED; Int16 result; CSL_SpiHandle hSpi; SPI_Config hwConfig; volatile Uint32 looper; result = SPI_init(); if(CSL_SOK != result) { status = CSL_TEST_FAILED; return (status); } else { printf ("SPI Instance Initialize successfully\n"); } //see if this is the equivalent of asserting the CS hSpi = SPI_open(SPI_CS_NUM_1, 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_8; hwConfig.frLen = SPI_FRAME_LENGTH; hwConfig.wcEnable = SPI_WORD_IRQ_DISABLE; hwConfig.fcEnable = SPI_FRAME_IRQ_DISABLE; hwConfig.csNum = SPI_CS_NUM_1; hwConfig.dataDelay = SPI_DATA_DLY_0; hwConfig.csPol = SPI_CSP_ACTIVE_LOW; hwConfig.clkPol = SPI_CLKP_LOW_AT_IDLE; hwConfig.clkPh = SPI_CLK_PH_RISE_EDGE; //was falling edge result = SPI_config(hSpi, &hwConfig); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Configured successfully\n"); } /*Enable the Internal Loopback mode*/ #if (defined(CHIP_C5517)) CSL_FINST(CSL_SPI_REGS->SPIDCRU,SPI_SPIDCRU_LPBK,ENABLE); #else #if (defined(CHIP_C5505_C5515) || defined(CHIP_C5504_C5514)) CSL_FINST(CSL_SPI_REGS->SPIDC2,SPI_SPIDC2_LPBK,ENABLE); #endif #endif for(looper = 0; looper < CSL_SPI_BUF_LEN; ) { spiWriteBuff[looper] = 0; if(CSL_SPI_BUF_LEN>1){ spiWriteBuff[(looper + 1)] = 0; spiReadBuff[(looper + 1)] = 0; } spiReadBuff[looper] = 0; //spiReadBuff[(looper + 1)] = 0; looper += 2; } //send reset command (0x06h) // spiWriteBuff[7] = 0; // spiWriteBuff[6] = 0; // spiWriteBuff[5] = 0; // spiWriteBuff[4] = 0; // spiWriteBuff[3] = 0; // spiWriteBuff[2] = 1; // spiWriteBuff[1] = 1; // spiWriteBuff[0] = 0; spiWriteBuff[0] = 0x0006; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } EZDSP5535_waitusec(10000); //send write reg command spiWriteBuff[0] = 0x0040; //write to register 0, 1byte(8bits), (0100 0000) /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //config first buffer // spiWriteBuff[7] = 1; //config the input to be AIN1 and negative reference to be tied to ground // spiWriteBuff[6] = 0; // spiWriteBuff[5] = 0; // spiWriteBuff[4] = 1; // spiWriteBuff[3] = 0;//config the gain to be one // spiWriteBuff[2] = 0; // spiWriteBuff[1] = 0; // spiWriteBuff[0] = 1;//disable PGA spiWriteBuff[0] = 0x0090; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //send write reg command spiWriteBuff[0] = 0x0044; //write to register 1, 1byte(8bits), (0100 0100) /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //config second buffer // spiWriteBuff[7] = 1; //config the sampling frequency to 330 sps duty cycle // spiWriteBuff[6] = 1; // spiWriteBuff[5] = 0; // spiWriteBuff[4] = 0; //set to duty cycle sampling mode // spiWriteBuff[3] = 1; // spiWriteBuff[2] = 1; //set for continuous conversion mode // spiWriteBuff[1] = 0; //disable temp converter // spiWriteBuff[0] = 0; //disable burnout current sensor spiWriteBuff[0] = 0x00CC; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //send write reg command spiWriteBuff[0] = 0x0048; //write to register 0, 1byte(8bits), (0100 1000) /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //config third buffer // spiWriteBuff[7] = 1; //config analog supply as voltage reference // spiWriteBuff[6] = 1; // spiWriteBuff[5] = 1; //config for 60Hz rejection filtering // spiWriteBuff[4] = 1; // spiWriteBuff[3] = 0;//config default // spiWriteBuff[2] = 0;//config for default // spiWriteBuff[1] = 0; // spiWriteBuff[0] = 0; spiWriteBuff[0] = 0x00F0; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //send write reg command spiWriteBuff[0] = 0x004C; //write to register 0, 1byte(8bits), (0100 1100) /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //config fourth buffer // spiWriteBuff[7] = 0; //config default // spiWriteBuff[6] = 0; // spiWriteBuff[5] = 0; // spiWriteBuff[4] = 0;//default // spiWriteBuff[3] = 0; // spiWriteBuff[2] = 0; // spiWriteBuff[1] = 1;//set DREADY/DOUT when data is ready // spiWriteBuff[0] = 0;//reserved spiWriteBuff[0] = 0x0001; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } //optional sanity check to read back all registers with RREG cmd(0x23h) // spiWriteBuff[7] = 0; //not sure if to write to spi or read from spi // spiWriteBuff[6] = 0; // spiWriteBuff[5] = 1; // spiWriteBuff[4] = 0; // spiWriteBuff[3] = 0; // spiWriteBuff[2] = 0; // spiWriteBuff[1] = 1; // spiWriteBuff[0] = 1; // spiWriteBuff[0] = 0x0023; // /* Write the Data to the SPI*/ // result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); // if(CSL_SOK != result) // { // return (CSL_TEST_FAILED); // } // else // { // printf ("SPI Instance Write successfully\n"); // } //send start command (0x08h) // spiWriteBuff[7] = 0; // spiWriteBuff[6] = 0; // spiWriteBuff[5] = 0; // spiWriteBuff[4] = 0; // spiWriteBuff[3] = 1; // spiWriteBuff[2] = 0; // spiWriteBuff[1] = 0; // spiWriteBuff[0] = 0; spiWriteBuff[0] = 0x0008; /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } EZDSP5535_waitusec(100); while(1){ //send read data command spiWriteBuff[0] = 0x0010; //write to register 0, 1byte(8bits), (0001 0000) /* Write the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiWriteBuff, CSL_SPI_BUF_LEN, SPI_WRITE); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Write successfully\n"); } /* Read the Data to the SPI*/ result = SPI_dataTransaction(hSpi ,spiReadBuff, CSL_SPI_BUF_LEN, SPI_READ); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Read successfully\n"); } printf("readBuff = %04x\n", spiReadBuff[0]); } result = SPI_close(hSpi); if(CSL_SOK != result) { return (CSL_TEST_FAILED); } else { printf ("SPI Instance Close successfully\n"); } /* Compare the Data */ for( looper = 0 ; looper < CSL_SPI_BUF_LEN ; looper++ ) { if(spiWriteBuff[looper] != spiReadBuff[looper] ) { return (CSL_TEST_FAILED); } } return (status); }