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.

C2000WARE-MOTORCONTROL-SDK: F28379D Motorcontrol SDK interfacing SPI in fcl_f2837x_tmdxiddk

Part Number: C2000WARE-MOTORCONTROL-SDK

In my previous projects, I have used an SPI encoder in the FCL code and implemented the following method

  1. Comment out all t-format related lines
  2. Initialize SPI_A
  3. Implement functions to Write and Read from SPIA
  4. place the SPI functions in the motorcontrol ISR

Here are some snippets of the code (some contents deleted for security)

Note: the encoder works in a separate project only with SPI separately. So there is no encoder signal problem. The SPI peripheral just gets stuck if I tried to integrate it into FCL code

void initSPIAMaster(void)
{
    //
    // Must put SPI into reset before configuring it
    //
    SPI_disableModule(SPIA_BASE);

    //
    // SPI configuration. Use a 500kHz SPICLK and 16-bit word size.
    //
    SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA1,
                      SPI_MODE_MASTER, 8333333, 8);
    SPI_disableLoopback(SPIA_BASE);
    SPI_setEmulationMode(SPIA_BASE, SPI_EMULATION_FREE_RUN);

    //
    // Configuration complete. Enable the module.
    //
    SPI_enableModule(SPIA_BASE);
}

This is called right after the configureADC

//
// PWM Configuration
//
    configurePWM();

//
// SDFM configuration
//
    configureSDFM();

//
// ADC Configuration
//
    configureADC();
    initSPIAMaster();
Then I wrote functions to read encoder (not using fifo interrupt)

void SPIEncoderRead(int32_t *encoder_readout, int32_t *encoder_revolution)
{
    ////Declare variables

    GPIO_writePin(19,0);
    for(i = 0; i < 4; i++)
    {
        // Set the the master TX buffer. This triggers the data trasnmission
        SPI_writeDataBlockingNonFIFO(SPIA_BASE, TX_Data);
        RxData_SPIA[i] = SPI_readDataBlockingNonFIFO(SPIA_BASE);
    }
    GPIO_writePin(19,1);

    /////bitwise operation to reconstruct the databuffer////

}

///T-format function modified for the SPI encoder purpose
void readSPIPosition(int32_t position, int16_t isr_cntr)
{
    tFormat.RawTheta = position * tFormat.MechScaler;
    if (lsw == ENC_ALIGNMENT && isr_cntr ==0 )
    {
		tFormat.InitTheta = tFormat.InitTheta * 0.90 +  tFormat.RawTheta  * 0.10;
        
    }
    isr_cntr = 1;

    tFormat.MechTheta = tFormat.RawTheta - tFormat.InitTheta;

    if(tFormat.MechTheta < 0.0)
        tFormat.MechTheta += 1.0;

    tFormat.ElecTheta = tFormat.MechTheta * tFormat.PolePairs;
    tFormat.ElecTheta -= ((float32_t)((int32_t)(tFormat.ElecTheta)));

    // link the feedback speed to FCL
    speedWe = SPD_OBSERVER_run(&spdObs, tFormat.ElecTheta, 0.0, T, angMax);


    // angle estimator
    pangle = angleEstimator_Tformat();  // link the angle to FCL
    return;
}

Then these functions were called on motorcontrolISR

__interrupt void motorControlISR(void)
{


    SPIEncoderRead(&encoder_readout, &encoder_revolution);
    readSPIPosition(encoder_readout, init_cntr);
    init_cntr =1;

#if(BUILDLEVEL == FCL_LEVEL1)
    buildLevel1();

#elif(BUILDLEVEL == FCL_LEVEL2)
    buildLevel2();

#elif(BUILDLEVEL == FCL_LEVEL3)
    buildLevel3();

#elif(BUILDLEVEL == FCL_LEVEL4)
    buildLevel468();

#elif(BUILDLEVEL == FCL_LEVEL5)
    buildLevel58();

#elif(BUILDLEVEL == FCL_LEVEL6)
    buildLevel468();

#elif(BUILDLEVEL == FCL_LEVEL7)
    buildLevel7();

#elif(BUILDLEVEL == FCL_LEVEL8)
    buildLevel8();

This exact same method I used worked on the f2838x version of the code a year ago on SDK vers 4.0. But on F2837x version SDK vers 5.0 it doesn't seem to work

When I go into debug mode and pause the code, the code gets stuck in the SPI_readDataBlockingNonFIFO function

Any suggestions would be appreciated.

Also open to hearing how to "properly" do this in FCL using interrupt register.

Thanks

Hansol

  • When I go into debug mode and pause the code, the code gets stuck in the SPI_readDataBlockingNonFIFO function

    Not quite sure why this is happening. Some things to check to see if sheds light on the issue:

    In which iteration of the for loop in SPIEncoderRead() does it get stuck?

    Have you check the status of SPI_STS_INT_FLAG and SPI_STS_BUFFULL_FLAG before calling SPIEncoderRead()?

  • Hey Gus, thanks for taking an interest in this issue.
    This is bizarre, I tested this code again to check what you suggested and all of sudden the SPI started updating. 
    I will keep this issue open for the next couple of days and observe and get back to you.

    Hansol