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.

TMS320F28379D: 1 McBsp, 2 SPIs communication

Part Number: TMS320F28379D

Hello,

I have to communicate a  spi slave on Tx side and a  spi master on Rx side of the McBsp. I have three lines to Rx and Tx each. (Data, Clk, CS) So it is half duplex coming to slave. ( Master->Rx(slave) and Tx(Master)->slave) . I should be able to communicate on both channels parallel. I am assuming clock stop mode is not the way here as clocks and CS are internally connected. Because (correct me if I am wrong) if Tx(Master) tries to send data to slave, the Rx(Slave)'s clock and CS will be driven internally forcing the Rx(Slave) to read 0 values.I will connect the SPI Master lines to MCLKR, FSR, MDR. And Tx(Master) would drive MCLKX, FSX , MDX.

That brings me to my McBsp receive. These are my configurations please let me know if I am correct. 

  • RxFrameSyncSource- External (at FSR)
  • RxFrameSyncPolarity- Low ( CS active low)
  • InterruptSource - ISR_Source serial word
  • EnableSRGSyncFSR- detects the FSR pin low and syncs the SRG: Does that mean Rx frame sync source will be internal then?
  • RxClockSource: external at MCLKR
  • SRG clock source LSPCLK
  • SRG data clock divider:100. Is there a possibility for Clock to cause problems?

Below is the SPI Master to Rx(slave) Signal, I am just sending 32 bit data.

To the transmit Tx now, I have not cross checked this yet

  • I am assuming FSX would be a pulse and not a standard CS low signal. Does this mean I cannot use McBSP standard and should jump to Clock stop mode or can I actually make it CS low?

Thank you

Varun

  • Hey Varun,

    Thanks for reaching out about this issue you are experiencing. I am looking into it now and will get back to you before End-of-Day Friday (11/30/18). In the mean time go ahead and take a look a Chapter 6: SPI Operation Using the Clock Stop Mode in the following

    McBSP User Guide Document: http://www.ti.com/lit/ug/sprug80a/sprug80a.pdf.

    Sections 6.6 and 6.7 discuss setting up the McBSP peripheral as a SPI Master and SPI Slave. A quick skim of the information tells me that Clock Stop Mode should probably be used which will also cause the Frame Sync Sources to be internal. I will dig a little deeper myself and let you know if I find anything further.

    Respectfully,

    Zackary Fleenor

  • Varun,

    Another possibility would be to take advantage of the second McBSP peripheral located on the device (McBSPA & McBSPB). I do not fully understand what you are trying to accomplish with the single McBSP module. If you have any further details that may help please share .

    Respectully,
  • Hi Zack,
    We are using only McBSP for now. But I am cross checking if we can actually make this happen. I want to send data at different time or simultaneously as well on both ends. Also if this is not possible I would appreciate if we can configure it for only Master-> Slave(Rx). That's my first priority. So later we can change it to two McBSP's hopefully.

    Thanks

    Varun

  • Hi Zackary,

    I think I cannot do a SPI operation and right now I am focusing on the receiving side of the McBSP without SPI operation. So I have taken the External Loopback example. I am working on TMS320F28379D launchpad.  The following changes I have made to match for 32 bit SPI message of what I am sending, please let me know if it is right.

    void initReceiver(uint32_t base)
    {
        //
        // Configure McBSP data behaviour.
        //
    
        McBSP_setRxDataSize(base, MCBSP_PHASE_ONE_FRAME, MCBSP_BITS_PER_WORD_32, 0);
    
        //
        // Set Rx data delay to 1 cycle.
        //
        McBSP_setRxDataDelayBits(base, MCBSP_DATA_DELAY_BIT_1);
    
        //
        // Set receive sign-extension and justification mode.
        //
        McBSP_setRxSignExtension(base, MCBSP_RIGHT_JUSTIFY_FILL_ZERO);
    
        //
        // Configure Rx frame-sync behaviour.
        //
    
        //
        // Set Rx frame sync source as external.
        //
        McBSP_setRxFrameSyncSource(base, MCBSP_RX_INTERNAL_FRAME_SYNC_SOURCE); 
        McBSP_setRxClockPolarity(MCBSPB_BASE, MCBSP_RX_POLARITY_RISING_EDGE);
       
    
        //
        // Disable DLB mode.
        //
        McBSP_disableLoopback(base);
    
        //
        // Set no external clock sync for CLKG i.e. GSYNC = 0.
        //
        McBSP_enableSRGSyncFSR(base);
    
        //
        // Configure Rx clock behaviour.
        //
    
        //
        // Set MCLKR pin as source for CLKR.
        //
        McBSP_setRxClockSource(base, MCBSP_EXTERNAL_RX_CLOCK_SOURCE);
    
        //
        // Set LSPCLK as input source for sample rate generator.
        //
        McBSP_setRxSRGClockSource(base, MCBSP_SRG_RX_CLOCK_SOURCE_LSPCLK);
    
        //
        // Set Divide down value for CLKG.
        //
        McBSP_setSRGDataClockDivider(base, 49);
    
        McBSP_setRxFrameSyncPolarity(MCBSPB_BASE, MCBSP_RX_FRAME_SYNC_POLARITY_LOW);
    
        //
        // Wait for CPU cycles equivalent to 2 SRG cycles-init delay.
        // Total cycles required = 2*(SYSCLK/LSPCLK). In this example
        // LSPCLK = SYSCLK/4.
        //
        MCBSP_CYCLE_NOP(8);
    }
    

    Now, I am sending one 32 bit word always, out of ten tries I am reading it only once and that too with bits shifted 1 or 2 places left or right. I am giving external connection to MCLKR, MDR and FSX. Once I read a word with bit shifted I will never be able to read another word again. Did anybody have this problem before?

    The SPCLKis running at 50MHz, so I used 49 divider to bring it down to 1MHz and I am sending with 1MHz as well. Let me know if you got anything

    Regards

    Varun

  • Hey Varun,

    I am starting to make sense of the issue. Thank you for your patience while I have been looking into this. If you have time, take a look at the following previous forum post (you can ignore the DMA information) :

    Make sure that your Clock Configuration registers are all set correctly.

    This is found in the code posted above:

        //
        // Set no external clock sync for CLKG i.e. GSYNC = 0.
        //
    
        McBSP_enableSRGSyncFSR(base);

    This function actually enables the clock sync. You would want:

    McBSP_disableSRGSyncFSR(base);

    to match the comment, unless this was done on purpose.

    There may be an issue with your sample rate generator configuration since you are using an external clock. Review section 15.4.3 and 15.4.4 and ensure it is properly setup.    

    After reading your initial post again I wanted to address your transmit question. While the clock stop mode would be ideal for your application it would not allow you to separate the operations (Tx pins as Master for external SPI Slave, and Rx as Slave fir external SPI Master). To do this you would need to utilize both McBSP modules one as slave one as master.

    Since you are trying to accomplish this communication on the single module you need to look at the options for Setting the Transmit Frame-Synchronization Mode (section 15.9.15) which allows you to supply from an external source.

    Look through these suggestions and see if anything clicks. If the issue continues to arise re-post and we will see if we can find a better solution. :)

    Respectfully,

  • Hi Zackary,

    Yes McBSP_enableSRGSyncFSR(base); function call was intentional sorry did not change the comment.

    I am still having problems communicating with SPI on receiving side.  Please review my code below

    void initTransmitter(uint32_t base)
    {
        //
        // Right justify word.
        //
    
    
        //
        // Set Rx & Tx delay to 1 cycle.
        //
        McBSP_setTxDataDelayBits(base, MCBSP_DATA_DELAY_BIT_0);
    
    
        //
        // Configure McBSP data behaviour: phase = 1; frame length = 1 word and
        // word length = dataSize.
        McBSP_setTxDataSize(base, MCBSP_PHASE_ONE_FRAME, MCBSP_BITS_PER_WORD_16,0);
    
        //
        // Configure Frame synchronization behaviour.
        //
    
        //
        // Enable transmit frame-sync ignore function.
        //
        McBSP_disableTxFrameSyncErrorDetection(base);
    
        //
        // Set Tx frame-sync source as internal.
        //
        McBSP_setTxFrameSyncSource(base, MCBSP_TX_INTERNAL_FRAME_SYNC_SOURCE);
        McBSP_setTxClockPolarity(MCBSPB_BASE, MCBSP_TX_POLARITY_FALLING_EDGE);
    
        //
        // Set the trigger source for internally generated frame-sync pulse.
        //
        McBSP_setTxInternalFrameSyncSource(base, MCBSP_TX_INTERNAL_FRAME_SYNC_DATA);
    
    
        //
        // Set no external clock sync for CLKG.
        //
        McBSP_enableSRGSyncFSR(base);
    
        //
        // Set frame-sync pulse period.
        //
        //McBSP_setFrameSyncPulsePeriod(base, 320);
    
        //
        // Set frame-sync pulse width.
        //
        McBSP_setFrameSyncPulseWidthDivider(base, 0);
    
        //
        // Configure Tx Clock behaviour.
        //
    
        //
        // Set LSPCLK as input source for sample rate generator.
        //
        McBSP_setTxSRGClockSource(base, MCBSP_SRG_TX_CLOCK_SOURCE_MCLKR_PIN);
    
        //
        // Set CLKX source as sample rate generator.
        //
        McBSP_setTxClockSource(base, MCBSP_INTERNAL_TX_CLOCK_SOURCE);
    
        //
        // Set Divide down value for CLKG.
        //
        McBSP_setSRGDataClockDivider(base, 0);
    
        //
        // Wait for CPU cycles equivalent to 2 SRG cycles-init delay.
        // Total cycles required = 2*(SYSCLK/LSPCLK). In this example
        // LSPCLK = SYSCLK/4.
        //
        MCBSP_CYCLE_NOP(8);
    }
    
    //
    // Init Receiver - This function initialises the McBSP Receiver module.
    //
    void initReceiver(uint32_t base)
    {
        //
        // Configure McBSP data behaviour.
        //
        McBSP_setRxDataSize(base, MCBSP_PHASE_ONE_FRAME, MCBSP_BITS_PER_WORD_16,0);
    
    
        //
        // Set Rx data delay to 1 cycle.
        //
        McBSP_setRxDataDelayBits(base, MCBSP_DATA_DELAY_BIT_0);
    
        //
        // Set receive sign-extension and justification mode.
        //
        McBSP_setRxSignExtension(base, MCBSP_RIGHT_JUSTIFY_FILL_ZERO);
    
        //
        // Configure Rx frame-sync behaviour.
        //
    
        //
        // Set Rx frame sync source as external.
        //
        McBSP_setRxFrameSyncSource(base, MCBSP_RX_EXTERNAL_FRAME_SYNC_SOURCE);
        McBSP_setRxFrameSyncPolarity(base, MCBSP_RX_FRAME_SYNC_POLARITY_LOW);
        McBSP_setRxClockPolarity(base, MCBSP_RX_POLARITY_FALLING_EDGE);
    
    
        McBSP_disableRxFrameSyncErrorDetection(base);
    
    
        //
        // Disable DLB mode.
        //
        McBSP_disableLoopback(base);
    
        //
        // Set no external clock sync for CLKG i.e. GSYNC = 0.
        //
        //McBSP_disableSRGSyncFSR(base);
    
        //
        // Configure Rx clock behaviour.
        //
    
        //
        // Set MCLKR pin as source for CLKR.
        //
        McBSP_setRxClockSource(base, MCBSP_EXTERNAL_RX_CLOCK_SOURCE);
    
    
    
        //
        // Wait for CPU cycles equivalent to 2 SRG cycles-init delay.
        // Total cycles required = 2*(SYSCLK/LSPCLK). In this example
        // LSPCLK = SYSCLK/4.
        //
        MCBSP_CYCLE_NOP(8);
    }

    Trying to do SPI on receiving end. I have enabled the GSYNC so I would trigger FSG on falling edge of FSR ( which is connected to CS). I am not concerned about Tx side of McBSP for now. Now the clock is being sourced by MCLKR pin. I also used LSPCLK clock as the source dividing it by 24 to get to 1MHz. Still does not work. Is this configuration issue or the timing issue? I am asking about timing because when the FSR goes low, I am also waiting 1 clock cycle before sending out data. Tried both ways waiting and not waiting. I surely cant see the FSG signal when the FSR goes low so I am really not able to predict whats happening.

    Couple of problems I have:

    The data still seems to be shifting a bit here and there. 

    And i set it for 1 word 16 bit, but I am receiving the word when I send 2 16 bits word so the 2nd word is being skipped. Dont know why.

    Regards

    Varun

  • Hey Varun,

    I think it is possible to create issues for the McBSP module by trying to program for half slave and half master. You should fully configure the McBSP as a SPI Slave or SPI Master and then initiate communication.

    See if this does anything for the bit shifting when using loopback mode.

    In section 21.7.7 of the device TRM (www.ti.com/.../spruhm8g.pdf) the last sentence mentions the following: The data delay parameters of the McBSP must be set to 0 for proper SPI slave operation. A value of 1 or
    2 is undefined in the clock stop mode.

    Based on this perhaps you should try without waiting the 1 clock cycle before sending or receiving.

    Keep me up to date with your progress and let me know if there is more I can do.

    Respectfully,