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.

[参考译文] TMS320F28035:SIMO 锁存高电平

Guru**** 1640390 points
Other Parts Discussed in Thread: DRV8711
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1311629/tms320f28035-simo-latch-high

器件型号:TMS320F28035
主题中讨论的其他器件:DRV8711

您好!

我目前遇到问题、即 SPIB SIMO 线路在向 DRV8711传输8个(16位)字后锁存为高电平。 DRV8711似乎已正确设置、因为测试设置中的步进电机能够移动。 但是、当我在初始设置后尝试写入或读取寄存器时、DRV8711没有响应。 我使用的是定制电路板。 附件是我的测试代码。 谢谢你。

#include "DSP28x_Project.h"
#include <stdint.h>

#ifdef _FLASH
extern Uint16 RamfuncsRunStart;
extern Uint16 RamfuncsLoadSize;
extern Uint16 RamfuncsLoadStart;
#endif

void epwm1RegInit(void)
{
    EPwm1Regs.TBSTS.all = 0;
    EPwm1Regs.TBPHS.half.TBPHS = 0;
    EPwm1Regs.TBCTR = 0;
    EPwm1Regs.CMPCTL.all = 0x50;     // immediate mode for CMPA and CMPB
    EPwm1Regs.CMPB = 0;
    EPwm1Regs.AQCTLA.all = 0x00;// Reset CMPA
    EPwm1Regs.AQCTLA.bit.ZRO = 0x02; // output High at zero
    EPwm1Regs.AQCTLA.bit.PRD = 0x00; // Unaffected.
    EPwm1Regs.AQCTLA.bit.CAU = 0x01;// output low at CMPA
    EPwm1Regs.AQCTLB.all = 0x09;
    EPwm1Regs.AQSFRC.all = 0;
    EPwm1Regs.AQCSFRC.all = 0;
    EPwm1Regs.ETSEL.all = 0x0B;      // Interrupt on ZERO
    EPwm1Regs.ETPS.all = 1;
    EPwm1Regs.ETFLG.all = 0;
    EPwm1Regs.ETCLR.all = 0;
    EPwm1Regs.ETFRC.all = 0;
    EPwm1Regs.PCCTL.all = 0;
    EPwm1Regs.TBCTL.all = 0x0010 + 0x200C;
    EPwm1Regs.TBCTL.bit.CLKDIV = 0x6;
    EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0x0;
}

void spiTxDrv(Uint16 tx)
{
    Uint16 dummyRead = 0;
    SpibRegs.SPITXBUF = tx;
    while (SpibRegs.SPIFFRX.bit.RXFFST == 0) {}
    dummyRead = SpibRegs.SPIRXBUF;
}

Uint16 spiRxDrv(Uint16 rx)
{
    Uint16 spiReturn = 0;
    SpibRegs.SPITXBUF = rx;
    while (SpibRegs.SPIFFRX.bit.RXFFST == 0) {}
    spiReturn = SpibRegs.SPIRXBUF;
    return spiReturn;
}

int main(void)
{
    Uint16 txData = 0;
    Uint16 rxData = 0;
    float32 prd = 0.0;
    Uint16 cmp = 0;
    Uint16 fail = 0;
    Uint16 i = 0;
    Uint16 regVals[8] = {0x0119, 0x10C3, 0x2060, 0x3000, 0x4510, 0x531E, 0x6005, 0x7000};
    Uint16 mask[8] = {0x0FFF, 0x07FF, 0x01FF, 0x01FF, 0x07FF, 0x0FFF, 0x0FFF, 0x00FF};

    InitSysCtrl();

#ifdef _FLASH
    memcpy((uint16_t *)&RamfuncsRunStart,(uint16_t *)&RamfuncsLoadStart,(unsigned long)&RamfuncsLoadSize);

    InitFlash();
#endif

    InitGpio();

    // spib gpio.
    EALLOW;
    //
    // Enable internal pull-up for the selected pins
    // Pull-ups can be enabled or disabled disabled by the user.
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; //Enable pull-up on GPIO24 (SPISIMOB)
    GpioCtrlRegs.GPAPUD.bit.GPIO13 = 0;   //Enable pull-up on GPIO13 (SPISOMIB)
    GpioCtrlRegs.GPAPUD.bit.GPIO14 = 0;    //Enable pull-up on GPIO14 (SPICLKB)
    GpioCtrlRegs.GPAPUD.bit.GPIO15 = 0;    //Enable pull-up on GPIO15 (SPISTEB)

    //
    // Set qualification for selected pins to asynch only
    // This will select asynch (no qualification) for the selected pins.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 3;  // Asynch input GPIO24 (SPISIMOB)
    GpioCtrlRegs.GPAQSEL1.bit.GPIO13 = 3;   // Asynch input GPIO13 (SPISOMIB)
    GpioCtrlRegs.GPAQSEL1.bit.GPIO14 = 3;   // Asynch input GPIO14 (SPICLKB)
    GpioCtrlRegs.GPAQSEL1.bit.GPIO15 = 3;   // Asynch input GPIO15 (SPISTEB)

    //
    // Configure SPI-B pins using GPIO regs
    // This specifies which of the possible GPIO pins will be SPI functional
    // pins. Comment out other unwanted lines.
    GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 3;   // Configure GPIO24 as SPISIMOB
    GpioCtrlRegs.GPAMUX1.bit.GPIO13 = 3;    // Configure GPIO13 as SPISOMIB
    GpioCtrlRegs.GPAMUX1.bit.GPIO14 = 3;    // Configure GPIO14 as SPICLKB
    GpioCtrlRegs.GPAMUX1.bit.GPIO15 = 3;    // Configure GPIO15 as SPISTEB
    EDIS;

    // set spib register.
    SpibRegs.SPICCR.bit.SPISWRESET = 0; //Set SPISWRESET=0 before SPI configuration
    SpibRegs.SPIBRR = 14;               // spiclk 1MHz.
    SpibRegs.SPICCR.bit.SPICHAR = 0xF;  // 16bit word.
    SpibRegs.SPICTL.all = 0x000E;       // clk phase, master, talk = 1
    SpibRegs.SPIFFTX.all = 0xE000;
    SpibRegs.SPIFFRX.all = 0x6000;
    SpibRegs.SPICCR.bit.SPISWRESET = 1; //Set SPISWRESET=1 before SPI configuration

    // epwm1a gpio setup.
    EALLOW;
    //
    // Disable internal pull-up for the selected output pins
    // for reduced power consumption
    // Pull-ups can be enabled or disabled by the user.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAPUD.bit.GPIO0 = 1;    // Disable pull-up on GPIO0 (EPWM1A)

    //
    // Configure EPWM-1 pins using GPIO regs
    // This specifies which of the possible GPIO pins will be
    // EPWM1 functional pins.
    // Comment out other unwanted lines.
    //
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1;   // Configure GPIO0 as EPWM1A
    EDIS;

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    EDIS;

    // set epw1 registers.
    epwm1RegInit();

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    EDIS;

    DINT;
    InitPieCtrl();
    IER = 0x0000;
    IFR = 0x0000;
    InitPieVectTable();

    EALLOW;
    // DRV8711 GPIOs
    GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 0; //DIR
    GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 0; //RESET
    GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 0; //n_SLEEP
    GpioCtrlRegs.GPAMUX1.bit.GPIO4 = 0; //n_STALL
    GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 0; //n_FAULT
    GpioCtrlRegs.GPADIR.bit.GPIO1 = 1; //DIR
    GpioCtrlRegs.GPADIR.bit.GPIO2 = 1; //RESET
    GpioCtrlRegs.GPADIR.bit.GPIO3 = 1; //n_SLEEP
    GpioCtrlRegs.GPADIR.bit.GPIO4 = 0; //N_STALL
    GpioCtrlRegs.GPADIR.bit.GPIO5 = 0; //n_FAULT
    GpioCtrlRegs.GPAQSEL1.bit.GPIO1 = 0; //DIR
    GpioCtrlRegs.GPAQSEL1.bit.GPIO2 = 0; //RESET
    GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 0; //n_SLEEP
    GpioCtrlRegs.GPAQSEL1.bit.GPIO4 = 0; //n_STALL
    GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 0; //n_FAULT

    // led at gpio9.
    GpioCtrlRegs.GPAMUX1.bit.GPIO9 = 0;
    GpioCtrlRegs.GPADIR.bit.GPIO9 = 1;

    GpioCtrlRegs.GPBMUX1.bit.GPIO44 = 0;            // set as GPIO44
    GpioCtrlRegs.GPBDIR.bit.GPIO44 = 1;             // set as output
    EDIS;

    GpioDataRegs.GPASET.bit.GPIO9 = 1;
    GpioDataRegs.GPBSET.bit.GPIO44 = 1;

    // don't care about direction for test.
    GpioDataRegs.GPACLEAR.bit.GPIO1 = 1;

    // reset pin on DRV8711 is active-high.
    GpioDataRegs.GPACLEAR.bit.GPIO2 = 1;

    // Set sleep to high to enable DRV8711.
    GpioDataRegs.GPASET.bit.GPIO3 = 1;

    DELAY_US(10000);

    // calculate prd for 4Khz pwm for 150rpm @ 1/8 step.
    prd = (1.0 / 4000.0);
    prd /= (1.0 / 937500.0);
    prd -= 1.0;

    cmp = (Uint16)prd;
    cmp /= 2;

    /*
     * gain = 10.
     * mode = 1/8 step.
     * enable = 1.
     */
    spiTxDrv(regVals[0]);

    // torque = 195.
    spiTxDrv(regVals[1]);

    // toff = 96.
    spiTxDrv(regVals[2]);

    // tblank = 0.
    spiTxDrv(regVals[3]);

    // decay = auto mixed.
    spiTxDrv(regVals[4]);

    // stall after 8 steps, stall thresh = 30.
    spiTxDrv(regVals[5]);

    // ocp thresh 500mV, deglitch = 1us.
    spiTxDrv(regVals[6]);

    // clear status register.
    spiTxDrv(regVals[7]);

    // set epwm1a.
    EPwm1Regs.TBPRD = (Uint16)prd;
    EPwm1Regs.CMPA.half.CMPA = cmp;

    // let stepper motor run for 5 seconds.
    DELAY_US(5000000);

    // stop stepper motor.
    EPwm1Regs.TBPRD = 0;
    EPwm1Regs.CMPA.half.CMPA = 0;

    EALLOW;
    SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
    EDIS;

    // wait 5 seconds.
    DELAY_US(5000000);

    for (i = 0; i < 8; i++)
    {
        // read a register.
        rxData = spiRxDrv(0x8000 | i << 12);
        rxData &= mask[i];

        if (rxData != (regVals[i] & mask[i]))
        {
            fail = 1;
        }
    }

    while (1)
    {
        if (fail == 1)
        {
            GpioDataRegs.GPACLEAR.bit.GPIO9 = 1;
            DELAY_US(500000);
            GpioDataRegs.GPASET.bit.GPIO9 = 1;
            DELAY_US(500000);
        }
    }

	return 0;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    能否检查 SPI 数据是否正确输出? 使用逻辑分析仪还是示波器?

    此致、

    维纳

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好 Veena:

    附加后、您将找到 DRV8711上的 SPI 写入/读取地址0和1的示波器截图。 SIMO 上的数据正确。 在 addr1屏幕截图中、处理器将写入寄存器、然后读取内容。 它将继续此过程、直到写入和读取变量匹配为止。 未记录 SOMI 线。

    蓝色- SIMO

    红色- CS

    绿色- CLK

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    由于您获得了 C2000器件发出的正确 SPI 数据、我建议您将 此帖子发布在电机驱动论坛。

    此致、

    维纳