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.

Trouble getting TMS320F28377S Launchpad communicating with the BOOST-DRV8711 through SPI

Other Parts Discussed in Thread: BOOST-DRV8711, TMS320F28377S, DRV8711

I will start out by saying I am new to SPI.

I am attemting to use the TMS320F28377S Launchpad with the BOOST-DRV8711.

My problem is when I write out the register data from the TMS320F28377S using the SPI everything looks good, the issue comes in to play when I try and read the register back I get all 1's

I am attempting to write out all 16-bits at onetime and read all 16-bits at one time.

Below is my code.

Any help would be greatly appreciated.

//###########################################################################

// Main Program

//###########################################################################

 

#include "F28x_Project.h"       // Device Headerfile and Examples Include File

#include "DRV8711.h"            // Motor Driver Headerfile

#include "mySPI.h"                 // SPI Headerfile

#include "myGPIO.h"             // GPIO and Communication Headerfile

 

void main(void)

{

// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks

   InitSysCtrl();

 

// Step 2. Initialize GPIO:

   initmyGPIO();

 

// Step 3. Clear all __interrupts and initialize PIE vector table:

// Disable CPU __interrupts

   DINT;

 

// Initialize PIE control registers to their default state.

   InitPieCtrl();

 

// Disable CPU __interrupts and clear all CPU __interrupt flags:

   IER = 0x0000;

   IFR = 0x0000;

  

// Initialize the PIE vector table with pointers to the shell Interrupt

// Service Routines (ISR).

   InitPieVectTable();

      

// Step 4. Initialize the Device Peripherals:

   initmySPI();            // init SPI

 

// Step 5. User specific code:

   initDRV8711();           // Form Motor Driver Registers

   WriteAllRegisters();   // Write Motor Driver Registers

   ReadAllRegisters();  // Read Motor Driver Registers

}

/*******************************************************************************************

FILE:   myGpio.c

TITLE:   Device GPIO Setup

*******************************************************************************************/

 

#include "F2837xS_device.h"         // F2837xS Headerfile Include File

#include "F2837xS_Examples.h"   // F2837xS Examples Include File

 

/* Initialize GPIO and Communication Pins */

 

void initmyGPIO(void)

{

// Enable GPIO outputs 4, 41-43, 61-62, and 78

  

   GpioCtrlRegs.GPAPUD.bit.GPIO4  = 0;          // Enable pullup on GPIO4

   GpioDataRegs.GPASET.bit.GPIO4  = 1;        // Load output latch

   GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0;       // GPIO4 = GPIO4

   GpioCtrlRegs.GPADIR.bit.GPIO4  = 1;         // GPIO4 = output

 

 

   GpioCtrlRegs.GPBPUD.bit.GPIO41  = 0;           // Enable pullup on GPIO42 G_nSLEEP = low

   GpioDataRegs.GPBSET.bit.GPIO41  = 1;         // Load output latch

   GpioCtrlRegs.GPBMUX1.bit.GPIO41 = 0;        // GPIO41 = GPIO41

   GpioCtrlRegs.GPBDIR.bit.GPIO41  = 1;          // GPIO41 = output

 

   GpioCtrlRegs.GPBPUD.bit.GPIO42  = 0;          // Enable pullup on GPIO42 G_DIR_AIN2 = low

   GpioDataRegs.GPBSET.bit.GPIO42  = 1;        // Load output latch

   GpioCtrlRegs.GPBMUX1.bit.GPIO42 = 0;       // GPIO42 = GPIO42

   GpioCtrlRegs.GPBDIR.bit.GPIO42  = 1;          // GPIO42 = output

 

   GpioCtrlRegs.GPBPUD.bit.GPIO43  = 0;          // Enable pullup on GPIO42 G_DIR_AIN2 = low

   GpioDataRegs.GPBSET.bit.GPIO43  = 1;        // Load output latch

   GpioCtrlRegs.GPBMUX1.bit.GPIO43 = 0;       // GPIO43 = GPIO43

   GpioCtrlRegs.GPBDIR.bit.GPIO43  = 1;          // GPIO43 = output

 

   GpioCtrlRegs.GPBPUD.bit.GPIO61  = 0;          // Enable GPIO61 as G_RESET = low

   GpioDataRegs.GPBSET.bit.GPIO61  = 1;        // Load output latch

   GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0;       // GPIO61 = GPIO61

   GpioCtrlRegs.GPBDIR.bit.GPIO61  = 1;         // GPIO61 = output

 

   GpioCtrlRegs.GPBPUD.bit.GPIO62  = 0;          // Enable GPIO62 as G_RESET = low

   GpioDataRegs.GPBSET.bit.GPIO62  = 1;        // Load output latch

   GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 0;       // GPIO62 = GPIO62

   GpioCtrlRegs.GPBDIR.bit.GPIO62  = 1;        // GPIO62 = output

 

   GpioCtrlRegs.GPCPUD.bit.GPIO78  = 0;          // Enable GPIO78 as (SPISTEA)

   GpioDataRegs.GPCSET.bit.GPIO78  = 1;        // Load output latch

   GpioCtrlRegs.GPCMUX1.bit.GPIO78 = 0;       // GPI78 = GPIO78

   GpioCtrlRegs.GPCDIR.bit.GPIO78  = 1;        // GPIO78 = output

 

   // Enable SPI-A on GPIO58 - GPIO60

   /* Enable internal pull-up for the selected pins */

       GpioCtrlRegs.GPBPUD.bit.GPIO58 = 0;             // Enable pull-up on GPIO58 (SPISIMOA)

       GpioCtrlRegs.GPBPUD.bit.GPIO59 = 0;            // Enable pull-up on GPIO59 (SPISOMIA)

       GpioCtrlRegs.GPBPUD.bit.GPIO60 = 0;           // Enable pull-up on GPIO60 (SPICLKA)

 

   /* Set qualification for selected pins to Asynch only */

       GpioCtrlRegs.GPBQSEL2.bit.GPIO58 = 3;            // GPIO58 (SPISIMOA)

       GpioCtrlRegs.GPBQSEL2.bit.GPIO59 = 3;            // GPIO59 (SPISOMIA)

       GpioCtrlRegs.GPBQSEL2.bit.GPIO60 = 3;           // GPIO60 (SPICLKA)

 

   /* Configure SPI-A pins using GPIO regs */

       GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 1;            // Configure as SPISIMOA

       GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 1;           // Configure as SPISOMIA

       GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 1;          // Configure as SPICLKA

   EDIS;

}

/*****************************************************************************/

// Function to setup variables for the DRV8711 Control register and set initial pin state

void initDRV8711()

{

// Set Default GPIO Settings

       GpioDataRegs.GPCCLEAR.bit.GPIO78 = 1;       // SPIA_CS = low;

       GpioDataRegs.GPBCLEAR.bit.GPIO41 = 1;       // G_nSLEEP = low;

       GpioDataRegs.GPBCLEAR.bit.GPIO61 = 1;       // G_RESET = low;

       GpioDataRegs.GPBCLEAR.bit.GPIO43 = 1;       // G_STEP_AIN1 = low;

       GpioDataRegs.GPBCLEAR.bit.GPIO42 = 1;       // G_DIR_AIN2 = low;

       GpioDataRegs.GPBSET.bit.GPIO62   = 1;          // G_nFAULT = high;

       GpioDataRegs.GPASET.bit.GPIO4    = 1;          // G_nSTALL = high;

 

 

// Set Default Register Settings

       // CTRL Register

       G_CTRL_REG.Address     = 0x00;     // CRTL Register Address

       G_CTRL_REG.DTIME       = 0x03;     // 850ns

       G_CTRL_REG.ISGAIN      = 0x01;    // Gain of 10

       G_CTRL_REG.EXSTALL  = 0x00;  // Internal Stall Detect

       G_CTRL_REG.MODE       = 0x00;   // Full Step

       G_CTRL_REG.RSTEP     = 0x01;   // Step No Action

       G_CTRL_REG.RDIR        = 0x00;     // Direction set by DIR Pin

       G_CTRL_REG.ENBL       = 0x01;    // Enable motor

               // 0000 1101 0000 0001

}

 

/*************************************************************************************/

 

// Function to construct 16 bit value to write to DRV8711 register

void WriteAllRegisters()

{

 

Uint16 REGWRITE = 0x000;                // Set MSB to 0 for write

unsigned char sdata = 0x000;            // send data

 

// Write CTRL Register

  sdata = REGWRITE | (G_CTRL_REG.Address << 12) | (G_CTRL_REG.DTIME << 10) |

          (G_CTRL_REG.ISGAIN << 8) | (G_CTRL_REG.EXSTALL << 7) | (G_CTRL_REG.MODE << 3) |        

          (G_CTRL_REG.RSTEP << 2) | (G_CTRL_REG.RDIR << 1) | (G_CTRL_REG.ENBL);

  SPI_DRV8711_ReadWrite(sdata); // Go to function write SPI data

}

 

/************************************************************************************/

 

// Function to read 16 bit register value from DRV8711

void ReadAllRegisters()

{

          Uint16 REGREAD = 0x8000;                 // Set MSB to 1 for read

          Uint16 rdata = 0x0000;                          // receive data

          unsigned char sdata = 0x0000;            // send data

 

// Read CTRL Register

    sdata = REGREAD | (G_CTRL_REG.Address << 12);

    rdata = SPI_DRV8711_ReadWrite(sdata);  // Go to SPI function read DRV8711 register

    G_CTRL_REG.DTIME        = ((rdata >> 10) & 0x03);

    G_CTRL_REG.ISGAIN       = ((rdata >> 8) & 0x03);

    G_CTRL_REG.EXSTALL   = ((rdata >> 7) & 0x01);

    G_CTRL_REG.MODE        = ((rdata >> 3) & 0x0F);

    G_CTRL_REG.RSTEP       = ((rdata >> 2) & 0x01);

    G_CTRL_REG.RDIR          = ((rdata >> 1) & 0x01);

    G_CTRL_REG.ENBL         = ((rdata >> 0) & 0x01);

}

 

/************************************************************************************/

 

// Function to setup SPI for communication

 

void initmySPI()

{

    EALLOW;

       SpiaRegs.SPICCR.bit.SPISWRESET = 0;        // SPI software reset

       SpiaRegs.SPIBRR.all = 0x007F;                      // SPI Baud Rate Control. 1.5Mhz

       SpiaRegs.SPICCR.all = 0x000F;                     // Reset on, rising edge, 16-bit

       SpiaRegs.SPICTL.all = 0x0006;                      // Enable master mode, normal phase, enable talk, and SPI int disabled.

       SpiaRegs.SPIBRR.all = 0x007F;                    // SPI Baud Rate Control. 1.5Mhz

       SpiaRegs.SPICCR.all = 0x008F;                   // Relinquish SPI from Reset No loop back

       SpiaRegs.SPIPRI.bit.FREE = 1;                   // Set so breakpoints don't disturb xmission

    EDIS;

}

 

Uint16 SPI_DRV8711_ReadWrite(unsigned char sdata)

{

       Uint16 rdata = 0x000;

 

       GpioDataRegs.GPCSET.bit.GPIO78 = 1;              // Selects the DRV8711

       SpiaRegs.SPITXBUF = sdata;                               // Transmit Buffer

       while (SpiaRegs.SPISTS.bit.INT_FLAG != 1) {}    // Wait until character has been transferred

       rdata |= SpiaRegs.SPIRXBUF;                              // Receive Buffer

       GpioDataRegs.GPCCLEAR.bit.GPIO78 = 1;         // Releases the DRV8711

      

       return rdata;

}

 

 

 

 

Thanks again for any help you can give me.

  • Michael,

    Are you sure that the SPI is transmitting properly? Have you verified this on a Scope? If I am reading your full code, then this should not be the case. You have not configured the SPI GPIOs properly. For GPIO58, GPIO59, and GPIO60 the SPI is available on Mux position 15. Look at the muxing table in the datasheet to see the available muxing options. Here is the proper configuration:


    /* Configure SPI-A pins using GPIO regs */
    GpioCtrlRegs.GPBGMUX2.bit.GPIO58 = 3;
    GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 3; // Configure as SPISIMOA
    GpioCtrlRegs.GPBGMUX2.bit.GPIO59 = 3;
    GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 3; // Configure as SPISOMIA
    GpioCtrlRegs.GPBGMUX2.bit.GPIO60 = 3;
    GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 3; // Configure as SPICLKA

    Thanks,
    Mark