cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

ToVa_285016
Contributor

Hi,

I am having an issue with motor driver communication, and I would like to ask if my SPI code is correct.  I am only getting 0xFFFF for any register that I am trying to read, and I know that that is not correct for startup of the registers.

The guts of the code is here:

 

 

uint16 DRV8323_Read(uint8 addr)
{
    // Dummy byte needed to clock in read data
    uint16 dummy = 0x00;
    
    // Write read command and address
    // Read bit is MSB, addr takes up next 4
    uint16 cmd = ((SPI_READ << 15) | (addr << 11));
    SPI_DRV_SpiUartWriteTxData(cmd); 
    // Write Dummy
    SPI_DRV_SpiUartWriteTxData(dummy);               

    // Wait for data to be received - is size consisting of 16 or 8 bit elements?
    while (SPI_DRV_SpiUartGetRxBufferSize() < 2) {}    
    
    // Read both data bytes
    // dummy
    data1 = SPI_DRV_SpiUartReadRxData();  
    // return data
    data2 = SPI_DRV_SpiUartReadRxData();  
    
    SPI_DRV_SpiUartClearRxBuffer();
    
    // Return register data
    return (data2);
}

 

 

Attached is the full test project.

Datasheet for the motor driver is here:  DRV8323 

Thank you in advance for any help that can be offered.

Regards,

Tom

0 Likes
1 Reply
MotooTanaka
Esteemed Contributor

Hi,

From the datasheet timing chart below, it seems that the data is returned  in the same transaction.

001-DataSheet.JPG

So I would try

(1) comment out the dummy write

    // Write Dummy
    SPI_DRV_SpiUartWriteTxData(dummy);      

(2) wait for only 1 RxBufferSize() instead of 2

while (SPI_DRV_SpiUartGetRxBufferSize() < 2) {}    

(3) take data1 as the returned value and do not read data2

 

Or you can just try returning data1 for the value and see if it's what you are expecting.

 

Note: as usual, I may be wrong, and I'm sorry if it's the case.

 

moto

0 Likes