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.

CCS/TMS320F28335: Delfino TMS320F28335

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Dear Sir/Madam,

I am using the function SPI on F28335. I want to interface the F28335 with another board AD9834, which supports 3 wire SPI. I want the F28335 to continuously output five array of control word to AD9834, and the control word will be read on the falling edge of the SPI CLOCK into AD9834's registers. But right now I have no ouput on the pins MOSI and SPICLK, which are GPIO16 and GPIO18, here are my codes in the main file, can you please help me with this pronlem? I think the problems may lies in the condition of "if", but I don't know how to write correct code. What's more, I only want these control words to be output once. Thanks a lot! 

Best,

Jiangwei

#include "DSP28x_Project.h"
void spi_fifo_init(void);
void spi_init(void);
//void error(void);
void delay_loop(void);
void main(void)
{
Uint16 control0;
Uint16 freq0_lsb;
Uint16 freq0_msb;
AN-1070.pdfUint16 phase;

Uint16 reset;

InitSysCtrl();

InitSpiaGpio();

DINT;

InitPieCtrl();

IER = 0x0000;
IFR = 0x0000;

InitPieVectTable();

spi_fifo_init(); // Initialize the Spi FIFO
spi_init();

control0=0x2100;
freq0_lsb=0x50C7;
freq0_msb=0x4000;
phase=0xC000;
reset=0x2000;
SpiaRegs.SPITXBUF=control0;
if(SpiaRegs.SPISTS.bit.INT_FLAG == 1)
SpiaRegs.SPITXBUF=freq0_lsb;
if(SpiaRegs.SPISTS.bit.INT_FLAG == 1)
SpiaRegs.SPITXBUF=freq0_msb;
if(SpiaRegs.SPISTS.bit.INT_FLAG == 1)
SpiaRegs.SPITXBUF=phase;
if(SpiaRegs.SPISTS.bit.INT_FLAG == 1)
SpiaRegs.SPITXBUF=reset;
}

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

void spi_fifo_init()
{
// Initialize SPI FIFO registers


SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x204f;
SpiaRegs.SPIFFCT.all=0x0;
}

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

  • Hi Jiangwei Wang,

    There is a note in the register description of INT_FLAG stating that "This bit should not be used if FIFO mode is enabled. The internal process of copying the received word from SPIRXBUF to the Receive FIFO will clear this bit. Use the FIFO status, or FIFO interrupt bits for similar functionality."

    Also, I recommend you use a loop for the bit state instead of a plain if check

    Regards,
    Veena
  • Dear Veena,

    Thanks for your reply, I modified my code as below, and I got output, but when I deleted the while (1) loop, I got no output again. So I still cannot get the output for only once.
    I am confused about using a loop for the bit state instead of pain if check, can you please write several example lines for this?
    Thanks a lot!

    Best,
    Jiangwei
  • #include "DSP28x_Project.h"
    void spi_fifo_init(void);
    void spi_init(void);
    //void error(void);
    void delay_loop(void);
    void main(void)
    {
    Uint16 control0;
    Uint16 freq0_lsb;
    Uint16 freq0_msb;
    //Uint16 control1;
    //Uint16 freq1_lsb;
    //Uint16 freq1_msb;
    Uint16 phase;
    Uint16 reset;

    InitSysCtrl();

    InitSpiaGpio();

    DINT;

    InitPieCtrl();

    IER = 0x0000;
    IFR = 0x0000;

    InitPieVectTable();

    spi_fifo_init(); // Initialize the Spi FIFO
    spi_init();

    control0=0x2100;
    freq0_lsb=0x50C7;
    freq0_msb=0x4000;
    phase=0xC000;
    reset=0x2000;
    while(1)
    {
    SpiaRegs.SPITXBUF=control0;
    if(SpiaRegs.SPIFFTX.bit.TXFFST==0)
    {
    SpiaRegs.SPITXBUF=freq0_lsb;
    }

    if(SpiaRegs.SPIFFTX.bit.TXFFST==0)
    {
    SpiaRegs.SPITXBUF=freq0_lsb;
    }
    if(SpiaRegs.SPIFFTX.bit.TXFFST==0)
    {
    SpiaRegs.SPITXBUF=freq0_msb;
    }

    if(SpiaRegs.SPIFFTX.bit.TXFFST==0)

    {
    SpiaRegs.SPITXBUF=phase;
    }
    if(SpiaRegs.SPIFFTX.bit.TXFFST==0)
    {
    SpiaRegs.SPITXBUF=reset;
    }
    }

    }

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

    void spi_fifo_init()
    {
    // Initialize SPI FIFO registers


    SpiaRegs.SPIFFTX.all=0xE040;
    SpiaRegs.SPIFFRX.all=0x204f;
    SpiaRegs.SPIFFCT.all=0x0;
    }

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

    Since you using FIFO, you could write directly to the TXBUF upto the 16 data. You need not wait or check for the FIFO status bit.
    if(SpiaRegs.SPIFFTX.bit.TXFFST==0) is actually checking if the Transmit FIFO is empty or not. If you do this check immediately after a write to TX buffer, it may not return a pass since TX might be in progress.

    Regards,
    Veena
  • Hi Veena,

    I also tried it before, without if and directly wrote the six 16-bit control word into TXBUF. And I got output when I added the while(1) loop, but There were no output when I deleted the loop, That's where I am confused a lot of. I  have tried several times but there are no signals on scope, I think it should appear once and then disappear. Can you help me check with this problem?

    Best,

    Jiangwei

  • Hi Jiangwei Wang,

    I am unable to reproduce the issue. I just ran the code you shared and removed the while loop and if conditions and I am able to see the data on the scope.

    I ran it own a different device, but the SPI functionality would be same.

    Regards,

    Veena

  • Dear Veena,

    Thanks a lot for the reply, I guess it's because of my scope. can you please tell me how did you get the signal? did you stop the scope once you saw the signal and use the decoder function of the scope?

    Best,
    Jiangwei
  • Hi,

    I am using Saleae Logic Analyzer. I have configured that to capture the signal for 5 seconds after a rising edge is detected on the SPI channel

    Regards,
    Veena
  • Hi Veena,

    Thanks a lot for the reply, I guess my question got resolved

    Best,
    Jiangwei