My questions are at the end. First, some background: I am new to programming in C and to this microcontroller family.
I have a TM4C1236H6PM connected to a Beaglebone Black. The BBB is the master and the TM4C is configured as the slave. I can confirm that the correct data stream is being sent from the BBB correctly as I have the signal lines connected to a logic analyzer at the pins to the TM4C.
The LA is configured for decoding 16-bit transfers, CPOL=0, CPHA=0 (data valid on clock leading edge), CS is active low. Basically, normal conditions.
I am writing (4) words: 0x5555 0x0003 0xAAAA 0x0004
The TM4C is configured as follows (shortened to just the relevant lines):
//Set the clock internal to the Tiva to 40 MHz
ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
//Enable peripheral SSI1
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1); // Enable SPI Port #1 (BBB communications)
// GPIOF p0,p1,p2,p3 as SPI communications with BBB (SPI1)
// BBB is the master for this port. Tiva is the slave device.
GPIOPinConfigure(GPIO_PF0_SSI1RX);
GPIOPinConfigure(GPIO_PF1_SSI1TX);
GPIOPinConfigure(GPIO_PF2_SSI1CLK);
GPIOPinConfigure(GPIO_PF3_SSI1FSS);
GPIOPinTypeSSI(GPIO_PORTF_BASE,GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
// Configure SPI1 for communications with the BBB (Master device).
SSIDisable(SSI1_BASE);
ROM_SSIConfigSetExpClk(SSI1_BASE,ROM_SysCtlClockGet(),SSI_FRF_MOTO_MODE_0,SSI_MODE_SLAVE,500000,8);
SSIEnable(SSI1_BASE);
// ENABLE AN INTERRUPT ON THE SPI1 Rx FIFO
IntRegister(INT_SSI1, SPI_ISR_Handler);
IntEnable(INT_SSI1);
SSIIntEnable(SSI1_BASE, SSI_RXFF);
SSIIntClear(SSI1_BASE, SSI_RXFF | SSI_RXTO | SSI_RXOR);
IntMasterEnable();
The ISR is as follows (including some debugging writes to the UART):
void SPI_ISR_Handler (void) {
char ISR_Rx_FIFO[12];
uint32_t ui32Index;
uint32_t pui32DataRx[8];
unsigned long isr_source = SSIIntStatus(SSI1_BASE, true);
UARTprintf("--------------------------------------------\r");
UARTprintf("RECEIVED AN SPI THINGY. Interrupt status: %d (4: FIFO >= Half Full, 0: FIFO Empty).\r", isr_source);
UARTprintf("Reading 4 words from Rx FIFO.\r");
for(ui32Index = 0; ui32Index < 8; ui32Index++) {
SSIDataGetNonBlocking(SSI1_BASE, &pui32DataRx[ui32Index]);
pui32DataRx[ui32Index] &= 0xFFFF;
pui32DataRx[ui32Index] = Reverse(pui32DataRx[ui32Index]);
snprintf(ISR_Rx_FIFO, 12, "0x%0.4X", pui32DataRx[ui32Index]);
UARTprintf("Read: %s\r", ISR_Rx_FIFO);
}
UARTprintf("Attempting to clear interrupt.\r", isr_source);
SSIIntClear(SSI1_BASE, isr_source);
isr_source = SSIIntStatus(SSI1_BASE, true);
UARTprintf("Revised interrupt status = %d.\r", isr_source);
}
My problems/questions:
1. The ISR is only triggered on every fourth transmission from the BBB. From my understanding of the SSI FIFO, the SSI_RXFF condition should mean that the ISR is triggered after 8 bytes (one complete transmission of my 4 data words). Correct?
2. Once triggered, the contents of my variable pui32DataR do not contain the contents of the transmission (at least not as I intended). What I see is:
As I am new to C, I am hoping somebody can help point out my obvious mistakes and/or misunderstanding about retrieving this data. I'm looking to learn, but have so far not found anything online. Please help get me back on track. Thanks!