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.

SPI in C28XX

Other Parts Discussed in Thread: CONTROLSUITE

Have written following code. The error says unresolved variables Please help

#include "DSP28x_project.h"
#include "dsp2834x_cputimers.h"
#include "dsp2834x_gpio.h"
#include "DSP2834x_spi.h"



void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void error(void);

void main(void)
{
    Uint16 sdata,rdata;  // send data
      // received data
    rdata = 0x0000;
    InitSysCtrl();
     InitSpiaGpio();
    DINT;
     InitPieCtrl();
     IER = 0x0000;
        IFR = 0x0000;
        InitPieVectTable();
        EALLOW;
        spi_fifo_init();      // Initialize the Spi FIFO
           spi_init();          // init SPI
           sdata = 0x0000;
              for(;;)
              {
                                  // Transmit data
                spi_xmit(sdata);
                                   // Wait until data is received
                while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
                                    // Check against sent data
                rdata = SpiaRegs.SPIRXBUF;
                if(rdata != sdata) error();
                sdata++;
              }

          }


void delay_loop()
{
    long      i;
    for (i = 0; i < 1000000; i++) {}
}


void error(void)
{
    asm("     ESTOP0");                        // Test failed!! Stop!
    for (;;);
}

void spi_init()
{
    SpiaRegs.SPICCR.all =0x000F;                 // Reset on, rising edge, 16-bit char bits
    SpiaRegs.SPICTL.all =0x0006;                 // Enable master mode, normal phase,
                                                 // enable talk, and SPI int disabled.
    SpiaRegs.SPIBRR =0x007F;
    SpiaRegs.SPICCR.all =0x009F;                 // Relinquish SPI from Reset
    SpiaRegs.SPIPRI.bit.FREE = 1;                // Set so breakpoints don't disturb xmission
}

void spi_xmit(Uint16 a)
{
    SpiaRegs.SPITXBUF=a;
}

void spi_fifo_init()
{
// Initialize SPI FIFO registers
    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x204f;
    SpiaRegs.SPIFFCT.all=0x0;
}

//===========================================================================
// No more.
//===========================================================================

  • Hi Pranav,

    Have you also included SPI.c in your project?

    Regards,

    Gautam

  • No where can I find that?

  • Pranav,

    This can be found in ControlSuite at \ti\controlSUITE\device_support\f2833x\v133\DSP2833x_common\source\DSP2833x_Spi.c

    -Mark

     

  • Thanks. but I still have some issues:

    1) how do I configure a GPIO as SPI output. I am really confused with that?

    2) Will this program alone can solve the purpose of communicating the C28xx MCU with DAC card?

  • 1) The Spi.c file contains the GPIO setup in the InitSpiaGpio() function. If you wish to pull that into your program as is, or rewrite it how you like, it is up to you. This function contains everything you need: Enable Pullups if desired, select input qualification, and then GPIO Muxing for SPI. The System Control and Interrupts User Guide SPRUFB0 explains our GPIO configurations in more detail.

    2) The program you supplied is similar to the SPI loopback example in ControlSuite. This is just an example code that will transmit and receive its own data. You will need to modify it to work with the DAC card. 

    You will want to look at what the DAC requires for proper communication: What is it's Baud rate? What is the Clocking Scheme? What is the word length? All of this information will be in the DAC's Datasheet/ User Guide.

    -Mark

  • I have included the spi.c file into my project folder. Aslo the program is running without an error. I have a confusion with the baud rate.Does the SPICLK have a fixed frequency? or is it setable?. The max baudrate that the DAC can carry is 50Hz, so how can I set the baud rate in the C28xx card?