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.

Tm4c123 as SPI slave

Hi,

I have an SPI master sending me commands and want to initialise the LM4F232 processor as a slave. I am using the LM4F232 Eval board for this purpose.

Following is the code for SPI initialisation as a slave.

void InitGPIOF(void)
{
GPIO_PORTF_LOCK_R = 0x4C4F434B; //Enable writing to GPIOCR registers
GPIO_PORTF_CR_R = 0x000000FF;

GPIOPinConfigure(GPIO_PF2_SSI1CLK);
GPIOPinConfigure(GPIO_PF3_SSI1FSS);
GPIOPinConfigure(GPIO_PF0_SSI1RX);
GPIOPinConfigure(GPIO_PF1_SSI1TX);

GPIOPinTypeSSI(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);
}
void InitSPI(void)
{
U32 ulRcvdData[2];

SSIDisable(SSI1_BASE);
SSIConfigSetExpClk(SSI1_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_SLAVE, 125000, 8);

while(SSIDataGetNonBlocking(SSI1_BASE, ulRcvdData))
{

}

SSIIntEnable(SSI1_BASE, SSI_RXTO);
SSIIntRegister(SSI1_BASE, ISR_SpiInterrupt);
IntEnable(INT_SSI1);
SSIEnable(SSI1_BASE);
}


I want to receive single bytes from the master so I am using an SPI receive timeout interrupt.

Following is the interrupt service routine.

void ISR_SpiInterrupt(void)
{
U32 ulSPI_IntStatus = RESET;
ulSPI_IntStatus = SSIIntStatus(SSI1_BASE, TRUE);
SSIIntClear(SSI1_BASE, ulSPI_IntStatus);
g_stApolloParms.m_ulSPI_RcvdInt = YES;
}
And the while 1 loop:

if(g_stApolloParms.m_ulSPI_RcvdInt == YES)
{
g_stApolloParms.m_ulSPI_RcvdInt = NO;
GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_3, ~(GPIOPinRead(GPIO_PORTD_BASE, GPIO_PIN_3)));
}


I am facing multiple problems with this.

1. The SPI interrupt does trigger, but continously - I can see the PORTD, Pin 3 toggling all the time. The SPI master sends me one byte every 10ms.
2. Whenever I try to read any data after the interrupt is received, the interrupt does not trigger again - This is the case even if I use any of SSIDataGet(), SSIDataGetUnblocking, or even directly reading the SSI1_DR_R register.
3. On the SSI_TX line is always low.

Just to make sure that my connections are proper, I have connected the system in the following manner.
1. SSICLK - SCLK (Masterclock)
2. SSIRX - MOSI (On the master side)
3. SSITX - MISO (On The master side)
4. SSIFSS is pulled low.


I do not know what I am missing or what is going wrong. Kindly help.

Just as an update, I have tried using 2 modules of SSI on the same controller with the same issues. Also, the SPI works correctly in loopback fashion..

Thanks and Regards,
Makarand

  • Hello Makarand

    As I understand there are 3 issues.

    1. The SPI Interrupt triggers continously: Since you are using the RXTO interrupt bit, it would mean that you have to read the data before clearing the RXTO bit, else it will timeout again since the data has not been read.
    2. If the data is read and the RXFIFO is empty, then SSIDataGet will not return till FIFO has data. Similarly the SSIDataGetNonBlocking will not return the data.
    3. For the SSI_TX to be non zero, you need to send data. You might want to capture the SSI lines on FSS going low.

    Regards
    Amit