XilinxProcessorIPLib/drivers/spi/examples/xspi_eeprom_example.c
void EepromWrite(XSpi *SpiPtr, u16 Address, u8 ByteCount, EepromBuffer Buffer)
{
	u8 WriteEnableCmd = { WRITE_ENABLE_CMD };
	u8 ReadStatusCmd[] = { READ_STATUS_CMD, 0 };  /* must send 2 bytes */
	u8 EepromStatus[2];
	int DelayCount = 0;

	/*
	 * Send the write enable command to the SEEPOM so that it can be
	 * written to, this needs to be sent as a separate transfer before
	 * the write
	 */
	TransferInProgress = TRUE;

	XSpi_Transfer(SpiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));

	/*
	 * Wait for the transfer on the SPI bus to be complete before proceeding
	 */
	while (TransferInProgress);

	/*
	 * Setup the write command with the specified address and data for the
	 * EEPROM
	 */
	Buffer[COMMAND_OFFSET]     = WRITE_CMD;
	Buffer[ADDRESS_MSB_OFFSET] = (u8)((Address & 0xFF00) >> 8);
	Buffer[ADDRESS_LSB_OFFSET] = (u8)(Address & 0x00FF);

	/*
	 * Send the write command, address, and data to the EEPROM to be
	 * written, no receive buffer is specified since there is nothing to
	 * receive
	 */
	TransferInProgress = TRUE;

	XSpi_Transfer(SpiPtr, Buffer, NULL, ByteCount + OVERHEAD_SIZE);

	while (TransferInProgress);

	/*
	 * Wait for a bit of time to allow the programming to occur as reading
	 * the status while programming causes it to fail because of noisy power
	 * on the board containing the EEPROM, this loop does not need to be
	 * very long but is longer to hopefully work for a faster processor
	 */
	while (DelayCount++ < 10000) {
	}

	/*
	 * Wait for the write command to the EEPROM to be completed, it takes
	 * some time for the data to be written
	 */
	while (1) {
		/*
		 * Poll the status register of the device to determine when it
		 * completes by sending a read status command and receiving the
		 * status byte
		 */
		TransferInProgress = TRUE;

		XSpi_Transfer(SpiPtr, ReadStatusCmd, EepromStatus,
					sizeof(ReadStatusCmd));

		/*
		 * Wait for the transfer on the SPI bus to be complete before
		 * proceeding
		 */
		while (TransferInProgress);

		/*
		 * If the status indicates the write is done, the stop waiting,
		 * if a value of 0xFF in the status byte is read from the
		 * device and this loop never exits, the device slave select is
		 * possibly incorrect such that the device status is not being
		 * read
		 */
		if ((EepromStatus[1] & 0x03) == 0) {
			break;
		}
	}
}
/******************************************************************************/
/**
*
* This function writes to the Microchip serial EEPROM connected to the
* SPI interface.  This 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.
*
* @param 	SpiPtr is a pointer to the SPI driver component to use.
* @param 	Address contains the address to write data to in the EEPROM.
* @param 	ByteCount contains the number of bytes to write.
* @param 	Buffer is a buffer of data to write from.
*
* @return	None.
*
* @note		None.
*
******************************************************************************/
This function writes to the Microchip serial EEPROM connected to the
SPI interface.  This 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.
This function writes to the Microchip serial EEPROM connected to the SPI interface . This 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 .
void EepromWrite(XSpi *SpiPtr, u16 Address, u8 ByteCount, EepromBuffer Buffer)
{
	u8 WriteEnableCmd = { WRITE_ENABLE_CMD };
	u8 ReadStatusCmd[] = { READ_STATUS_CMD, 0 };  
	u8 EepromStatus[2];
	int DelayCount = 0;
	TransferInProgress = TRUE;
	XSpi_Transfer(SpiPtr, &WriteEnableCmd, NULL, sizeof(WriteEnableCmd));
	while (TransferInProgress);
	Buffer[COMMAND_OFFSET]     = WRITE_CMD;
	Buffer[ADDRESS_MSB_OFFSET] = (u8)((Address & 0xFF00) >> 8);
	Buffer[ADDRESS_LSB_OFFSET] = (u8)(Address & 0x00FF);
	TransferInProgress = TRUE;
	XSpi_Transfer(SpiPtr, Buffer, NULL, ByteCount + OVERHEAD_SIZE);
	while (TransferInProgress);
	while (DelayCount++ < 10000) {
	}
	while (1) {
		TransferInProgress = TRUE;
		XSpi_Transfer(SpiPtr, ReadStatusCmd, EepromStatus,
					sizeof(ReadStatusCmd));
		while (TransferInProgress);
		if ((EepromStatus[1] & 0x03) == 0) {
			break;
		}
	}
}
void EepromWrite ( XSpi * SpiPtr , u16 Address , u8 ByteCount , EepromBuffer Buffer ) { u8 WriteEnableCmd = { WRITE_ENABLE_CMD } ; u8 ReadStatusCmd [ ] = { READ_STATUS_CMD , 0 } ; u8 EepromStatus [ 2 ] ; int DelayCount = 0 ; TransferInProgress = TRUE ; XSpi_Transfer ( SpiPtr , & WriteEnableCmd , NULL , sizeof ( WriteEnableCmd ) ) ; while ( TransferInProgress ) ; Buffer [ COMMAND_OFFSET ] = WRITE_CMD ; Buffer [ ADDRESS_MSB_OFFSET ] = ( u8 ) ( ( Address & 0xFF00 ) >> 8 ) ; Buffer [ ADDRESS_LSB_OFFSET ] = ( u8 ) ( Address & 0x00FF ) ; TransferInProgress = TRUE ; XSpi_Transfer ( SpiPtr , Buffer , NULL , ByteCount + OVERHEAD_SIZE ) ; while ( TransferInProgress ) ; while ( DelayCount ++ < 10000 ) { } while ( 1 ) { TransferInProgress = TRUE ; XSpi_Transfer ( SpiPtr , ReadStatusCmd , EepromStatus , sizeof ( ReadStatusCmd ) ) ; while ( TransferInProgress ) ; if ( ( EepromStatus [ 1 ] & 0x03 ) == 0 ) { break ; } } }
This function writes to the Microchip serial EEPROM connected to the
SPI interface.
This function writes to the Microchip serial EEPROM connected to the SPI interface .
/* must send 2 bytes */ /*
	 * Send the write enable command to the SEEPOM so that it can be
	 * written to, this needs to be sent as a separate transfer before
	 * the write
	 */ /*
	 * Wait for the transfer on the SPI bus to be complete before proceeding
	 */ /*
	 * Setup the write command with the specified address and data for the
	 * EEPROM
	 */ /*
	 * Send the write command, address, and data to the EEPROM to be
	 * written, no receive buffer is specified since there is nothing to
	 * receive
	 */ /*
	 * Wait for a bit of time to allow the programming to occur as reading
	 * the status while programming causes it to fail because of noisy power
	 * on the board containing the EEPROM, this loop does not need to be
	 * very long but is longer to hopefully work for a faster processor
	 */ /*
	 * Wait for the write command to the EEPROM to be completed, it takes
	 * some time for the data to be written
	 */ /*
		 * Poll the status register of the device to determine when it
		 * completes by sending a read status command and receiving the
		 * status byte
		 */ /*
		 * Wait for the transfer on the SPI bus to be complete before
		 * proceeding
		 */ /*
		 * If the status indicates the write is done, the stop waiting,
		 * if a value of 0xFF in the status byte is read from the
		 * device and this loop never exits, the device slave select is
		 * possibly incorrect such that the device status is not being
		 * read
		 */