EasyManuals Logo

Cypress EZ-USB FX3 User Manual

Cypress EZ-USB FX3
660 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #180 background imageLoading...
Page #180 background image
EZ-USB FX3 Technical Reference Manual, Document Number: 001-76074 Rev. *F 180
Low Performance Peripherals (LPP)
8.5.3 Reads and Writes Using Register Transfers
The CyU3PSpiReceiveWords API reads data from the SPI slave device in register mode, and the CyU3PSpiTransmitBytes
API writes data to an SPI slave device in register mode. Following is the code for performing reads and writes to an SPI slave
using register transfers.
CyFxSpiTransfer (uint16_t pageAddress, uint16_t byteCount, uint8_t *buffer, CyBool_t
isRead)
{
uint8_t location[4];
uint32_t byteAddress = 0;
uint16_t pageCount = (byteCount / glSpiPageSize);
if ((byteCount % glSpiPageSize) != 0)
{
pageCount ++;
}
byteAddress = pageAddress * glSpiPageSize;
while (pageCount != 0)
{
location[1] = (byteAddress >> 16) & 0xFF; /* MS byte */
location[2] = (byteAddress >> 8) & 0xFF;
location[3] = byteAddress & 0xFF; /* LS byte */
if (isRead) /*Read*/
{
location[0] = 0x03; /* Read command. */
status = CyFxSpiWaitForStatus ();
CyU3PSpiSetSsnLine (CyFalse);
status = CyU3PSpiTransmitWords (location, 4);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "SPI READ command failed\r\n");
CyU3PSpiSetSsnLine (CyTrue);
}
status = CyU3PSpiReceiveWords (buffer, glSpiPageSize);
if (status != CY_U3P_SUCCESS)
{
CyU3PSpiSetSsnLine (CyTrue);
}
CyU3PSpiSetSsnLine (CyTrue);
}
else /* Write */
{
location[0] = 0x02; /* Write command */
status = CyFxSpiWaitForStatus ();
CyU3PSpiSetSsnLine (CyFalse);
status = CyU3PSpiTransmitWords (location, 4);
if (status != CY_U3P_SUCCESS)
{
CyU3PDebugPrint (2, "SPI WRITE command failed\r\n");
CyU3PSpiSetSsnLine (CyTrue);
}

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Cypress EZ-USB FX3 and is the answer not in the manual?

Cypress EZ-USB FX3 Specifications

General IconGeneral
BrandCypress
ModelEZ-USB FX3
CategoryController
LanguageEnglish

Related product manuals