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.

TMS320F28388D: SPI clock stops while reading the angle from an encoder

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE, SYSCONFIG

Tool/software:

I want to use the SPI communication feature on the 28388D to get an angle from an absolute encoder - RM44SC (11bit version). It works on the SSI communication protocol and with some figuring out I realized the SPI works for this. I followed the guidelines given here - https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/981032/tms320f28379d-reading-the-angle-from-a-ssi-encoder-using-spi, to generate the clock signal. I am able to generate the clock signal and the sensor responds with the corresponding position data. However, once I enable the read statement, the clock signal stops transmitting anything and gets latched on to a high signal. And this provides no data in the output. Given below is my SPI settings and the dummy word I write to the sensor. Now when I comment out line 335 (check out second screenshot), SPICLK generates the train of clock pulses needed, but when I un-comment it out, the SPICLK just stops and goes to a high value.

  • Hello,

    This waits for data to be received before reading from the buffer. If there is not data being continually communicating between devices, the SPICLK will halt. The SPICLK is only active during communication.

    Also, are you using FIFO or nonFIFO mode? This function should not be used when FIFO mode is enabled.

    Best Regards,

    Allison

  • Hello Allison, 

    Thanks for this guidance. I recognized this mistake and was able to rectify it. I tried the following steps

    1) I enabled the FIFO transmit mode in the SPI_setconfig() function, and I changed my SPI read and write functions appropriately (check screenshots below). 

    2) When I run this piece of code, I see from my scope (I've probed on the differential output end of a transceiver) that there is continuous clock black) being sent to the sensor and there is differential data as expected from the sensor (blue). I use the serial communication feature on my scope to decode the information from the sensor and it makes sense. However I receive no data on my end. I see that my single end side (0-3.3V) output of my transceiver that goes to the DSP works and is line with my differential data. I understand that there might be an issue with the way I set my receive/read registers? I've also added a screenshot of the SPI registers during run time for your reference. As you can see the read buffer is at 0xAFFF completely different and does not change at all. The TXBUF has the dummy word that I give to the sensor. 

    3) Here is a screenshot of my GPIO settings, I've made sure the physical pin mapping to the GPIO numbers are correct on my hardware. 

    Also another note, for some weird reason, I keep my clock at 500kHz, and my transmit delay at 9, and only then I get a delay of 20us between my clock cycles. 

    Thanks!

    Pranav

  • Hi Pranav,

    Thanks so much for the information. Please allow another day for me to review this and get back to you.

    Best Regards,

    Allison

  • Hi Pranav,

    Just wanted to let you know I will try to get back to you this week, but please note I am out of office the next few days.

    Best Regards,

    Allison

  • Hello Allison,

    No problem , thanks for looking into this. Your help is very much appreciated. Meanwhile I am trying different approaches on my end and will update accordingly. 

  • Hello,

    Allison is out of office until Tuesday 9/3, so please expect a response next week. I apologize for any inconvenience.

    Best Regards,
    Delaney

  • Hello Pranav,

    Thanks so much for the patience as I was out. Have you tried other approaches in the mean time? Let me know if you are still facing issues or have another update.

    Best Regards,

    Allison

  • Hello Allison,

    No worries. I have no other update for you. Unfortunately I am stuck at a dead end.

    I guess the core of the issue that I face is that I don't seem to have a basic code for the 28388D microcontroller with SPI functionality specifically in the Driverlib format. Hence I try to understand the register setting from existing bitfield examples and recreate it on my own in the driverlib format, but with little success. Could I please get an example spi code in the driverlib format for the 28388D to start with? I do not see this specific example in resource explorer to get started with.

    Thanks!

  • Hi Pranav,

    No worries at all. We have quite a few examples available in our C2000Ware SDK. The F2838x DriverLib-based SPI examples specifically can be found in the directory C:\ti\c2000\C2000Ware_5_02_00_00\driverlib\f2838x\examples\c28x\spi.

    Please take a look at these - there are some simple internal loopback examples (where RX and TX are internally tied together in "loopback mode") to help test if your SPI module is set up correctly, and then there are some external loopback examples as well that you may find helpful. 

    Please also note that these examples also use our CCS graphical user interface, SysConfig. So you may notice when you import the examples to CCS they contain a .syscfg file. In the examples, when "board_init()" is called, the Sysconfig-generated C code is implemented (you can always view the generated driverlib C code within the SysConfig window). There are some video series and documentation on how to use Sysconfig if you need those as well, just let me know!

    Let me know if you have any questions regarding them or if you find them useful!

    Best Regards,

    Allison

  • Hello Allison, 

    I did take a look at the example file that you suggested, specifically the 28388D_spi_external_loopback. For some weird reason I wasn't even able to run the example code on my end. However I was able to get into the source code and understand how the registers are modified. For most part my code is same apart from the fact that I need to run it in FIFO mode, in order to set custom delays between clock cycles and read the incoming data. Here is my code snippet for your reference.

    When I run this piece of code, I have two issues. First, the TX delay that I am setting in the code is not reflecting on the hardware. This is for whatever number I key in the TxFifoTransmitDelay fcn. Secondly, the variable 'Sensor' keeps reading only 45055 although I can see that my sensor spits out some other value and changes as I physically spin the motor. Somehow my read buffer and hence the variable Sensor is not catching it? 

    Thanks!

  • Hi Pranav,

    Glad the examples were at least helpful as a reference.

    It is concerning that the example is not working out of the box, so I'd like to make sure we establish that as a basis. Can you please make sure you are using the latest C2000Ware 5.02? There were driverlib functions that were updated from past versions.

    The next suggestion is that it is always good to triple check the hardware - are you able to scope the pins and see activity? Are you having trouble compiling the project at all or seeing specific software issues? 

    On the transmit delay - are you using the registers window in CCS to double check the transmit delay is present/configured in the SPI regs? Delay should be implemented between words if it is there.

    If you verified that the sensor is sending expected values to the C2000, but the value read into the Sensor variable on the C2000 is incorrect, there is likely some configuration setting issue - have you double checked that the clock mode agrees with both devices? 

    Best Regards,

    Allison