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.

F28335 SPI problem with AD7699

Hi,

I'm currently having problems communicating via 4-wire SPI between the F28335 and the AD7699. I believe I have the SPI configured correctly on the F28335 by observing the inputs/outputs on a scope. My main two problems are: 1) while trying to configure the SPI clock above a lower freq (above ~5 MHz) it becomes an ugly triangle wave which could or could not be a problem and 2) It looks like I am sending the proper configuration to the ADC on the MOSI but while on the read back configuration setting, the MISO is not properly reading back the configuration or the correct voltage reading output (3.3 VDC). I have attached a scope print out and code below. I used an example program for the SPI setup. Any help is appreciated, thanks in advance.

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

void spi_init(void);

 Uint16 data1;
 Uint16 data2;

void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();

// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();  // Skipped for this example
// Setup only the GP I/O only for SPI-A functionality
   InitSpiaGpio();

// Step 3. Initialize PIE vector table:
// Disable and clear all CPU interrupts
   DINT;
   IER = 0x0000;
   IFR = 0x0000;

// Initialize PIE control registers to their default state:
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   spi_init();   // Initialize the SPI only


// Step 5. User specific code, enablenfiguration();

   while(1)
   {  
 GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1; /* set CS low */


 data1 = spiBSendByte(0x71E0);  /* keep configuration and read back data from IN0 (71E4) from IN1 (73E4) */
 DELAY_US(1);
 data1 = spiBSendByte(0);  /* read back configuration */


 GpioDataRegs.GPBSET.bit.GPIO57 = 1; /* set CS high */

 DELAY_US(6);
   }
}

int spiBSendByte(const unsigned int data)
{
 SpiaRegs.SPITXBUF = data;    /* Load TX buffer with data */

 DELAY_US(6);  /* Delay to load TX buffer */

 data2 = SpiaRegs.SPIRXBUF;   /* Read data from RX buffer */
 
 return (1);

}

void spi_init()  */ SPI setup */
{
   Uint16 dummy;

   SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI

   SpiaRegs.SPICCR.all=0x000F;       //16-bit character
   SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;   // Master mode enabled
   SpiaRegs.SPICTL.bit.TALK = 1; // Transmit capability enabled
   SpiaRegs.SPISTS.all=0x0000;
   SpiaRegs.SPIBRR = 0x0002;           // Baud rate ~ 10 MHz
   SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;  // Rise edge w/o delay
   SpiaRegs.SPICTL.bit.CLK_PHASE = 0;

   SpiaRegs.SPICCR.bit.SPISWRESET=1;  // Enable SPI

   GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1; /* set CS low */
   dummy = spiBSendByte(0xF1E0);  /* Set ADC to factory settings by holding DIN high for two conversions */
   GpioDataRegs.GPBSET.bit.GPIO57 = 1; /* set CS high */
  
   DELAY_US(10);  /* Delay between dummys */

   GpioDataRegs.GPBCLEAR.bit.GPIO57 = 1; /* set CS low */
   dummy = spiBSendByte(0xF1E0);  /* second dummy (F1E4 for IN0) */
   GpioDataRegs.GPBSET.bit.GPIO57 = 1; /* set CS high */
}

 

Yellow = clock,   blue = MISO,   purple = CS (above)  or MOSI (below)

  • Hi Hale,

    1) 5MHz should be no issue for an F28335.  The triangle waveforms you see may be due to a combination of your scope's maximum sampling frequency and the timescale it is set to during capture.  Try going to a smaller timescale and observe the waveform then.

    2) You can try setting the SPI to loopback mode to verify the commands you are sending out to the ADC.  If those commands are correct, perhaps your code is mis-interpreting the data it receives from the ADC.  If you can determine what the raw data the ADC is supposed to send back, you can compare that with the raw data the SPI saves.

    Regards,
    Daniel

  • Daniel,

    Thanks for getting back to me so quickly. As for your first suggestion, I am using a 300MHz scope which should be able to sample quickly enough. For your suggestion on loopback mode, that is what i meant by "read back" in my first post. So, I am sending 0x71E0 and should be receiving that back as well as 3.3 VDC or 0xCE40. As you can see in my scope print outs, the word I'm sending to the ADC is correct, but I am getting back junk.

    My ADC configuration is set up for:

    keep current config, unipolar and inputs referenced to GND, input channel IN0, full BW, external reference and internal buffer, disabled sequencer and to read back current config

  • If you have confirmed the data being sent over SPI using loopback mode, then let's assume the command is being sent to the ADC correctly.  BTW, you are probably doing this, but make sure you disable loopback mode when actually trying to talk to the ADC.

    Assuming the data sent to the ADC is correct, the problem is then in the ADC interpreting the command and responding.  Can you post some shots of the waveforms being sent to the ADC?  I am not familiar with the ADC, but I would first verify the timings and sequencing matches the ADC specs. 

    I took a quick look and it said it requires two dummy conversions to perform configuration.  That would be where I would start looking at.

  • Hale,

    Have you had progress in working through this issue?  If so, what resolution did you get to?

  • Brandon,

    I apologize for not keeping up with the forum. I ended up changing the ADC module I was using in order to more easily communicate with it.

    Thanks,

    Hale