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.

DRV8301: STM32 DRV8301 SPI communication

Part Number: DRV8301

Tool/software:

Hi everone,

i have a question regarding the DRV8301 im trying to communicatie with the drive to put it in 3 pwm mode only i dont get any response.

my MCU is a STM32G431CBU at which the SPI port are connected.

if this is the wrong place for it im sorry in advanced

kind regarts,

Ruben Konings

  • Hi Ruben,

    Debugging SPI communications can be a little tricky but a good place to start would be to check if you are able to read all the registers of the device and if you are seeing the default values mentioned in the datasheet. Are you able to post the SPI reads using a logic analyzer?

    Keep in mind the SPI timing requirements as well as the SPI frame requirements:

    Regards,

    Yara

  • thank you for your reply this is the feed of the logic analyzer but i trying to configure the clk but got no luck with it. find i realy hard to understand which clk setting i have to use with the CPol and such.

    thank you anyway.

  • Hi Ruben,

    Yeah it seems like sCLK mightt be an issue, here is some code from out sensored trap code for SPI configuration

    void Config_evm_spi(void)
    {
        //Pin Config
        EALLOW;
        // SPI_MOSI
        GPIO_SetupPinOptions(16, GPIO_INPUT, GPIO_ASYNC | GPIO_PULLUP);
        // SPI_MISO
        GPIO_SetupPinOptions(17, GPIO_INPUT, GPIO_ASYNC | GPIO_PULLUP);
        // SPI_CS
        GPIO_SetupPinOptions(56, GPIO_INPUT, GPIO_ASYNC | GPIO_PULLUP);
        // SPI_CLK
        GPIO_SetupPinOptions(57, GPIO_INPUT, GPIO_ASYNC | GPIO_PULLUP);
    
        GPIO_SetupPinMux(16, GPIO_MUX_CPU1, 1);
        GPIO_SetupPinMux(17, GPIO_MUX_CPU1, 1);
        GPIO_SetupPinMux(56, GPIO_MUX_CPU1, 1);
        GPIO_SetupPinMux(57, GPIO_MUX_CPU1, 1);
        EDIS;
    
        EALLOW;
        ClkCfgRegs.LOSPCP.all = 0;
        EDIS;
    
        // Initialize SPI FIFO registers
        SpiaRegs.SPIFFTX.all=0xE040;
        SpiaRegs.SPIFFRX.all=0x2044;
        SpiaRegs.SPIFFCT.all=0x0;
    
        //SPI Settings
        SpiaRegs.SPICCR.bit.SPISWRESET = 0;     //SPI Reset On
        SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;    //SCLK Active High
        SpiaRegs.SPICCR.bit.SPICHAR = 0x7;      //16-bit SPI char
        SpiaRegs.SPICCR.bit.SPILBK = 0;
    
        SpiaRegs.SPICTL.bit.OVERRUNINTENA = 0;  //No overrun interrupt
        SpiaRegs.SPICTL.bit.CLK_PHASE = 0;      //Phase 0
        SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;   //Master mode
        SpiaRegs.SPICTL.bit.TALK = 1;           //nSCS enabled
        SpiaRegs.SPICTL.bit.SPIINTENA = 0;      //TX/RX Interrupt Disabled
    
        SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = ((25000000 / 1000000) - 1);              //Set baud rate to 1MHz
        SpiaRegs.SPIPRI.bit.FREE = 1;           //Set so breakpoints don't disturb transmission
        SpiaRegs.SPICCR.bit.SPISWRESET = 1;   //Exit SPI reset
    
    }

    You can also find firmware for most of our devices on the EVM page, although DRV8301 might be a little outdated I think, SPI communication can have quite a few similarities across our devices as long as they use close to the same SPI frame.

  • thank you im going to look into that.

  • Hi again,

    I got the clock working now im sending data to the drv but i dont get a good respones Im still not sure and cant find a good answer for what the baudrate should be for the CPOL en CHPA settings

  • Hi Ruben,

    Correct me if I'm wrong but it looks like SDI is red and SDO is orange/yellow and you are trying to read register address 0x00 correct? Looks like you are getting a GVDD_UV fault?

    Are you able to measure GVDD?

    Also can you read all the registers to see if they are responding back with the default values?

    Also I'm not sure if this is what you're looking for or not but the baud rate that was set during the SPI configuration was 1MHz

    Regards,

    Yara

  • I have figuerd it out you have to wait the whole SpI sequence and the next sequence you get the answer thank you for your help