I am developing a custom board, based on a TM4C129 MCU, which integrates several components that use SPI protocol. In all components except one, this MCU is master and everything goes fine. But when slave, I do not manage to make it work.
The component to which the MCU is connected is an AD converter that must be powered up by following a recommended sequence (take reset line low for a period of time and write the two control registers).
In most discussions I have found in this forum dealing with the MCU as a slave, the MCU just reads, and does not write except for one (e2e.ti.com/.../453608).
I think that the problem I have is more due to understanding of the SPI protocol principle than a problem of coding (maybe or probably there is also a coding problem). When I write to the 32-bit control register of the ADC by calling ROM_SSIDataPut four times (4 bytes), the last byte is transmitted continuously, i.e. it is not just send once, but non stop. Why does it happen? what could be pushing the MCU to send the byte continuously?
As the MCU is acting as a slave, the CLK and nFSS are controlled by the ADC (master). The nFss is always logic low after reset.
Below is the SSI setting:
// // The SSI0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // // For this example SSI0 is used with PortA[5:2]. GPIO port A needs to be // enabled so these pins can be used. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // 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. // GPIOPinConfigure(GPIO_PA2_SSI0CLK); GPIOPinConfigure(GPIO_PA3_SSI0FSS); GPIOPinConfigure(GPIO_PA4_SSI0XDAT0); GPIOPinConfigure(GPIO_PA5_SSI0XDAT1); // // Configure the GPIO settings for the SSI pins. This function also gives // control of these pins to the SSI hardware. Consult the data sheet to // see which functions are allocated per pin. // The pins are assigned as follows: // PA5 - SSI0Tx // PA4 - SSI0Rx // PA3 - SSI0Fss // PA2 - SSI0CLK // GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_5 | GPIO_PIN_4 | GPIO_PIN_3 | GPIO_PIN_2); // // Configure and enable the SSI0 port for SPI master mode. // SSIConfigSetExpClk(SSI0_BASE, g_ui32SysClock, SSI_FRF_MOTO_MODE_0, SSI_MODE_SLAVE, 5000000, 8); // Enable the SSI0 module. // ROM_SSIEnable(SSI0_BASE); Another question, after writing the four bytes, I add ROM_SSIDataPutNonBlocking (SSI0_BASE, ui8AddrByte1); /* Argument[31..24] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte2); /* Argument[23..16] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte3); /* Argument[15..8] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte4 ); /* Argument[7..0] */ // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // //while(ROM_SSIBusy(SSI0_BASE));
Another question, after writing the four bytes, I add ROM_SSIBusy as shown below
ROM_SSIDataPutNonBlocking (SSI0_BASE, ui8AddrByte1); /* Argument[31..24] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte2); /* Argument[23..16] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte3); /* Argument[15..8] */ ROM_SSIDataPutNonBlocking(SSI0_BASE, ui8AddrByte4 ); /* Argument[7..0] */ // // Wait until SSI0 is done transferring all the data in the transmit FIFO. // while(ROM_SSIBusy(SSI0_BASE));
and the code gets stuck. Is it that normal?
Thanks,
Gello