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.

Basic SPI communication problem ( 28016 )

Hello,
Right now I am starting to deal with SPI communication. I use 28016 and I wrote a small program just to read out a sensors register (addr. 0x04). The code is a mixture of TI´s SPI FIFO examples and hints from another thread.

This is the code:

#include "DSP280x_Device.h" // DSP280x Headerfile Include File
#include "DSP280x_Examples.h" // DSP280x Examples Include File

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

Uint16 sdata,dummy=0; // send data,dummybyte
Uint16 rdata,int_clear; // received data

void main(void)
{
InitSysCtrl();
InitSpiaGpio(); //GPIO19=Gpio
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
spi_init();

GpioDataRegs.GPACLEAR.bit.GPIO19=1; //chip-select = low

for(;;)
{
sdata = 0x0010; //registeraddress I want to read from (0x04 + R/W + 0)
int_clear=SpiaRegs.SPIRXBUF; //read RX buffer to clear int flag
SpiaRegs.SPITXBUF=sdata; //write address
SpiaRegs.SPITXBUF=dummy; //write dummy
while(SpiaRegs.SPISTS.bit.INT_FLAG !=1){} //wait for spi int
rdata = SpiaRegs.SPIRXBUF; //receive data
}
GpioDataRegs.GPASET.bit.GPIO19=1; //chip-select = high (warning:statement unreachable?)
}

void spi_init()
{ SpiaRegs.SPICCR.all =0x0047; // Reset on, falling edge, 8-bit char bits
SpiaRegs.SPICTL.all =0x0007; // Enable master mode, normal phase, talk and SPI int
SpiaRegs.SPIBRR =0x007F;
SpiaRegs.SPICCR.all =0x00C7; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}

//EOF

The problem is that I got stuck in the "wait for spi int"-while expression.
I also get a warning for the line where I put the chip-select back to high, but that is caused by the placement behind the infinite loop I guess.
If anyone has ideas about this, I appreciate it.

Regards Stephan
  • Hi

    I am working with Flash memory through SPI.

    My code looks like that:

    ReadPage( ... ...)

    {

    ... 

    SendFlashCmd(READ);    // Send READ command
    ...

    ...

    }

    void SendFlashCmd(char cmd)

    {

    SpiaRegs.SPITXBUF = cmd << 8; // Send command

    PollSPIInterrupt();

    }

    void PollSPIInterrupt()

    {

    char dummy; // dummy character to access read SPI

    while (!SpiaRegs.SPISTS.bit.INT_FLAG) {} // Check that command is sent

    dummy = SpiaRegs.SPIRXBUF; // Reset Interrupt flag

    }

  • Hi Yvon

     

    thank you for your reply. I am not sure why but the example code I posted above works when I do not write the dummy byte (line above bold one). Since I am working on another problem I will leave SPI for a while. If I find an explanation for this or if it was not the solution I will post it here.

    regards stephan