DRV8323R: UNABLE TO WRITE SPI REGISTERS

Part Number: DRV8323R
Other Parts Discussed in Thread: DRV8323,

Hello,

I am trying to set DRV8323 in PWM 1X mode but  i am unable to the SPI registers. I am able to read the default values of SPI all registers and unable to write SPI registers and read the same.  Need Some assistance.

I am attaching my simple code to read and write the registers 

void main()
{
// initialize the device
SYSTEM_Initialize();
uint16_t i,j,DCR_2;
b=0x9000; // ADDRESS OF DRIVER CONTROL REGISTER FOR READING
DCR_2=0x1052;// trying to set PWM 1X in driver control register
DRV_EN=0;
for(i=0;i<1000;i++);
DRV_EN=1; // Enabling DRV
j=0;
SPI_SS_PORT=1;
for(i=0;i<1000;i++);
while(1)
{
SPI_SS_PORT=0;
SPI1_Write(&DCR_2); // TRYING WIRTE THE DATA TO DRIVER CONTROL REGISTER
SPI_SS_PORT=1;
for(i=0;i<10000;i++);
SPI_SS_PORT=0;
SPI1_Exchange(&b,&j);// VERIFYING AND READING DRIVER CONTROL REGSITER b REPRESENST THE ADDRES OF DCR  j REPRESENTS WHERE THE VALUE IS BEING STORED
 SPI_SS_PORT=1;
for(i=0;i<10000;i++);
}
}

Thank You.   

  • Hello Shyam,

    Can you share your schematic (or which EVM you are using?

    Have you reviewed this FAQ about SPI configuration and use? LINK

    Thanks,

    Matt

  • Hi Matt,

    Thank you for your reply.

    I just reviewed the FAQ. I just changed my driver accordingly for read and write.

    Here are my drivers ,

    For write,

    void SPI1_Write( uint16_t addr, uint16_t data, uint16_t *pReceiveData )
    {

    uint16_t commandword =(addr) << 11 | (data);

    while( SPI1STATbits.SPITBF == 1 )
    {

    }
    SPI1BUF = commandword;

    while ( SPI1STATbits.SRXMPT == true);

    *((uint16_t*)pReceiveData) = SPI1BUF;
    }

    For Read,

    void SPI1_Read( uint16_t addr, uint16_t *pReceiveData )
    {

    uint16_t commandword = (0x8000 | (addr << 11));

    while( SPI1STATbits.SPITBF == 1 )
    {

    }
    SPI1BUF = commandword;

    while ( SPI1STATbits.SRXMPT == 1);

    *((uint16_t*)pReceiveData) = SPI1BUF;
    }

    MCU used: Microchip dsPIC33EP512MC504

    I am still facing the same issue.

  • Hello Shyam,

    Can you share your schematic so we can confirm that the connections and external components are correct?

    Thanks,

    Matt

  • Hi Matt,

    Due to some conditions I may not able to share the schematic. But, I can get you some hardware information and necessary information needed.

    As far as, connections are concerned i hope they are correct best of my knowledge. Otherwise(Best of my knowledge), we wouldn't be able to read the default data from registers.

  • Hi Shyam,

    Since some of the default SPI settings are '0', reading the default back could mean that the hardware is not functional. For example, if SPI SDO line does not have a pull-up resistor the SDO output will only read '0'.

    Can you confirm that you are correctly reading the contents of 0x5h? This address has a non-0 and non-1 default setting.

    Thanks,

    Matt

  • Hi Matt,

    I just the read the address 0x5h . I received the data 0x0159, which turns out be the default value.

    For my information, are registers locked to write initially?. I see LOCK register has unlock value by default. 

  • Hi Shyam,

    LOCK is unlocked by default, allowing to write the register settings. You would have to first set the LOCK for it to prevent further writes.

    Can you confirm that the ENABLE pin of the DRV8323R stays high during and after the attempted write? The DRV8323 does not have non-volatile memory and therefore resets to default SPI register settings after loosing power or going into sleep mode.

    b=0x9000; // ADDRESS OF DRIVER CONTROL REGISTER FOR READING
    DCR_2=0x1052;// trying to set PWM 1X in driver control register
    DRV_EN=0; --> This will put the DRV8323R to sleep and reset the register settings you just wrote

    Do you have any waveform of nSCS, SCLK, SDI, and SDO during one of your reads & writes?

    Thanks,

    Matt