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/TMS320F2808: Simulink R2018a SPI: Send and Receive more than 16 words

Part Number: TMS320F2808

Tool/software: Code Composer Studio

Hi everyone,

I have a question concerning Simulink. Starling from MATLAB R2017b, Simulink can receive and send Nx1 vector from SPI interface, N can be 50, 100, etc but my processor's(f2808) RXFIFO and TXFIFO size is limited, which can hold 16x1 vector at one time. I verify this by checking the registers of the processor while SPI communication is happening. For instance, I send 50x1 vector from master to my slave(F2808), lets say numbers from 1 to 50 but in registers, I see the last 16 number, which are from 35 to 50. I think this is a huge problem. I am using R2018a version. I appreciate any help.

  • Hello,

    We recommend you to also contact the Mathworks support at : www.mathworks.com/.../.


    Regards,
    Sudhakar
    ---------------------------------------------------------------------------------------------------
    If a post answers your question, please mark it with the "verify answer" button.
    Other useful links:
    C2000 Getting Started      C2000 Flash Common Issues/FAQs      Emulation FAQ
  • Hi,

    Thanks for the advice but I do now want this question to be marked as TI Thinks Resolved, I want to keep it unsolved and maybe it will attract some user's attention.

    Thanks
  • So it depends on how you are looking at the registers and when.

    Obviously the SPI only has the 16 word FIFO, so the transmission of more than that will need to be managed. As you are using the MATLAB generated code, I do not know how that is implemented and the MATLAB team will have better insight. As the F2808 is the slave, and it receives 16 words, you would only be able to see the first of the 16 words present in the FIFO by looking at the SPIRXBUF register. You need to read out all of the data in the FIFO and into an array or structure to use elsewhere in the program.

    -Mark
  • Hi,

    You can use SPI Tx interrupt on the Tx FIFO to send the chunks of data inside the ISR.

    For example if you have 50 data values, then you can split the data values in to 5*10.

    Configure the Tx FIFO for depth of 10 and use a counter to count 5 sending 10 data values every time.

  • Configure the Tx FIFO for depth of 10 and use a counter to count 5 sending 10 data values every time.

    -By ISR, do you mean that I should use SPIRXINT and SPITXINT?

    -Will this mean to manually changing the generated code from Simulink in CCS or can I just simply configure this from Simulink model? PS:I know how to set Tx Interrupt level from Simulink model( Configuration Parameters). I just want to know if there is any way to use SPI Tx Interrupt level in the Simulink model. If there is a way, it would be really easy. If not, then I would have to manually change the code from CCS(by adding code to the model_step()).

    -I understood what you try to say but wouldn't it be better first to make sure that slave side correctly receives 50x1 vector?

    -Also will this mean to do 5 transmit processes against 1 receive process? But again I think I need to make sure that I receive the incoming vector correctly before transmitting something. Maybe same thought is vaild where RX Interrupt can be used and incoming vector can be read in 5 pieces as 10x1.

  • Hi,
    I think venkatesh can answer from the Simulink side, but I can address the SPI aspects.

    - If you need to also receive 50 words, yes you would need to set up the RX ISR as well to handle reading the RX FIFO. You would need both SPIRXINT and SPITXINT.

    - AFAIK, that is what the simulink should be able to do. I have not worked with it before so I can't say for sure. , can you address this?

    - It really depends on your slave, sending 1 word at a time is really not much different than sending more than 1.

    - You would need to match the number of processes between master and slave. As you are aware, the SPI FIFO can only transmit/receive up to 16 words before needing to be serviced. If you do not handle the receive side at the same rate as the transmit, you run the risk of having overflow in the receiver.

    To help understand the SPI and FIFOs, try running the SPI FIFO loopback example for the F2808. you adjust the how many total words you need to send, the FIFO interrupt levels and other things. See how they affect the transmission you can try 10 bursts of 5 words, 5 bursts of 10 words, 50 bursts of 1 word, you can even have the transmitter and receiver interrupt levels different. Once you understand the SPI module intimately, you can then add the abstraction of the Simulink model, and I bet you will know exactly what knobs to turn to make it do what you want.

    FYI, I will be out of the office until Jan 2, after today. I will try to see if someone who is not taking as much time off can monitor this thread, but cannot guarantee anything.

    Happy Holidays.
    -Mark