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.

Strange McBSP behavior in SPI Master mode

Other Parts Discussed in Thread: TMS320DM642

I am trying to set up the McBSP on a TMS320DM642 as an SPI Master in a very simple form.  I need to write 64 bits, then manually generate a pulse on the FSX pin.  I don't need to do this often, nor at a high rate, so simply servicing it directly by the CPU is fine - no need to mess with interrupts or EDMA.  My first attempt is to set up simply to write one 32-bit word, wait for 10 seconds, and shut down the McBSP.  I would expect to see one 32-bit transfer on the scope, but I don't - I see a continual stream of 32-bti transfers, all of the correct value, that continues until the delay ends and the McBSP is closed.  Why?

Here is the relevant code:

#include <stdint.h>

#include "std.h"
#include "tsk.h"

#include "csl.h"
#include "csl_mcbsp.h"

#include "biosconfigcfg.h"

MCBSP_Config testCfg =
{
    MCBSP_SPCR_RMK(MCBSP_SPCR_FREE_YES, MCBSP_SPCR_SOFT_YES,
                   MCBSP_SPCR_FRST_NO, MCBSP_SPCR_GRST_NO,
                   MCBSP_SPCR_XINTM_DEFAULT, MCBSP_SPCR_XSYNCERR_DEFAULT,
                   MCBSP_SPCR_XRST_YES, MCBSP_SPCR_DLB_OFF,
                   MCBSP_SPCR_RJUST_DEFAULT, MCBSP_SPCR_CLKSTP_DELAY,
                   MCBSP_SPCR_DXENA_OFF, MCBSP_SPCR_RINTM_DEFAULT,
                   MCBSP_SPCR_RSYNCERR_DEFAULT, MCBSP_SPCR_RRST_YES), ///< spcr
    MCBSP_RCR_DEFAULT, ///< rcr
    MCBSP_XCR_RMK(MCBSP_XCR_XPHASE_SINGLE, MCBSP_XCR_XFRLEN2_OF(0),
                  MCBSP_XCR_XWDLEN2_8BIT, MCBSP_XCR_XCOMPAND_DEFAULT,
                  MCBSP_XCR_XFIG_DEFAULT, MCBSP_XCR_XDATDLY_0BIT,
                  MCBSP_XCR_XFRLEN1_OF(0), MCBSP_XCR_XWDLEN1_32BIT,
                  MCBSP_XCR_XWDREVRS_DISABLE), ///< xcr
    MCBSP_SRGR_RMK(MCBSP_SRGR_GSYNC_FREE, MCBSP_SRGR_CLKSP_DEFAULT,
                   MCBSP_SRGR_CLKSM_INTERNAL, MCBSP_SRGR_FSGM_FSG,
                   MCBSP_SRGR_FPER_OF(64), MCBSP_SRGR_FWID_OF(0),
                   MCBSP_SRGR_CLKGDV_OF(0x80)), ///< srgr
    MCBSP_MCR_DEFAULT, ///< mcr
    MCBSP_RCERE0_DEFAULT, ///< rcere0
    MCBSP_RCERE1_DEFAULT, ///< rcere1
    MCBSP_RCERE2_DEFAULT, ///< rcere2
    MCBSP_RCERE3_DEFAULT, ///< rcere3
    MCBSP_XCERE0_DEFAULT, ///< xcere0
    MCBSP_XCERE1_DEFAULT, ///< xcere1
    MCBSP_XCERE2_DEFAULT, ///< xcere2
    MCBSP_XCERE3_DEFAULT, ///< xcere3
    MCBSP_PCR_RMK(MCBSP_PCR_XIOEN_SP, MCBSP_PCR_RIOEN_GPIO,
                  MCBSP_PCR_FSXM_INTERNAL, MCBSP_PCR_FSRM_DEFAULT,
                  MCBSP_PCR_CLKXM_OUTPUT, MCBSP_PCR_CLKRM_OUTPUT,
                  MCBSP_PCR_CLKSSTAT_DEFAULT, MCBSP_PCR_DXSTAT_DEFAULT,
                  MCBSP_PCR_FSXP_ACTIVEHIGH, MCBSP_PCR_FSRP_DEFAULT,
                  MCBSP_PCR_CLKXP_RISING, MCBSP_PCR_CLKRP_DEFAULT), ///< pcr
};

void atest(void)
{
    MCBSP_Handle mc = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
    MCBSP_config(mc, &testCfg);
    MCBSP_enableSrgr(mc);
    spinDelay(100);
    MCBSP_enableXmt(mc);

    MCBSP_write(mc, 0x00ffff00);

    TSK_sleep(10000);
    MCBSP_close(mc);

    while (1) {
        TSK_sleep(1);
    }
}

What's happening here???

Thanks!

  • Robert,

    Did you follow the initialization sequence in the McBSP User's Guide, or did you start from a working example from CSL or BIOS?

    How have you configured your FSX to be generated. Will it come out only when data is ready to transmit or is it configured to be free-running?

    What versions of CCS and BIOS and CSL are you using?

    How do you plan to manually toggle FSX?

    Regards,
    RandyP

  • Hi RandyP,

    I used a working McBSP example that we had used before, but this was with a codec - not an SPI thing.  The code I include here was based on a TI app note (sorry, I'm not at my office, so I don't know which) that described how to set it up using the CSL.

    Right now with this sample, the FSX goes active high while the SPI is sending; I want to change that.  What I was hoping to do was use the McBSP as an SPI Master, send the 64-bits, then set the XIOEN to GPIO, then manually twiddle that.  Right now, the problem is first, how to send just two, different, 32-bit words - without the peripheral going nuts and sending them continuously, and second, how to not drive the FSX signal.

    I'm using Code Composer 3.1 - stuck with that because we have an old, binary-distributed library that only works with 3.1.  Don't know what version of the BIOS/CSL, but it is what came with CCS 3.1, I guess.

    Thanks for the help!

    Bob

  • Bob,

    Please refer to the McBSP Reference Guide to find Section 9.3 McBSP Initialization for SPI Mode. Check if you are following the steps there.

    Regards,
    RandyP

  • Yes, in another attempt, I tried to follow that procedure, programming the registers individually.  I wasn't able to get anything to happen, so I went back to the CSL.  My example above uses just the CSL, which I would expect would implement Section 9.3 - is that not the case?  Are my settings in my MCBSP_Config structure wrong?

  • Here is what the scope is showing me:

  • Robert,

    Robert Grimes said:
    My example above uses just the CSL, which I would expect would implement Section 9.3 - is that not the case?

    Like you, I have to believe that you should be able to send a single word and not have it repeated as you are showing. That means something is setup incorrectly, which is what you have been asking from the beginning.

    The good part is that you seem to have CLKSTP mode working well and you have the desired framing with FSX.

    My recommendation is to go back to directly configuring the registers. [The other option is to debug through the BIOS assembly code to figure out exactly what BIOS is doing behind the scenes in the MCBSP functions.]

    Test changes for any bit that could be relevant. For example, I do not notice FRST being reset; that bit is not discussed in the SPI initialization, but if you check out its description elsewhere in the User Guide, perhaps it needs to be handled. Or other bits. This is going to be tough, and I do not see what the problem is. But I believe the must be a solution, and it has to be in the register setup if you are driving all the pins from the DSP.

    Sorry for nothing better. I will stay silent and see if someone else will jump in.

    Regards,
    RandyP

  • Hi Randy,

    I did what you suggested (direct register manipulation), and I can now send a single word.  However, I really need to send 64 bits in one frame, and I could not figure out how to do that; no matter what I tried, it would simply send the second word twice.  I think using the EDMA might fix this, but decided to go a different route; besides, what I really need is to generate a single pulse on the FSX signal, without the clock running, then start the clock while keeping the FSX signal low.  

    Given the small amount of data involved (64 bits), and the relative infrequency (generally a few times per hour, no more that once per second at the absolute maximum scenario), I decided to just set the McBSP with a free-running clock (all I have to do is set the frequency and enable the SRG!).  When I need to send the 64 bits, I stop the clock, set the pins as XIOEN_GPIO (always as outputs), and simply bit-bang the data out, generating the FSX pulse after I'm done; then, I just set the pins back to XIOEN_SP and restart the clock.  Boom! Done. 

    Thanks for your help, regardless!

    Bob