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/TMS320F28377S: How to save 4 real time data(bytes) coming over SPI MISO line into four distinct variables?

Part Number: TMS320F28377S
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hi,

I am working on SPI communication between TMS320F28377s and third party embedded hardware.

Currently much interested in a floating point number exchange between my TI board and third party hardware . Third party hardware has limitation of transmitting as well as receiving only 8bits(1byte).

So, I have typecasted float to char  and I am sending 4 bytes from TI to third party hardware and I am receiving back 4 bytes from third party hardware to TI.

On TI side I am receiving 4 bytes immediately one after other in 16 bit SPIRXBUF. These bytes are overwritten, so my question is how to save the one by one byte before it gets overwritten in SPIRXBUF.

Can any one please help to answer this issue?

Regards,

Narayani

  • Narayani,

    Have you enabled the FIFO on the SPI? You can store up to 16 x 16bit words in the SPI before any data is overwritten. Please refer to the TRM as well as the examples found in C2000ware for more information on the FIFO. I will describe a basic configuration and usage for you to work with.

    Configure the SPI with the the RX FIFO to interrupt at 4 words. ensure that the TXFIFO is enabled so you can write multiple words and let the SPI transmit them without CPU intervention.

    whenever you are ready to receive data from the slave. you can write 4 words to SPITXBUF and move on to other actions. Once the SPI has received 4 complete words, the CPU will be interrupted by the SPI. You can get the contents of the RXFIFO by reading SPIRXBUF 4 times and storing/packing the 8-bit data into an array.

    I hope this helps!
  • Hello Mark,

    I tried out the solution suggested by you. I configured my SPIFFRX contents as 0x0A2A (i.e., RXFFST and RXFFIL as 10h, Receive FIFO has 16 words, which is the maximum) and in RXFIFO ISR, I am reading the SPIRXBUF 4 times (may be the way I am doing is wrong) but still I am unable to get the 4 bytes.

    I have disabled TXFIFO mode. As soon as I received data into RXBUF, I send it back to the third party hardware in the void main() only. I am receiving proper bytes at the other side. So as suggested by you, Do I need to configure TX into FIFO mode?? I am attaching my code which will give you clear idea about my doubts.


    #include "F28x_Project.h"
    #include "stdio.h"

    Uint32 rdata[2];     // Receive data buffer
    char *ptr_rdata;     // Receive data buffer
    Uint16 rdata_point;  // Keep track of where we are
    char res[20];
    float n=8.6857;
    unsigned char *chptr;
    unsigned char *chptr1;
    unsigned char *chptr2;
    unsigned char *chptr3;
    unsigned char *chptr4;
    unsigned char arr[4];
    unsigned char TempBuf = 0;
    Uint32 TempBuf1_rx;


    interrupt void spiTxFifoIsr(void);
    interrupt void spiRxFifoIsr(void);
    void delay_loop(void);
    void spi_fifo_init(void);
    void error();


    void main(void)

    {
       Uint16 i;

      InitSysCtrl();

       InitSpiaGpio();

       DINT;
       IER = 0x0000;
       IFR = 0x0000;
       Uint16 count;

       InitPieCtrl();

       InitPieVectTable();

       EALLOW; 
       PieVectTable.SPIA_RX_INT = &spiRxFifoIsr;
       PieVectTable.SPIA_TX_INT = &spiTxFifoIsr;
       EDIS;  

       spi_fifo_init();   // Initialize the SPI only

       PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   
       PieCtrlRegs.PIEIER6.bit.INTx1 = 1;   
       PieCtrlRegs.PIEIER6.bit.INTx2 = 1;   
       IER=0x20;                            
       EINT;                                


       for(;;)
       {
                if(rdata[0] != 0)
                {
                  int i=0;
                  sensor[0] = (float)rdata[0]*8.6857;
                  //sensor[0] = (float)rdata[0]*1;
                  chptr=(unsigned char *)&sensor;
                  //byte by byte transfering
                  while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG);
                  TempBuf = ((*chptr) & 0xff00);
                  SpiaRegs.SPITXBUF = (uint16_t)TempBuf;// << 8) & 0xFF00);
                  delay_loop();
                  while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG);
                  TempBuf = ((*chptr) << 8 & 0xff00);
                  SpiaRegs.SPITXBUF = (uint16_t)TempBuf;// << 8) & 0xFF00);
                  //delay_loop();
                  while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG);
                  TempBuf = (*(chptr + 1)  & 0xff00);
                  SpiaRegs.SPITXBUF = (uint16_t)TempBuf;// << 8) & 0xFF00);
                  //delay_loop();
                  while (SpiaRegs.SPISTS.bit.BUFFULL_FLAG);
                  TempBuf = (*(chptr + 1) << 8 & 0xff00);
                  SpiaRegs.SPITXBUF = (uint16_t)TempBuf;// << 8) & 0xFF00);
                }
      }


    }


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


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

    void spi_fifo_init()
    {
     
        SpiaRegs.SPIFFTX.bit.SPIRST = 0;
        SpiaRegs.SPIFFTX.all = 0x0000;   
        //SpiaRegs.SPIFFTX.all = 0xC022;      
        SpiaRegs.SPIFFRX.all = 0x0A2A;
        SpiaRegs.SPIFFRX.bit.RXFFST=A;
        SpiaRegs.SPIFFCT.all = 0x00;

        //SpiaRegs.SPIFFTX.bit.TXFIFO=1;
        SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;

        SpiaRegs.SPIFFTX.bit.SPIRST = 1;

        InitSpi();
    }



    /*interrupt void spiTxFifoIsr(void)
    {
        Uint16 i;
        SpiaRegs.SPITXBUF=sdata[0];
     

      for(i=0;i<2;i++)                  
        {
           sdata[i] = sdata[i]+5;
        }

        SpiaRegs.SPIFFTX.bit.TXFFINTCLR=1;
        PieCtrlRegs.PIEACK.all|=0x20;       //
    }*/


    interrupt void spiRxFifoIsr(void)
    {
        Uint16 i=0;


        rdata[0] = ((SpiaRegs.SPIRXBUF)& 0x00FF);
        chptr1 = (unsigned char *)&rdata[0];
        rdata[0] = ((SpiaRegs.SPIRXBUF)& 0x00FF);
        chptr2 = (unsigned char *)&rdata[0];
        rdata[0] = ((SpiaRegs.SPIRXBUF)& 0x00FF);
        chptr3 = (unsigned char *)&rdata[0];
        rdata[0] = ((SpiaRegs.SPIRXBUF)& 0x00FF);
        chptr4 = (unsigned char *)&rdata[0];



           //SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1;  // Clear Overflow flag
        SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1;  // Clear Interrupt flag
        PieCtrlRegs.PIEACK.all|=0x20;       // Issue PIE ack
    }

    Thanks and regards,

    Narayani

  • Narayani,

    Sorry for the delay. Yes, you can enable the TXFIFO so that you can write 4 words to the FIFO at SYSCLK speed and let the SPI handle the transmit/receive at the SPICLK rates. This will free up the CPU to handle other things until the RX FIFO ISR is triggered.

    A few questions-
    Have you resolved your issue on your own?
    What is your data-flow supposed to look like? Constant data stream? On demand, 4-byte bursts?
    Do you need to echo each byte on the next byte or is it a burst type of echo (receive 4 bytes, then echo 4 bytes).
    Is the F28377S the Master or Slave?

    Thanks,
    Mark
  • Hi Mark,

    I actually resolved the issue.

    And yeah, my data flow should look like a float data exchange between two platforms. As I am using SPI communication, I am converting float to 4 bytes char.

    Its not a constant data stream, its changing every clock cycle. I don't want to echo the bytes. F28377S is a slave in my case.

    Now my next challenge is the 4 bytes can take any values from 00 to FF (0 to 255). And my dummy byte can also anything from 0 to 255. I have taken it as 255 for my sake. If I dont send and receive dummy byte I am unable to collect 4 bytes in proper sequence. If sequence gets disturbed, float value will change, which will cause errors. So can any one please help me how can I receive proper 4 bytes without any dummy byte or any other ideas will also be helpful. I am attaching dummy byte condition of my code for better understanding.

    interrupt void spiRxFifoIsr(void)
    {

        RByte = (unsigned char)(SpiaRegs.SPIRXBUF & 0x00FF);

        if (RByte == 255)
            cnt1 = 0;
        else if (RByte != 255 & cnt1<=3 )
        {
            string2[cnt1] = RByte;//(unsigned char)(SpiaRegs.SPIRXBUF & 0x00FF);
            cnt1 = cnt1+1;

         }


        //SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1;  // Clear Overflow flag
        SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1;  // Clear Interrupt flag
        PieCtrlRegs.PIEACK.all|=0x20;       // Issue PIE ack
    }

    In above condition what happens is if any of 4 bytes apart from dummy byte then this condition is failed and if I ignore this then the sequence in string2[cnt1] array is disturbed. So kindly suggest some solution to it. This is a piece of code under ISR. Rest code I have attached in previous posts.

    Thanks in advance,

    Narayani