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: DRV8301-hc-evm revision D (CC2803X IDO DIM REV 1.3)

Other Parts Discussed in Thread: DRV8301, CONTROLSUITE, DRV8302, C2000WARE

Tool/software: Code Composer Studio

Hi TI
the MCU (F2803) and DRV8301 is already using SPI communication in the instaspin_BLDC.ccs project.

We want to use the isolated SPI interface (GPIO 16, 17, 18, and 19) for SPI communication between the MCU and an Arduino.

As you don't have any examples, we have added Arduino_SPI.c and Arduino_SPI.h which use the same syntax/structure as DRV8301_SPI.c and DRV8301_SPI.h

GPIO 16, 17, 18, and 19 have been enabled for SPI communication in BLDC_Int-DevInit_F2803x.c

the Arduino_SPI_Init(&SpiaRegs) function works (added in BLDC_int.c line 217)
But using Arduino_SPI_Read in line 340 or Arduino_SPI_Write in line 493 to BLDC_int.c does not work and disables controllability over the motor (using the watchwindow in CCS on a pc connected to the MCU (F2803)).

So, the implemented code for SPI communication between MCU (F2803) and Arduino messes up the SPI communication between MCU (F2803) and DRV8301.

Can you help us solve this problem? any help is appreciated. Do you need more information/files from us?

the expanded CCS project is attached to this message.InstaSPIN_BLDC.zip

  • 1. There are two SPI on F2803x, you might use another SPI, SPIB for communication.

    Or 2. Don't use the GPIO19 as SCS for your board, use a GPIO as the SCS pin. Disable the SCS for DRV if you want to use the SPIA for your board.

  • Dear Yanming Luo, thanks for the quick answer.

    Could you please help me with the following question:

    Question is regarding SPI communication in the instaSPIN_BLDC CCS project (with F2803x_DRV8301_RAM as target) the MCU F2803x is using the SPI-B module to communicate with DRV8301. F2803x is configured as master. Is it possible to use the SPI-A module on F2803x with F2803x configured as slave while F2803x is configured as master in the SPI-B module. 

    Thanks 

    -Mads

  • Yes. You can use SPI_A and SPI_B as master or slave according to your system. You might find the related examples in controlSUITE for SPI of F2803x.

    If you want to design your own board. You might use DRV8302 that doesn't need SPI for control, just use GPIOs that could be easier for you.

  • hmmm okay, We want to make SPI communication with an arduino as master (or slave)

    These codes are supposed to implement communication using the SPI-A module. But we cannot record any SPI communication on GPIO 16, 17, 18, and 19 with an Oscilloscope. Can you please take a look at the corresponding code and look after possible mistake to why we dont see any signal on the board pins?  

    //============================================================================
    //============================================================================
    //
    // FILE:   Arduino_SPI.c
    //
    // TITLE:   Arduino SPI comm functions
    //
    // Version: 1.0
    //
    // Date:    24 May 2011
    //
    //============================================================================
    //============================================================================
    #include "PeripheralHeaderIncludes.h"
    #include "Arduino_SPI.h"
    
    /*****************************************************************************/
    // Initialize the SPI peripheral
    /*****************************************************************************/
    void Arduino_SPI_Init(volatile struct SPI_REGS *s)
    {
        s->SPICCR.bit.SPISWRESET = 0;       // Put SPI in reset state
        s->SPICCR.bit.SPICHAR = 0xF;        // 16-bit character
        s->SPICCR.bit.SPILBK = 0;           // loopback off
        s->SPICCR.bit.CLKPOLARITY = 0;      // Rising edge without delay
    
        s->SPICTL.bit.SPIINTENA = 0;        // disable SPI interrupt
        s->SPICTL.bit.TALK = 1;             // enable transmission
        s->SPICTL.bit.MASTER_SLAVE = 1;     //
        s->SPICTL.bit.CLK_PHASE = 0;        // Rising edge without delay
        s->SPICTL.bit.OVERRUNINTENA = 0;    // disable reciever overrun interrupt
    
        s->SPIBRR = 0;                      // SPICLK = LSPCLK / 4 (max SPICLK)
    
        s->SPICCR.bit.SPISWRESET=1;         // Enable SPI
    }
    
    /*****************************************************************************/
    // Read from a Arduino Register
    /*****************************************************************************/
    Uint16 Arduino_SPI_Read(volatile struct SPI_REGS *s, Uint16 address)
    {
        union Arduino_SPI_WRITE_WORD_REG w;
        volatile Uint16 dummy1;
    
        w.bit.R_W = 1;                          //we are initiating a read
        w.bit.ADDRESS = address;                //load the address
        w.bit.DATA = 0;                         //dummy data;
    
        s->SPITXBUF = w.all;                    //send out the data
    
       while(s->SPISTS.bit.INT_FLAG == 0);     //wait for the packet to complete
    
        dummy1 = s->SPIRXBUF;                    //dummy read to clear the INT_FLAG bit
    
        w.bit.R_W = 1;                          //we are initiating a read
        w.bit.ADDRESS = address;                //load the address
        w.bit.DATA = 0;                         //dummy data;
    
        s->SPITXBUF = w.all;                    //send out the data
    
        while(s->SPISTS.bit.INT_FLAG == 0);     //wait for the packet to complete
    
        dummy1 = s->SPIRXBUF;                    //dummy read to clear the INT_FLAG bit
    
        return(dummy1);
    
    }
    
    /*****************************************************************************/
    // Write to a Arduino Register
    // SPI writes always clock out the data in Status Register 1.
    // Since it's available we'll return the status from this function
    /*****************************************************************************/
    Uint16 Arduino_SPI_Write(volatile struct SPI_REGS *s, Uint16 address, Uint16 data)
    {
        union Arduino_SPI_WRITE_WORD_REG w;
        volatile Uint16 Arduino_stat_reg1;
    
        w.bit.R_W = 0;                          //we are initiating a write
        w.bit.ADDRESS = address;                //load the address
        w.bit.DATA = data;                      //data to be written;
    
        s->SPITXBUF = w.all;                    //send out the data
    
        while(s->SPISTS.bit.INT_FLAG == 0);     //wait for the packet to complete
    
        Arduino_stat_reg1 = s->SPIRXBUF;                //read returned value of Status Register 1 and clear the INT_FLAG bit
    
        return(Arduino_stat_reg1);
    
    }

    //============================================================================
    //============================================================================
    //
    // FILE:    Arduino_SPI.h
    //
    // TITLE:   Header file for Arduino SPI comm functions
    //
    // Version: 1.0
    //
    // Date:    27-10-2020
    //
    //============================================================================
    //============================================================================
    
    // Arduino SPI Input Data bit definitions:
    struct  Arduino_SPI_WRITE_WORD_BITS {       // bit      description
       Uint16 DATA:11;                          // 10:0     FIFO reset
       Uint16 ADDRESS:4;                        // 14:11    Enhancement enable
       Uint16 R_W:1;                            // 15       R/W
    };
    
    union Arduino_SPI_WRITE_WORD_REG {
       Uint16                               all;
       struct Arduino_SPI_WRITE_WORD_BITS   bit;
    };
    
    // Arduino SPI Status Reister 1 bit definitions:
    struct  Arduino_STATUS_REG_1_BITS {     // bit      description
       Uint16 EnableFlagArduino:1;          // 0        enable flag in (motor startup)
       Uint16 CurrentLimitArduino:1;        // 1        switch on current limit when in eco-mode
       Uint16 SpeedRefArduino:9;            // 2-10     modtag speedref fra arduino
       Uint16 Reserved:5;                   // 15:11
    };
    
    union Arduino_STATUS_REG_1 {
       Uint16                           all;
       struct Arduino_STATUS_REG_1_BITS bit;
    };
    
    // Arduino SPI Control Reister 1 bit definitions:
    struct  Arduino_CONTROL_REG_1_BITS {    // bit      description
       Uint16 motorRPM:11; // 10:0 Send hastighed til Arduino
       Uint16 Reserved:5;                   // 15:11
    };
    
    union Arduino_CONTROL_REG_1 {
       Uint16                               all;
       struct Arduino_CONTROL_REG_1_BITS    bit;
    };
    
    /***************************************************************************************************/
    //defines
    /***************************************************************************************************/
    //Arduino Register Addresses
    #define Arduino_STAT_REG_1_ADDR     0x04
    //#define Arduino_STAT_REG_2_ADDR     0x05
    #define Arduino_CNTRL_REG_1_ADDR    0x05
    //#define Arduino_CNTRL_REG_2_ADDR    0x07
    
    /***************************************************************************************************/
    //function prototypes
    /***************************************************************************************************/
    void Arduino_SPI_Init(volatile struct SPI_REGS *s);
    Uint16 Arduino_SPI_Read(volatile struct SPI_REGS *s, Uint16 address);
    Uint16 Arduino_SPI_Write(volatile struct SPI_REGS *s, Uint16 address, Uint16 data);
    
    

  • These are the relevant lines in the main file.

    It would be awesome if you could help us mr.Yanming.THANKS

    DRV8301_SPI.h
    
    #include "Arduino_SPI.h"
    
    
    
    BLDC.Int.c
    
    #include "BLDC_Int.h"
    
    // Include header files used in the main function
    union Arduino_STATUS_REG_1 Arduino_stat_reg1; 
    union Arduino_CONTROL_REG_1 Arduino_cntrl_reg1; 
    
    void main(void)
    {
    #ifdef DRV8301
    // Initialize SPI for communication to the DRV8301
    	DRV8301_SPI_Init(&SpibRegs);
    	Arduino_SPI_Init(&SpiaRegs);
    #endif
    
    Arduino_SPI_Write(&SpiaRegs,Arduino_CNTRL_REG_1_ADDR,Arduino_cntrl_reg1.all);
    
    } //END MAIN CODE
    
    

     

  • Hello there,

    Your SPI configuration looks ok. A couple of things you may want to check:

    - GPIO configuration (I didn't see that in the code you posted)

    - Enable SPI peripheral clock through PCLKCR0.SPIBENCLK

    Here a couple of examples  you can reference depending on which SW package you are using:

    C:\ti\c2000\C2000Ware_3_02_00_00\device_support\f2803x\examples\c28\spi_loopback

    C:\ti\controlSUITE\device_support\f2803x\v130\DSP2803x_examples_ccsv5\spi_loopback