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.

TMS320F28035: help for SPI communication for reading and writing data to slave chips

Part Number: TMS320F28035
Other Parts Discussed in Thread: C2000WARE

Hello

   I try to use SPI communication to read and write the data to sensor chip. It is 4 wire SPI communication and 28035 is used as Master mode. For the sensor chip, the data transfer starts with falling edge of CSn(pin 19)  and SPI commands are executed at the rising edge of CSn.  However, it seems that I can read and write data correctly. I wrote something as follows. Could anyone help me to find the problem? It is my first time to use SPI and any help is appreciated.

#define SPI_WRITE_MICRO(v) \
SpiaRegs.SPITXBUF = v; \
GpioDataRegs.GPACLEAR.bit.GPIO19 = 1; \
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }\
GpioDataRegs.GPASET.bit.GPIO19 = 1; \
spi_read_dummy = SpiaRegs.SPIRXBUF;

#define SPI_READ_MICRO(v) \
SpiaRegs.SPITXBUF = spi_write_dummy;\
GpioDataRegs.GPACLEAR.bit.GPIO19 = 1; \
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { } /*Check against sent data*/ \
GpioDataRegs.GPASET.bit.GPIO19 = 1; \
v = SpiaRegs.SPIRXBUF;

 

  • Lee,

    Have you checked out the examples in c2000WARE? it should help you get a basic understanding of the module and how it works. Please read through the User guide as well (http://www.ti.com/lit/SPRUG71)

    I think you have a typo and mean to say that you are NOT able to read and write data correctly?

    First thing, once you write to SPITXBUF, the SPI will begin transmitting. Since the next thing you do is enable the slave, it is possible that you are violating the slave timing requirements. The word will be actively coming out of the SPI when the slave is enabled. You are running the risk of missing the first bit(s) of the transmission. At a minimum, you will want to assert the chip select before you write the the SPITXBUF.

    Alternately, if this is the only slave, you can let the SPI drive the chip select signal. Make sure that you are setting up the GPIO mux before you start the tranmission. By allowing the SPI to control the chip select signal (SPISTEA), you will not need to waste extra cycles controlling the GPIO during your communication.

    As this is your first time working with the SPI, I highly recommend that you mess around with the examples. If you have a development kit, you can wire up two SPIs, and write code for both the master and slave and see how they work together. The user guide and many other sources on the web are great resources for SPI. Its a pretty simple module and many, many devices in the world use it.

    Please let me know if you have additional questions.

    Thanks,
    Mark
  • Hello Mark,
    Thank you for quick reply. I read the SPI document again and may need your help to clarify my understanding.
    1. Regarding SPISTE pin, in master mode, is it automatically controlled? I mean this pin is driven low before transmission and set high after transmission and there is no need to control it.
    2. What is difference between write to SPIDAT and to SPITXBUF in Master mode? If data is written to SPITXBUF, Does SPI first transfer existing data in SPIDAT and receive data from slave, after received data is transfer to SPIRXBUF, the written data is transferred? If only one word is transferred , do I need to write to SPIDAT instead of SPITXBUF?
    Thank you.

    lee
  • Lee

    1. Yes, in Master mode, the SPI will automatically control the SPISTE chip select pin. It will be driven to the active state before starting to transmit and will de-assert after the last word is transmitted. The SPI will keep SPISTE active as long as there is data to transmit.
    2. SPIDAT is the shift register. You can write to this register and the transmission will start. during the transmission, you will see the state of this register change. After the transmission has completed, the SPI will copy the data from SPIDAT to the SPIRXBUF. If you are only writing one word at a time and reading it before transmitting the next word, yes, you can just use SPIDAT.

    Regards,
    Mark