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.

TMS320F28027: SPI SLAVE RECEIVE

Part Number: TMS320F28027
Other Parts Discussed in Thread: C2000WARE

HELLO,

I am working with SPI of TMS320F28027 Launchpad.i have questions related to it. 

1) what is FIFO mode of spi and why and where to use it. I am not getting  any idea by reading document.

2)when i am only sending data to slave ( msp432 and tms320 acting as master without loop back mode) without FIFO mode and with out spi interrupt (using for loop) then data is sent is correct but when I am trying  to get any data by sending dummy data I am not receiving any data .How to receive data data in master mode with does it always need interrupt to receive data, if not then how to check rxbuf is loaded with data, does it have any flag or bit to check to receive data. 

3) when tsm320f28027 acting as a slave how to receive data without interrup mode.

4) when tms320 is master and sending data in 8 bit mode I am able to send data but while receiving when rxbuf shows correct data but when I am copying to variable rdata by defining it to uint8_t and uint16_t different. Suppose when my rxbuf data is 0xEE    I am receiving it only 0x0E.

  • Ajay,

    1. Which documentation are you reading? The SPI User Guide SPRUG71 describes the functionality of the SPI and the FIFO. I can summarize here. The FIFO allows the application to automate the sending/receiving of data without CPU intervention. To transmit, you load the TXFIFO by writing to the SPITXBUF register up to the number of free spaces in the FIFO. if it was empty, the maximum FIFO depth on F2802x is 4 words. The SPI will then load the first word to the transmit shift register and begin shifting the data out bit by bit. once that word is complete, the RX will grab the data from SPIDAT that it shifted in, and copy it to the RX FIFO, which can be read from SPIRXBUF. The SPI will automatically grab the next word in the TX FIFO and begin transmitting that word. This will occur until the FIFO is empty. by setting the interrupts properly, the SPI can interrupt at any programmed fifo depth. if you want to read 4 words, you set the SPIRXINT to trigger at 4 words. If you want to make continuously transmit data you set the SPITXINT to trigger when the FIFO is almost empty (or some intermediate value) to continually reload the FIFO with more data. I hope this makes sense.

    2. The SPI is essentially a programmable shift register. when the SPI is transmitting a bit, it will also receive the next bit. If you are sending one word at a time, with the FIFO mode off, you poll the SPIINT bit. this indicates that a full word has been received. This bit gives you two critical pieces of information: 1) The SPI has completed transmitting the last word. you can write to the SPITXBUF to initiate the next transfer. 2) The SPI has received a complete word and it is available to be read from the SPIRXBUF register.

    3. as mentioned in the previous bullet, the received data is always read from the SPIRXBUF register. you can poll the SPIINT bit to monitor for a complete transaction and then read SPIRXBUF.

    4. I am not quite sure I understand. Maybe seeing the small piece of code where you read the SPIRXBUF will help clear things up. Since the SPIRXBUF is a 16-bit register, you will need to mask off the upper 8 bits of the register if you only want 8-bit words.

    Please let me know if you have additional questions.

    Thanks,
    Mark
  • Hey Mark,
    this is code i am trying and i have disable FIFO and also not using interrupt .i am sending a single data and comparing in salve and sending response depending on comparison result.
    ""
    uint8_t sdata; // send data
    uint8_t rdata //receive data

    sdata=0x81;
    SpiaRegs.SPICTL.bit.TALK = 1; // Enable Transmit path
    spi_xmit(sdata << 8); // Master transmits data
    while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1); // Waits until data rx’d
    dummy = SpiaRegs.SPIRXBUF;
    delay_loop();

    SpiaRegs.SPICTL.bit.TALK = 0; // for clock is generation
    // Disable Transmit path

    while(SpiaRegs.SPISTS.bit.BUFFULL_FLAG == 1);
    spi_xmit(sdata << 8); // Send dummy to start tx
    while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) {} // Wait until data received
    // is this bit only use in interrupt mode ?
    rdata = SpiaRegs.SPIRXBUF;
    delay_loop();
    ""
  • Ajay,

    Is the above code not working? Your code appears like it should work. You don't necessarily need to manipulate the TALK bit, but it should not affect anything here.

    Have you looked at your SPI configuration? verify that you clock phase and polarity bits are set properly. Verify the requirements of the slave with the Chip select. does it need to be inverted? does it need to remain active in between the Command and response phases?

    If you are working with less than 16 bits, you should also mask your data read in the receive phase to clear out the upper bits. Pop over to this other thread I am working now. It seems that you both are having similar issues (e2e.ti.com/.../655436)
  • Dear mark ,
    I am getting lot of issue while transmitting and receive in slave mode.do you have any sample code of slave mode transmit and receive ,
    Because in sample code there is no code which define proper procedure code to operate in slave mode
  • Ajay,

    Please check out the example in C2000Ware (path is included below). Though this example works for the F28004x device, it can be easily ported to the F28027. It uses the driverlib style of programming, but if you look into each function call, you will see the registers and bits being set. This example uses interrupts.

    C:\ti\c2000\C2000Ware_1_00_03_00\driverlib\f28004x\examples\spi\spi_ex5_external_loopback_fifo_interrupts.c

    With slave mode, data may come at any time unless you program a flow to control and predict what kind of data to transmit or send. i.e. creating a command then response type of transfer. in the command phase, the slave does not have any valid data to send, but once it receives the command, it will fill the transmit buffer to be sent out on the next transfer from the master. In SPI, the master is always in control of the clock, so the slave cannot initiate any transfer.

    I may have another example somewhere, but cannot find it at this time. I should have access to what I need tomorrow.

    Thanks,
    Mark
  • Ajay,

    It has been a few days since you last replied. Have you been able to get up and running? I have not been able to find the example I was looking for, it may have been on an old laptop that I don't have access to anymore.

    Thanks,
    Mark