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.

28335 SPI Problem

Hi,

I am new learner of 28335, now I want to use SPI of 28335 to interface with a DA chip. But it can't work well. the following is my program

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

// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
void spi_fifo_init(void);
void spi_init(void);

void main(void)
{
   Uint16 sdata;  // send data
  
   InitSysCtrl();

   InitSpiaGpio();

   DINT;

   InitPieCtrl();

   IER = 0x0000;
   IFR = 0x0000;
  
   InitPieVectTable();
   
   spi_fifo_init();      // Initialize the Spi FIFO
   spi_init();          // init SPI

   EALLOW;   
   GpioCtrlRegs.GPADIR.bit.GPIO19 = 1;   // Configure outputs
   GpioDataRegs.GPASET.bit.GPIO19=1;
   EDIS;

   sdata = 0x000F;                           
   for(;;)
   {    
      EALLOW;
    GpioDataRegs.GPACLEAR.bit.GPIO19=1;
    EDIS;
     SpiaRegs.SPITXBUF=sdata;
     // Wait until data is received
     while(SpiaRegs.SPISTS.bit.INT_FLAG ==1)
      {   
       EALLOW;   
       GpioDataRegs.GPASET.bit.GPIO19=1;
       EDIS;
       SpiaRegs.SPIRXBUF=SpiaRegs.SPIRXBUF;
       }
   }
}    


// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:   

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 =0x0004;                                   
    SpiaRegs.SPICCR.all =0x008F;                 // Relinquish SPI from Reset  
    SpiaRegs.SPIPRI.bit.FREE = 1;                // Set so breakpoints don't disturb xmission
}


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

 

I programmed it based on the tutorial SPI Loopback.I don't need interrupt and here I just want to sent a fix data to test it.

the question is  I am not sure the pin the status of SPISTE pin should determined by the programmer or not. It is the reason why I changed the GPIO 19 status in program because I want to use this pin as the CS signal of the DA chip( when the data was transmitted, SPISTE is low and after the transmission is finished, the SPISTE is high). And I already defined the SPISTE as the GPIO in SpiaGpio function. And the SPISTE pin status changed but not right. So I am thinking is this term SpiaRegs.SPISTS.bit.INT_FLAG ==1 not right?  Since I want to use this term to check if the tranmission is completed or not.

hope someone can help me or figure where is the problem.

thanks for the help

  • You made the mistake in here:

    while(SpiaRegs.SPISTS.bit.INT_FLAG ==1)
          {   
           EALLOW;   
           GpioDataRegs.GPASET.bit.GPIO19=1;
           EDIS;
           SpiaRegs.SPIRXBUF=SpiaRegs.SPIRXBUF;
           }

    while you wait for the SPI to finish, you should not disable your CS!

    The correct code would be:

    while(SpiaRegs.SPISTS.bit.INT_FLAG ==1);     
    GpioDataRegs.GPASET.bit.GPIO19=1;
    SpiaRegs.SPIRXBUF=SpiaRegs.SPIRXBUF;

    Regards


         

  • thanks for replying

    I changed like your suggestion, but the results still are not right

    the channel one is the SPISTE output, and the channel two is the SPISIMO output.

    do you have any suggestion?

    thanks!