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 Program for multiple slave

Part Number: TM4C129ENCPDT
Other Parts Discussed in Thread: AMC7820

Tool/software: Code Composer Studio

Hi,

In my design I have to configure 2 slave modules in SPI2.

The slave module i used is TI- AMC7820.

First i tried to configure single SPI module.

The Pins I used was PD0,PD1 and PD3. The chip select was PK3 for slave 1.

I have modified the code for write 0x2345 to a register and read back it. But what I read back is NULL

The init,read and write functions are as below.

void SSI2Init(void) //SPI 2 initialization
{

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


SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);


SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);//  CS1 K3

//
// 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);



// GPIOPinConfigure(GPIO_PA3_SSI0FSS);// This is not done as CS is a GPIO pin



GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_3);//  CS1 for slave 1 as GPIO output pin

    GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3,GPIO_PIN_3);//make it high, as it is active low

//
// 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_TI,
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]))
{
}

}

void SPI2Read(void)
{

pui32DataTx[0]=0x82;// for reading from register

pui32DataTx[1]=0x40;

GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3 ,0);// CS LOw; AMC expects Active low control signal
for(ui32Index = 0; ui32Index < 2; 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(SSI2_BASE, pui32DataTx[ui32Index]);
}

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



// Receive 2 bytes of data.
//
for(ui32Index = 0; ui32Index < 2; ui32Index++)
{


//
// Receive the data using the "blocking" Get function. This function
// will wait until there is data in the receive FIFO before returning.
//
SSIDataGet(SPIBase, &pui32DataRx[ui32Index]);

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


}
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3 ,GPIO_PIN_3 );// Reset CS to High

}

void SPIwrite(void)
{

pui32DataTx[0]=0x02;
pui32DataTx[1]=0x40;
pui32DataTx[2]=0x23;
pui32DataTx[3]=0x45;


GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3 ,0)// CS LOw; AMC expects Active low control signal
for(ui32Index = 0; ui32Index < 4; 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(SSI2_BASE, pui32DataTx[ui32Index]);


}

//
// Wait until SSI0 is done transferring all the data in the transmit FIFO.
//
while(SSIBusy(SSI2_BASE))
{
}
GPIOPinWrite(GPIO_PORTK_BASE, GPIO_PIN_3 ,GPIO_PIN_3 );// Reset CS to High

}

Please Help me.

Thanks in advance.

  • I think the problem is that you did not provide the SPICLKs to read the data. There is a fundamental discussion about the full duplex nature of SPI in this thread: e2e.ti.com/.../665776

    If I understand the AMC7820 correctly, you send a 16-bit command, then send 16-bits of dummy data to read the response. You have configured SSI2 to transfer a byte on each call to SSIDataPut and you called it twice to send the command. But SSIDataGet does not generate any SSICLK edges. It simply reads the data in the FIFO that was captured during the masters last SSIDataPut calls.

    After you send the two bytes of command, send two dummy bytes to read the response. Then read four bytes from the FIFO discarding the first two. The results are in the second two bytes.
  • Hi Bob,

    Thank you for your quick response.

    "But SSIDataGet does not generate any SSICLK edges. It simply reads the data in the FIFO that was captured during the masters last SSIDataPut calls. "

    I understand this. Does the function given below generates clock. This is configured during initialization.

    SSIConfigSetExpClk(SSI2_BASE, g_ui32SysClock, SSI_FRF_MOTO_MODE_1 ,
                                  SSI_MODE_MASTER, 1000000, 8);

    I was unable to find a function to generate clock.

    We modified our code, changed the mode to  SSI_FRF_MOTO_MODE_1 ; added dummy send. But still we receive Null value.

    Regards,

    Neethu

  • Hi Bob,

    The issue is resolved.

    We  just added two lines after each  SSIDataPut() and SSIDataGet().

    SysCtlDelay(SysCtlClockGet()/100);
    
    while(SSIBusy(SSI0_BASE));

    Now every thing is working fine.

    Thank you very much.

    Regards,

    Neethu

  • Neethu G Prem10 said:
    I was unable to find a function to generate clock.

    The SSIDataPut() function - most definitely - generates the SPI clock.      As vendor's Bob noted - SPI operates in full duplex - so as the SSIDataPut() outputs SPI Clocks and SPI Data - it also is able to "Receive Data" via the MISO pin.      

    The key "trick" you appear to be missing - you must FOLLOW  "SSIDataPut()"  with  "SSIDataGet()!"        Then and only then - will the data received via the (earlier) "SSIPUT" become available to you...

    [edit]   If I could "see straight" and my pistol was nearer - I'd "Shoot myself!"      Our posts just crossed - glad that you succeeded - many fall victim to the "unusual" nature of SPI...

  • Hi,

    Thanks for your valuable reply.

    As Bob said we modified our code for full dupex mode of communication.Still it was not working.

    Today we added delay(was mentioned by Bob) along with full duplex mode. Now its working fine.:)

    Regards,

    Neethu