EZ-USB FX3 Technical Reference Manual, Document Number: 001-76074 Rev. *F 179
Low Performance Peripherals (LPP)
8.5 Examples
This section shows example codes to write and read to an SPI slave device (flash memory) using register-based and DMA-
based transfers from FX3. APIs to perform read and write accesses to an SPI device are provided with the FX3 SDK. Refer to
the Cyu3spi.c file located at C:\Program Files (x86)\Cypress\EZ-USB FX3 SDK\1.3\firmware\lpp_source (after FX3 SDK
installation) for the source code of SPI-related APIs. Refer to FX3APIGuide.pdf located at C:\Program Files
(x86)\Cypress\EZ-USB FX3 SDK\1.3\doc for more details on FX3 APIs.
8.5.1 Initialize SPI Block
The CyU3PSpiInit API initializes the FX3 SPI block. The SPI block is initialized to operate at the default frequency of 1 MHz.
Following is the CyU3PSPIInit function definition.
CyU3PSpiInit (void)
{
/* Set the clock freqency. This should precede the SPI power up */
CyU3PSpiSetClock (1000000);
CyU3PMutexCreate (&glSpiLock, CYU3P_NO_INHERIT);
/* Identify if the LPP block has been initialized. */
CyU3PLppInit (CY_U3P_LPP_SPI, CyU3PSpiInt_ThreadHandler);
/* Power on the SPI module */
SPI->lpp_spi_power &= ~(1 << 31);
CyU3PBusyWait (10);
SPI->lpp_spi_power |= 1 << 31;
/* Wait till the active bit is set */
while (!(SPI->lpp_spi_power & CY_U3P_LPP_SPI_ACTIVE));
/* Mark the module active. */
glIsSpiActive = CyTrue;
}
8.5.2 Configure SPI Block
The CyU3PSpiSetConfig API configures the FX3 SPI block. Following is the code for setting the SPI bus frequency to 8 MHz.
The word length is configured to 8 bits, and slave select (SSN) is configured to be controlled by the FX3 firmware.
CyU3PMemSet ((uint8_t *)&spiConfig, 0, sizeof(spiConfig));
spiConfig.isLsbFirst = CyFalse;
spiConfig.cpol = CyTrue;
spiConfig.ssnPol = CyFalse;
spiConfig.cpha = CyTrue;
spiConfig.leadTime = CY_U3P_SPI_SSN_LAG_LEAD_HALF_CLK;
spiConfig.lagTime = CY_U3P_SPI_SSN_LAG_LEAD_HALF_CLK;
spiConfig.ssnCtrl = CY_U3P_SPI_SSN_CTRL_FW;
spiConfig.clock = 8000000;
spiConfig.wordLen = 8;
CyU3PSpiSetConfig (&spiConfig, NULL);