SPRUJ26A September 2021 – April 2024
C2000 MCUs can be used with BLDC motor drivers for driving three-phase BLDC or PMSM motor applications. This universal lab project can support various pre-defined BLDC motor drivers. The user can refer to the example code in the lab project and follow the steps described in this section to implement newer or otherwise unsupported BLDC motor drivers. This section uses DRV8323RS with SPI as an example.
If the BLDC motor driver supports SPI, refer to the existing BLDC motor driver files (drv8323s.h and drv8323s.c) and change the registers and API function definitions where necessary in the drv8xxx.h and drv8xxx.c files. The detailed description of the BLDC motor driver register maps can be found in the data sheet of the BLDC motor driver device.
Create a new set of folders for the driver file, as with the DRV8323 ("\libraries\drvic\drv8323\include" and "\libraries\drvic\drv8323\source").
First, add the BLDC motor driver source files to the project you are working. There are two methods to add the files.
Using an Editor to open the universal_motorcontrol_lab.projectspec projectspec file, add the files to the project as follows.
<file action="link" path="SDK_ROOT/libraries/drvic/drv8323/source/drv8323s.c" targetDirectory="src_board" applicableConfigurations="Flash_lib_DRV8323RS" />
<file action="link" path="SDK_ROOT/libraries/drvic/drv8323/include/drv8323s.h" targetDirectory="src_board" applicableConfigurations="Flash_lib_DRV8323RS" />
Alternatively, right-click on the project name in the CCS project explorer window, and select “Add Files.” Next, navigate to the following folder and select the designed driver files from " \libraries\drvic\drv8323\source", and then select "Link to Files".
#include "drv8323s.h"
To ensure that the header files can be correctly found, add the directory to the header files in "Project Properties"->"Build"->"C2000 Compiler"->"Include Options"->"Add dir to #include search path".
Alternatively, add the directory to the header files by adding the following content in the universal_motorcontrol_lab.projectspec projectspec file.
-I${SDK_ROOT}/libraries/drvic/drv8323/include
Refer to the DRV8323 files to add the supporting code as follows.
Add the defines in the hal_obj.h file.
#define DRAdd the defines in hal_obj.h fileVIC_Obj DRV8323_Obj
#define DRVIC_VARS_t DRV8323_VARS_t
#define DRVIC_Handle DRV8323_Handle
#define DRVICVARS_Handle DRV8323VARS_Handle
#define DRVIC_init DRV8323_init
#define DRVIC_enable DRV8323_enable
#define DRVIC_writeData DRV8323_writeData
#define DRVIC_readData DRV8323_readData
#define DRVIC_setupSPI DRV8323_setupSPI
#define DRVIC_setSPIHandle DRV8323_setSPIHandle
#define DRVIC_setGPIOCSNumber DRV8323_setGPIOCSNumber
#define DRVIC_setGPIOENNumber DRV8323_setGPIOENNumber
Add the drvic interface handle and SPI handle to HAL_Obj:
uint32_t spiHandle; //!< the SPI handle
DRVIC_Handle drvicHandle; //!< the drvic interface handle
DRVIC_Obj drvic; //!< the drvic interface object
uint32_t gateEnableGPIO;
// BSXL8353RS_REVA
When using a motor driver with SPI, the SPI must be configured correctly from the MCU to match the format needed to communicate with the BLDC motor driver device properly.
Configure the related GPIOs for SPI function in HAL_setupGPIOs() of the hal.c file. Ensure to check the BLDC motor driver data sheet to determine if each SPI pin requires an external pullup or pull down resistor, or if it is configured as a push-pull pin.
// GPIO5->Connect to GPIO5 using a jumper wire->M1_DRV_SCS
GPIO_setPinConfig(GPIO_5_SPIA_STE);
GPIO_setDirectionMode(5, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(5, GPIO_PIN_TYPE_STD);
// GPIO09->M1_DRV_SCLK*
GPIO_setPinConfig(GPIO_9_SPIA_CLK);
GPIO_setDirectionMode(9, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(9, GPIO_PIN_TYPE_PULLUP);
// GPIO10->SPIA_SOMI->M1_DRV_SDO*
GPIO_setPinConfig(GPIO_10_SPIA_SOMI);
GPIO_setDirectionMode(10, GPIO_DIR_MODE_IN);
GPIO_setPadConfig(10, GPIO_PIN_TYPE_PULLUP);
// GPIO11->SPIA_SIMO->M1_DRV_SDI*
GPIO_setPinConfig(GPIO_11_SPIA_SIMO);
GPIO_setDirectionMode(11, GPIO_DIR_MODE_OUT);
GPIO_setPadConfig(11, GPIO_PIN_TYPE_PULLUP);
Configure the SPI control registers for baud rate, data frame in HAL_setupSPI() in the hal.c file:
// Must put SPI into reset before configuring it
SPI_disableModule(obj->spiHandle);
// SPI configuration. Use a 500kHz SPICLK and 16-bit word size, 25MHz LSPCLK
SPI_setConfig(obj->spiHandle, DEVICE_LSPCLK_FREQ, SPI_PROT_POL0PHA0,
SPI_MODE_MASTER, 400000, 16);
SPI_disableLoopback(obj->spiHandle);
SPI_setEmulationMode(obj->spiHandle, SPI_EMULATION_FREE_RUN);
SPI_enableFIFO(obj->spiHandle);
SPI_setTxFifoTransmitDelay(obj->spiHandle, 0x10);
SPI_clearInterruptStatus(obj->spiHandle, SPI_INT_TXFF);
// Configuration complete. Enable the module.
SPI_enableModule(obj->spiHandle);
//! \brief Defines the gpio for enabling Power Module
#define MTR1_GATE_EN_GPIO 29
//! \brief Defines the gpio for the nFAULT of Power Module
#define MTR1_PM_nFAULT_GPIO 34
// setup the spi for drv8323/drv8353/drv8316
HAL_setupSPI(handle);
// setup the drv8323s/drv8353s/drv8316s interface
HAL_setupGate(handle);
// turn on the DRV8323/DRV8353/DRV8316 if present
HAL_enableDRV(obj->halMtrHandle);
// initialize the DRV8323/DRV8353/DRV8316 interface
HAL_setupDRVSPI(obj->halMtrHandle, &drvicVars_M1);
drvicVars_M1.ctrlReg05.bit.VDS_LVL = DRV8323_VDS_LEVEL_1P700_V;
drvicVars_M1.ctrlReg05.bit.OCP_MODE = DRV8323_AUTOMATIC_RETRY;
drvicVars_M1.ctrlReg05.bit.DEAD_TIME = DRV8323_DEADTIME_100_NS;
drvicVars_M1.ctrlReg06.bit.CSA_GAIN = DRV8323_Gain_10VpV;
drvicVars_M1.ctrlReg06.bit.LS_REF = false;
drvicVars_M1.ctrlReg06.bit.VREF_DIV = true;
drvicVars_M1.ctrlReg06.bit.CSA_FET = false;
drvicVars_M1.writeCmd = 1;
HAL_writeDRVData(obj->halMtrHandle, &drvicVars_M1);