UINT16 SPIDrvRead(UINT8 u8Addr)
{
UINT8 u8TempValue=0;
UINT16 u16Data=0; /* u16Data[0] is MSB, u16Data[1] is LSB */
SPIClearRecieveStatReg(&u8TempValue); /* Clear status register (possible SPRF, SPTEF) */
SPIClearRecieveDataReg(&u8TempValue); /*
* Clear receive data register. SPI entirely
* ready for read or write
*/
MC13213DisableInterrupts(); /* Necessary to prevent double SPI access */
AssertCE(); /* Enables MC13213 SPI */
SPISendChar((u8Addr & 0x3f) | 0x80); /* Mask address, 6bit addr, Set
* read bit.
*/
SPIWaitTransferDone(); /* For this bit to be set, SPTED MUST be set */
SPIClearRecieveDataReg(&u8TempValue); /*
* Clear receive data register. SPI
* entirely ready for read or write
*/
SPISendChar(u8Addr ); /*
* Dummy write. Receive register of SPI
* will contain MSB
*/
SPIWaitTransferDone(); /*
* For this bit to be set, SPTED MUST be
* set. Get MSB
*/
SPIReadMSB(&u16Data); /* MSB */
SPISendChar(u8Addr); /*
* Dummy write. Waiting until after
* reading received data insures no
* overrun
*/
SPIWaitTransferDone(); /*
* For this bit to be set, SPTED MUST be
* set. Get LSB
*/
((UINT8*)&u16Data)[1] = SPIRead(); /* LSB */
DeAssertCE(); /* Disables MC13213 SPI */
MC13213RestoreInterrupts(); /* Restore MC13213 interrupt status */
return u16Data;
} 作者: seuafu2005 时间: 2007-9-17 10:27