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/TM4C129ENCPDT: SPI Reading Problem

Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: AMC7820,

Tool/software: Code Composer Studio

Hi,

i am working on TM4C129ENCPDT. I wants to communicate with AMC7820 Using SPI. I am writing a value to DAC0 of AMC 7280 and it read back using SPI. 

when i perform multiple read operations, first read back value is correct, then it shows random values . after some cycles it shows correct values

void SPIRead(int port,int pin, uint8_t *pui32DataTx,uint32_t ui32Count,int SPIBase)
{
char buf[25]={0};
int ireadValue=0;
GPIOPinWrite(port, pin,0);// CS LOw; AMC expects Active low control signal
SysCtlDelay(SysCtlClockGet()/3);//1 sec delay

SSIDataPut(SPIBase, pui32DataTx[0]);
SysCtlDelay(SysCtlClockGet()/100);
while(SSIBusy(SPIBase));
SSIDataPut(SPIBase,pui32DataTx[1]);
SysCtlDelay(SysCtlClockGet()/100);
//
// Wait until SSI0 is done transferring all the data in the transmit FIFO.
//
while(SSIBusy(SPIBase));
for(ui32Index = 0; ui32Index < ui32Count; ui32Index++)
{
SSIDataPut(SPIBase, 0xFF/*pui32DataTx[ui32Index]*/);
SSIDataGet(SPIBase, &pui32DataRx[ui32Index]);
}
SysCtlDelay(SysCtlClockGet()/100);
while(SSIBusy(SPIBase));
pui32DataRx[0] &= 0x00FF;
pui32DataRx[1] &= 0x00FF;
GPIOPinWrite(port, pin,pin);// Reset CS to High
SysCtlDelay(SysCtlClockGet()/3);//1 sec delay

ireadValue = pui32DataRx[0];
ireadValue = ireadValue << 8;
ireadValue |= pui32DataRx[1];

sprintf(buf,"SPI Read <%x>\n",ireadValue);
UARTSend((uint8_t *)buf,strlen(buf),UART5_BASE);


}

void SPIwrite(int port,int pin, uint8_t *pui32DataTx, uint32_t ui32Count,int SPIBase)
{
char buf[25]={0};
int ireadValue=0;
GPIOPinWrite(port, pin,0);// CS LOw; AMC expects Active low control signal
SysCtlDelay(SysCtlClockGet()/3);//1 sec delay
//SysCtlDelay(SysCtlClockGet()/100);

SSIDataPut(SPIBase, pui32DataTx[0]);
SysCtlDelay(SysCtlClockGet()/100);
while(SSIBusy(SPIBase));
SSIDataPut(SPIBase, pui32DataTx[1]);
SysCtlDelay(SysCtlClockGet()/100);
while(SSIBusy(SPIBase));

for(ui32Index = 2; ui32Index < ui32Count; ui32Index++)
{
SSIDataPut(SPIBase, pui32DataTx[ui32Index]);
SSIDataGet(SPIBase, &temp1/*&pui32DataRx[ui32Index-2]*/);
}

while(SSIBusy(SPIBase));
GPIOPinWrite(port, pin,pin);// Reset CS to High

SysCtlDelay(SysCtlClockGet()/100);
ireadValue = pui32DataTx[2];
ireadValue = ireadValue << 8;
ireadValue |= pui32DataTx[3];

sprintf(buf,"SPI write <%x>\n",ireadValue);
UARTSend((uint8_t *)buf,strlen(buf),UART5_BASE);

}

waiting for your suggessions

Regards

GPM

  • I am not familiar with, nor could I find any information on a part AMC7280. Are you sure this device is outputting the correct data. There may be a timing issue. I suggest you look at the SSI lines with an oscilloscope or logic analyzer.
  • Dear Bob,
    Thanks for your reply. Actually Part No is AMC 7820
    Regards
    GPM
  • OK, that makes more sense. Have you looked with a scope or logic analyzer? Your delays are probably not working correctly. The function SysCtlClockGet() is only for use on TM4C123 devices. You should use the value returned by the function SysCltClockFreqSet(). (Make sure you are using that function to setup the system clock and not SysCtlClockSet().) How did you configure the SSI?
  • Dear Bob,

    I configured SSI as follows

    void SSI2Init(void)//
    {

    //
    // The SSI2 peripheral must be enabled for use.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

    //
    // Configure the pin muxing for SSI0 functions on port D0,D1 and D3.
    //
    GPIOPinConfigure(GPIO_PD0_SSI2XDAT1);
    GPIOPinConfigure(GPIO_PD1_SSI2XDAT0);
    GPIOPinConfigure(GPIO_PD3_SSI2CLK);
    //
    // Configure the GPIO settings for the SSI pins.
    //
    GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_3 | GPIO_PIN_1 | GPIO_PIN_0);
    //
    // Configure and enable the SSI port for SPI master mode. Use SSI2,
    //
    SSIConfigSetExpClk(SSI2_BASE, g_ui32SysClock, SSI_FRF_MOTO_MODE_1,
    SSI_MODE_MASTER, 1000000, 8);
    //
    // Enable the SSI2 module.
    //
    SSIEnable(SSI2_BASE);
    //
    // Read any residual data from the SSI port.
    //
    while(SSIDataGetNonBlocking(SSI2_BASE, &pui32DataRx[0]))
    {
    }
    }

    Regards

    GPM

  • OK, it looks like your format is correct. Remember that for each call to SSIDataPut(), a byte is also received in the receive FIFO. When you want to read a register from the AMC7820, you "put" two bytes which constitute the read command. You should then clear the two bytes of zero from the receive FIFO. Now as you "put" bytes to generate the actual reads each "put" can be followed by a "get" to read the data.