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.

CCS/TM4C1294NCPDT: tm4c1294ncpdt communication with drv8308 with spi but read command did not respond

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: DRV8308

Tool/software: Code Composer Studio

tm4c1294ncpdt communication with drv8308 with spi but read command did not respond

this is my code

i try to sendind  3 byte  

but i cant communicate properly 

in that main portion in 3 byte
1-address
2-msb bit (8 bit)
3-lcb bit (8bit)


#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/debug.h"
#include "driverlib/pin_map.h"
#include "driverlib/ssi.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/pwm.h"

//*****************************************************************************
//
// Number of bytes to send and receive.
//
//*****************************************************************************
#define NUM_SSI_DATA 12

void
InitConsole(void)
{
//
// Enable GPIO port A which is used for UART0 pins.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

//
// Configure the pin muxing for UART0 functions on port A0 and A1.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);

//
// Enable UART0 so that we can configure the clock.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

//
// Use the internal 16MHz oscillator as the UART clock source.
//
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);

//
// Select the alternate (UART) function for these pins.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

//
// Initialize the UART for console I/O.
//
UARTStdioConfig(0, 115200, 16000000);
}

int
main(void)
{
uint32_t ui32SysClock;


//******************************************************************************

uint32_t pui32DataTx[NUM_SSI_DATA];
uint32_t pui32DataTxdataMSB[NUM_SSI_DATA];
uint32_t pui32DataTxdataLSB[NUM_SSI_DATA];
uint32_t pui32DataRx[NUM_SSI_DATA];
uint32_t ui32Index;

ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_OSC), 25000000);
InitConsole();

//
// Display the setup on the console.
//
UARTprintf("SSI ->\n");
UARTprintf(" Mode: SPI\n");
UARTprintf(" Data: 8-bit\n\n");

//
// The SSI0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);

//
// For this example SSI0 is used with PortA[5:2]. The actual port and pins
// used may be different on your part, consult the data sheet for more
// information. GPIO port A needs to be enabled so these pins can be used.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);

//
// Configure the pin muxing for SSI0 functions on port A2, A3, A4, and A5.
// This step is not necessary if your part does not support pin muxing.
// TODO: change this to select the port/pin you are using.
//
GPIOPinConfigure(GPIO_PQ0_SSI3CLK); // Clock
GPIOPinConfigure(GPIO_PQ1_SSI3FSS);
GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0); // MOSI
GPIOPinConfigure(GPIO_PQ3_SSI3XDAT1); // MISO

GPIOPinTypeSSI(GPIO_PORTQ_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 |
GPIO_PIN_3);
SSIConfigSetExpClk(SSI3_BASE, ui32SysClock, SSI_FRF_MOTO_MODE_1,
SSI_MODE_MASTER, 1000000, 24);
//
SSIEnable(SSI3_BASE);
while(SSIDataGetNonBlocking(SSI3_BASE, &pui32DataRx[0]))
{
}

//
// Initialize address
//
pui32DataTx[0] = 0x00;
pui32DataTx[1] = 0x01;
pui32DataTx[2] = 0x02;
pui32DataTx[3] = 0x03;
pui32DataTx[4] = 0x04;
pui32DataTx[5] = 0x05;
pui32DataTx[6] = 0x06;
pui32DataTx[7] = 0x07;
pui32DataTx[8] = 0x08;
pui32DataTx[9] = 0x09;
pui32DataTx[10] = 0x0A;
pui32DataTx[11] = 0x0B;

//tx data for msb data

pui32DataTxdataMSB[0] = 0x20;
pui32DataTxdataMSB[1] = 0x00;
pui32DataTxdataMSB[2] = 0x03;
pui32DataTxdataMSB[3] = 0x65;
pui32DataTxdataMSB[4] = 0x02;
pui32DataTxdataMSB[5] = 0x10;
pui32DataTxdataMSB[6] = 0x14;
pui32DataTxdataMSB[7] = 0x03;
pui32DataTxdataMSB[8] = 0x11;
pui32DataTxdataMSB[9] = 0x32;
pui32DataTxdataMSB[10] = 0xF4;
pui32DataTxdataMSB[11] = 0x0F;

//tx data for lsb

pui32DataTxdataLSB[0] = 0x93;
pui32DataTxdataLSB[1] = 0x57;
pui32DataTxdataLSB[2] = 0xB4;
pui32DataTxdataLSB[3] = 0xDC;
pui32DataTxdataLSB[4] = 0x55;
pui32DataTxdataLSB[5] = 0x5B;
pui32DataTxdataLSB[6] = 0xB1;
pui32DataTxdataLSB[7] = 0xB6;
pui32DataTxdataLSB[8] = 0x2C;
pui32DataTxdataLSB[9] = 0x58;
pui32DataTxdataLSB[10] = 0x79;
pui32DataTxdataLSB[11] = 0xA0;


//
// Display indication that the SSI is transmitting data.
//
UARTprintf("Sent:\n ");

//
// Send 3 bytes of data.
//
for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
{
//
// Display the data that SSI is transferring.
//
UARTprintf("'%x' ", pui32DataTx[ui32Index]);

//
// Send the data using the "blocking" put function. This function
// will wait until there is room in the send FIFO before returning.
// This allows you to assure that all the data you send makes it into
// the send FIFO.
//
SSIDataPut(SSI3_BASE, pui32DataTx[ui32Index]);
SSIDataPut(SSI3_BASE, pui32DataTxdataMSB[ui32Index]);
SSIDataPut(SSI3_BASE, pui32DataTxdataLSB[ui32Index]);
}

//
// Wait until SSI0 is done transferring all the data in the transmit FIFO.
//
while(SSIBusy(SSI3_BASE))
{
}

//
// Display indication that the SSI is receiving data.
//
UARTprintf("\nReceived:\n ");

//
// Receive 3 bytes of data.
//
for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
{
//
// Receive the data using the "blocking" Get function. This function
// will wait until there is data in the receive FIFO before returning.
//
SSIDataGet(SSI3_BASE, &pui32DataRx[ui32Index]);

//
// Since we are using 8-bit data, mask off the MSB.
//
pui32DataRx[ui32Index] &= 0x00FF;

//
// Display the data that SSI0 received.
//
UARTprintf("'%x'", pui32DataRx[ui32Index]);
}

//
// Return no errors
//
return(0);
}

  • in that read or write didn't get response properly..

  • Hello Govind,

    Have you scoped the SPI lines yet to see if data is being output?

    That is the first step to debugging here as it tells us if the data output is incorrect or if the data being sent to the device is not setup right and the device is not responding.

  • i see in scope but not any responce at output port at ssi3   PQ0 to PQ3 

  • Hello Govind,

    Thank you for confirming that the output occurs. That is very helpful as now I can focus on the interface between TM4C and DRV8308 in detail.

    Review of the DRV8308 datasheet and your code, I see a couple issues

    First, TM4C1294NCPDT with basic SSI mode does not support 24 byte output in one sequence. It is possible to do more than 8 bytes with Advanced mode, but that isn't even needed here actually.

    The DRV8308 specifically states Any amount of time may pass between bits, as long as SCS stays active high. This allows 8-bit writes to be used. 

    So based on this, you just need to manually control the SS line rather than have the SSI peripheral control SS. By doing manual control, you can hold SS high with GPIO API's and send 3 different 8 byte packets and then pull it low again.

    The second issue is that it looks like to communication with the device, you need to use SPI Mode 0: https://e2e.ti.com/support/motor-drivers/f/38/p/915852/3384634#3384634

    The datasheet is confusing about that, but I think EEPROM SPI uses Mode 1 and MCU SPI for register writes uses Mode 0? Or the Falling Edge comment is wrong. But all the timing diagrams show Mode 0, and on E2E it is stated to use Mode 0 too.

  • this is my last one code

    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_ssi.h"
    #include "inc/hw_types.h"
    #include "driverlib/ssi.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"

    uint32_t ui32SysClkFreq;

    #define NUM_SSI_DATA 12
    uint8_t pui8DataTx[NUM_SSI_DATA];
    uint8_t pui8DataTxdataMSB[NUM_SSI_DATA];
    uint8_t pui8DataTxdataLSB[NUM_SSI_DATA];


    int main(void)
    {
    uint32_t ui32Index;
    uint32_t ui32Data;

    ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_3);
    GPIOPinConfigure(GPIO_PA2_SSI0CLK);
    // GPIOPinConfigure(GPIO_PA3_SSI0FSS);
    GPIOPinConfigure(GPIO_PA4_SSI0XDAT0);
    GPIOPinTypeSSI(GPIO_PORTA_BASE,GPIO_PIN_4|GPIO_PIN_2);

    SSIConfigSetExpClk(SSI0_BASE, ui32SysClkFreq, SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 1000000, 8);
    SSIEnable(SSI0_BASE);


    //
    // Initialize address byte0
    //
    pui8DataTx[0] = 0x00;
    pui8DataTx[1] = 0x01;
    pui8DataTx[2] = 0x02;
    pui8DataTx[3] = 0x03;
    pui8DataTx[4] = 0x04;
    pui8DataTx[5] = 0x05;
    pui8DataTx[6] = 0x06;
    pui8DataTx[7] = 0x07;
    pui8DataTx[8] = 0x08;
    pui8DataTx[9] = 0x09;
    pui8DataTx[10] = 0x0A;
    pui8DataTx[11] = 0x0B;

    //tx data for msb data byte1

    pui8DataTxdataMSB[0] = 0x20;
    pui8DataTxdataMSB[1] = 0x00;
    pui8DataTxdataMSB[2] = 0x03;
    pui8DataTxdataMSB[3] = 0x65;
    pui8DataTxdataMSB[4] = 0x02;
    pui8DataTxdataMSB[5] = 0x10;
    pui8DataTxdataMSB[6] = 0x14;
    pui8DataTxdataMSB[7] = 0x03;
    pui8DataTxdataMSB[8] = 0x11;
    pui8DataTxdataMSB[9] = 0x32;
    pui8DataTxdataMSB[10] = 0xF4;
    pui8DataTxdataMSB[11] = 0x0F;

    //tx data for Lsb data byte2

    pui8DataTxdataLSB[0] = 0xA3;
    pui8DataTxdataLSB[1] = 0x57;
    pui8DataTxdataLSB[2] = 0xB4;
    pui8DataTxdataLSB[3] = 0xDC;
    pui8DataTxdataLSB[4] = 0x55;
    pui8DataTxdataLSB[5] = 0x5B;
    pui8DataTxdataLSB[6] = 0xB1;
    pui8DataTxdataLSB[7] = 0xB6;
    pui8DataTxdataLSB[8] = 0x2C;
    pui8DataTxdataLSB[9] = 0x58;
    pui8DataTxdataLSB[10] = 0x79;
    pui8DataTxdataLSB[11] = 0xA0;

    while(1)
    {
    for(ui32Index = 0; ui32Index < NUM_SSI_DATA; ui32Index++)
    {
    GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3,0x00);
    ui32Data =ui32Index;
    // SSIDataPut(SSI0_BASE, 0x00);
    SSIDataPut(SSI0_BASE, pui8DataTx[ui32Data]);
    while(SSIBusy(SSI0_BASE));
    SSIDataPut(SSI0_BASE, pui8DataTxdataMSB[ui32Data]);
    while(SSIBusy(SSI0_BASE));
    SSIDataPut(SSI0_BASE, pui8DataTxdataLSB[ui32Data]);

    GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3,GPIO_PIN_3);
    // SSIBusy(SSI0_BASE)
    while(SSIBusy(SSI0_BASE))
    {
    }
    }
    }
    }