spips
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Groups Pages
Xspips_eeprom_polled_example

Macros

#define WRITE_STATUS_CMD   1
 Write status register command. More...
 
#define WRITE_CMD   2
 Write data command. More...
 
#define READ_CMD   3
 Read data command. More...
 
#define WRITE_DISABLE_CMD   4
 Write disable command. More...
 
#define READ_STATUS_CMD   5
 Read status register command. More...
 
#define WRITE_ENABLE_CMD   6
 Write enable command. More...
 
#define COMMAND_OFFSET   0
 EEPROM instruction. More...
 
#define ADDRESS_MSB_OFFSET   1
 MSB of address to read or write. More...
 
#define ADDRESS_LSB_OFFSET   2
 LSB of address to read or write. More...
 
#define DATA_OFFSET   3
 Start of data in the buffer. More...
 
#define WRITE_DATA_OFFSET   3
 Start of data to write to the EEPROM. More...
 
#define READ_DATA_OFFSET   6
 Start of data read from the EEPROM. More...
 
#define OVERHEAD_SIZE   3
 Command and address bytes. More...
 
#define PAGE_SIZE   16
 EEPROM page size in bytes. More...
 
#define PAGE_COUNT   128
 Number of EEPROM pages. More...
 
#define MAX_DATA   PAGE_COUNT * PAGE_SIZE
 Max data size. More...
 
#define BUFFER_SIZE   MAX_DATA + READ_DATA_OFFSET
 Size of the buffer holding the data and the overhead bytes. More...
 
#define EEPROM_SPI_SELECT   0x01
 EEPROM slave select. More...
 

Typedefs

typedef u8 EepromBuffer [BUFFER_SIZE]
 Holds the data sent to and received from the serial EEPROM device. More...
 

Functions

void EepromRead (XSpiPs *SpiPtr, u16 Address, int ByteCount, EepromBuffer Buffer)
 Reads from the serial EEPROM connected to the SPI interface. More...
 
void EepromWrite (XSpiPs *SpiPtr, u16 Address, u8 ByteCount, EepromBuffer Buffer)
 Writes to the serial EEPROM connected to the SPI interface. More...
 
int SpiPsEepromPolledExample (XSpiPs *SpiInstancePtr, UINTPTR BaseAddress)
 Illustrates how to use the XSpiPs device driver in polled mode. More...
 
int main (void)
 Calls the SPI EEPROM polled example. More...
 

Variables

int Test
 Holds a test value added to the values written to the EEPROM. More...
 
EepromBuffer ReadBuffer
 Data read from the EEPROM. More...
 
EepromBuffer WriteBuffer
 Data to write to the EEPROM. More...
 

Macro Definition Documentation

#define ADDRESS_LSB_OFFSET   2

LSB of address to read or write.

#define ADDRESS_MSB_OFFSET   1

MSB of address to read or write.

#define BUFFER_SIZE   MAX_DATA + READ_DATA_OFFSET

Size of the buffer holding the data and the overhead bytes.

#define COMMAND_OFFSET   0

EEPROM instruction.

#define DATA_OFFSET   3

Start of data in the buffer.

#define EEPROM_SPI_SELECT   0x01

EEPROM slave select.

Referenced by SpiPsEepromPolledExample().

#define MAX_DATA   PAGE_COUNT * PAGE_SIZE

Max data size.

Referenced by SpiPsEepromPolledExample().

#define OVERHEAD_SIZE   3

Command and address bytes.

#define PAGE_COUNT   128

Number of EEPROM pages.

Referenced by SpiPsEepromPolledExample().

#define PAGE_SIZE   16

EEPROM page size in bytes.

Referenced by SpiPsEepromPolledExample().

#define READ_CMD   3

Read data command.

#define READ_DATA_OFFSET   6

Start of data read from the EEPROM.

Referenced by SpiPsEepromPolledExample().

#define READ_STATUS_CMD   5

Read status register command.

#define WRITE_CMD   2

Write data command.

#define WRITE_DATA_OFFSET   3

Start of data to write to the EEPROM.

Referenced by SpiPsEepromPolledExample().

#define WRITE_DISABLE_CMD   4

Write disable command.

#define WRITE_ENABLE_CMD   6

Write enable command.

#define WRITE_STATUS_CMD   1

Write status register command.

Typedef Documentation

typedef u8 EepromBuffer[BUFFER_SIZE]

Holds the data sent to and received from the serial EEPROM device.

The data type sends and receives data to the serial EEPROM device connected to the SPI interface. It is an array of bytes rather than a structure for portability avoiding packing issues. The application must setup the data to be written in this buffer and retrieve the data read from it.

Function Documentation

void EepromRead ( XSpiPs *  SpiPtr,
u16  Address,
int  ByteCount,
EepromBuffer  Buffer 
)

Reads from the serial EEPROM connected to the SPI interface.

Parameters
[in,out]SpiPtrPointer to the SPI driver component to use.
[in]AddressThe address to read data from in the EEPROM.
[in]ByteCountThe number of bytes to read.
[out]BufferA buffer to read the data into.
void EepromWrite ( XSpiPs *  SpiPtr,
u16  Address,
u8  ByteCount,
EepromBuffer  Buffer 
)

Writes to the serial EEPROM connected to the SPI interface.

The function is not designed to be a driver to handle all the conditions of the EEPROM device. The EEPROM contains a 32 byte write buffer which can be filled and then a write is automatically performed by the device. All the data put into the buffer must be in the same page of the device with page boundaries being on 32 byte boundaries.

Parameters
[in,out]SpiPtrPointer to the SPI driver instance to use.
[in]AddressThe address to write data to in the EEPROM.
[in]ByteCountThe number of bytes to write.
[in]BufferA buffer of data to write from.
int main ( void  )

Calls the SPI EEPROM polled example.

Returns
XST_SUCCESS if successful, otherwise XST_FAILURE.

References SpiPsEepromPolledExample().

int SpiPsEepromPolledExample ( XSpiPs *  SpiInstancePtr,
UINTPTR  BaseAddress 
)

Illustrates how to use the XSpiPs device driver in polled mode.

This test writes and reads data from a serial EEPROM. The serial EEPROM part must be present in the hardware to use this example.

Parameters
[in]SpiInstancePtrPointer to the Spi Instance.
[in]BaseAddressThe base address of the device.
Returns
XST_SUCCESS if successful else XST_FAILURE.
Note
- The function calls functions which contain loops that may be infinite if interrupts are not working such that it may not return. If the device slave select is not correct and the device is not responding on bus it reads a status of 0xFF for the status register as the bus is pulled up.
  • In XSCT/classic flow, the device configuration is looked up based on DeviceId.

References XSpiPs_Config::BaseAddress, EEPROM_SPI_SELECT, EepromRead(), EepromWrite(), MAX_DATA, PAGE_COUNT, PAGE_SIZE, READ_DATA_OFFSET, ReadBuffer, Test, WRITE_DATA_OFFSET, WriteBuffer, XSpiPs_CfgInitialize(), XSPIPS_CLK_PRESCALE_64, XSPIPS_FORCE_SSELECT_OPTION, XSpiPs_LookupConfig(), XSPIPS_MASTER_OPTION, XSpiPs_SelfTest(), XSpiPs_SetClkPrescaler(), XSpiPs_SetOptions(), and XSpiPs_SetSlaveSelect().

Referenced by main().

Variable Documentation

EepromBuffer ReadBuffer

Data read from the EEPROM.

int Test

Holds a test value added to the values written to the EEPROM.

The variable allows a test value to be added to the values that are written to the EEPROM such that unique values can be generated to guarantee the writes to the EEPROM were successful

EepromBuffer WriteBuffer

Data to write to the EEPROM.