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
#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);
}