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.

SPI COMMUNICATION PROBLEM

Other Parts Discussed in Thread: TM4C123GH6PZ

Hi...

   i'm interfacing ltc2440(24 bit ADC) with spi of  tm4c123gh6pz ...i'm checking the clock in oscilloscope but i'm not getting any clock pulses..i don't known wheather the communication configuration is wrong or rite..please help me.

my code is (XTAL = 8MHZ)


#include <string.h>
#include "inc/lm4f232h5qc.h"

#include "inc/hw_memmap.h"
#include "driverlib/pin_map.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "utils/softssi.h"
#include "utils/uartstdio.h"
#include "driverlib/rom.h"
#include "driverlib/ssi.h"
#include "inc/hw_gpio.h"

//#define NUM_SSI_DATA 4

#define GPIO_PK0_SSI3CLK 0x00090002

#define GPIO_PK1_SSI3FSS 0x00090402

#define GPIO_PK2_SSI3RX 0x00090802

//#define GPIO_PK3_SSI3TX 0x00090C02

// Number of bytes to send and receive used in the ulDataTx and ulDataRx arrays, this will equal 2 bytes
#define NUM_SSI_DATA 4

//unsigned long ulDataTx[NUM_SSI_DATA]; // An array of 2 data bytes to be Tx
unsigned long ulDataRx[NUM_SSI_DATA]; // An array of 4 data bytes to be Rx
unsigned long ulindex; // Used to count the number of bytes Tx or Rx


void system_peripheral_set();
//long SpiRead();

//*****************************************************************************
//
// The error routine that is called if the driver library encounters an error.
//
//*****************************************************************************
#ifdef DEBUG
void
__error__(char *pcFilename, unsigned long ulLine)
{
}
#endif

//const int nsamples = 5; // how many ADC readings to average together
unsigned long clock1 ;

int main(void)
{

system_peripheral_set();
clock1 = SSIClockSourceGet(SSI_CLOCK_SYSTEM);
while(1)
{
// while(SSIDataGetNonBlocking(SSI0_BASE, &ulDataRx[0])) {}
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1, 0x00);

for(ulindex = 0; ulindex < NUM_SSI_DATA; ulindex++)
{
// Receive the data using the "blocking" get function.
SSIDataGet(SSI3_BASE, &ulDataRx[ulindex]);

while(SSIBusy(SSI3_BASE)){}
}
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_1, 0x08);

}

}
void system_peripheral_set()
{
// The SSI0 peripheral must be enabled for use.


SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_XTAL_8MHZ | SYSCTL_OSC_MAIN); //8MHZ

SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);
//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_GPIOK);

// 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_PK0_SSI3CLK);
GPIOPinConfigure(GPIO_PK1_SSI3FSS);
GPIOPinConfigure(GPIO_PK2_SSI3RX);
GPIOPinTypeSSI(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);
GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0|GPIO_PIN_1);
GPIOPinTypeGPIOInput(GPIO_PORTK_BASE, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3, 0x08);


// Configure and enable the SSI port for SPI master mode. Use SSI0,
// system clock supply, idle clock level low and active low clock in
// freescale SPI mode, master mode, 1MHz SSI frequency, and 8-bit data.
SSIConfigSetExpClk(SSI3_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, SysCtlClockGet()/8, 16);

// Enable the SSI0 module.
SSIEnable(SSI3_BASE);
}

Thanks in advance

  • Hello,

    Part of the problem may be that you need to issue an SSIDataPut with "dummy" data in order to generate the clocks that will allow the data to be transferred from the ADC into the SSI peripheral.  You might refer to the "examples/peripherals/ssi/spi_master.c" code in you TivaWare installation folder to see how it uses both SSIDataPut and SSIDataGet in sequence.

    You could also reference the "utils/spi_flash.c" module to see how every byte of data that is being read from the SPI FLASH requires a corresponding SSIDataPut to generate the clocks.  This is not a direct match to how the ADC works, but illustrates the basic method.

    Another couple of issues I see.  First, the line:
    clock1 = SSIClockSourceGet(SSIC_CLOCK_SYSTEM);
    ... is incorrect.  The "SSIClockSourceGet" API should only be provided the SSI3_BASE parameter (as you have programmed your example).

    Second, you have allocated GPIO Port K1 as an SSI signal in your setup function, but you are attempting to access it as a GPIO in the main loop.  This will not work as you think.  The K1 signal is under control of the SSI module and the GPIOPinWrite APIs will not have any affect on K1.  You would need to remove the K1 signal from the GPIOPinTypeSSI() API call in your setup routine.

    --Bobby

  • K Thank you...now i'm getting sclk pulses n fss signal